| /*========================================================================= |
| * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. |
| * This product is protected by U.S. and international copyright |
| * and intellectual property laws. Pivotal products are covered by |
| * one or more patents listed at http://www.pivotal.io/patents. |
| *========================================================================= |
| */ |
| package com.gemstone.gemfire.management.internal.cli.domain; |
| |
| import java.io.Serializable; |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.Map; |
| |
| import com.gemstone.gemfire.cache.FixedPartitionAttributes; |
| import com.gemstone.gemfire.cache.PartitionAttributes; |
| import com.gemstone.gemfire.cache.PartitionResolver; |
| import com.gemstone.gemfire.internal.cache.PartitionAttributesImpl; |
| import com.gemstone.gemfire.management.internal.cli.util.RegionAttributesDefault; |
| import com.gemstone.gemfire.management.internal.cli.util.RegionAttributesNames; |
| |
| /*** |
| * Data class containing the PartitionAttributes for a region on a certain member |
| * @author bansods |
| * |
| */ |
| public class PartitionAttributesInfo implements Serializable { |
| |
| /** |
| * |
| */ |
| private static final long serialVersionUID = 1L; |
| private int totalNumBuckets = 0; |
| private int localMaxMemory = 0; |
| private int redundantCopies = 0; |
| private String colocatedWith = ""; |
| private long recoveryDelay = 0; |
| private long startupRecoveryDelay = 0; |
| private String partitionResolverName = ""; |
| private List<FixedPartitionAttributesInfo> fpaInfoList; |
| private Map<String, String> nonDefaultAttributes; |
| |
| public PartitionAttributesInfo(PartitionAttributes<?, ?> partitionAttributes) { |
| this.totalNumBuckets = partitionAttributes.getTotalNumBuckets(); |
| this.localMaxMemory = partitionAttributes.getLocalMaxMemory(); |
| this.redundantCopies = partitionAttributes.getRedundantCopies(); |
| this.colocatedWith = partitionAttributes.getColocatedWith(); |
| this.recoveryDelay = partitionAttributes.getRecoveryDelay(); |
| this.startupRecoveryDelay = partitionAttributes.getStartupRecoveryDelay(); |
| PartitionResolver<?, ?> partitionResolver = partitionAttributes.getPartitionResolver(); |
| |
| if (partitionResolver != null) { |
| partitionResolverName = partitionResolver.getName(); |
| } |
| |
| List<FixedPartitionAttributes> fpaList = partitionAttributes.getFixedPartitionAttributes(); |
| |
| if (fpaList != null) { |
| Iterator<FixedPartitionAttributes> iters = fpaList.iterator(); |
| fpaInfoList = new ArrayList<FixedPartitionAttributesInfo>(); |
| |
| while (iters.hasNext()) { |
| FixedPartitionAttributes fpa = (FixedPartitionAttributes)iters.next(); |
| FixedPartitionAttributesInfo fpaInfo = new FixedPartitionAttributesInfo(fpa); |
| fpaInfoList.add(fpaInfo); |
| } |
| } |
| |
| nonDefaultAttributes = new HashMap<String, String>(); |
| if (this.totalNumBuckets != RegionAttributesDefault.TOTAL_NUM_BUCKETS) { |
| nonDefaultAttributes.put(RegionAttributesNames.TOTAL_NUM_BUCKETS, Integer.toString(this.totalNumBuckets)); |
| } |
| |
| if (this.localMaxMemory != ((PartitionAttributesImpl) partitionAttributes).getLocalMaxMemoryDefault()) { |
| nonDefaultAttributes.put(RegionAttributesNames.LOCAL_MAX_MEMORY, Integer.toString(this.localMaxMemory)); |
| } |
| |
| |
| if (this.redundantCopies != RegionAttributesDefault.REDUNDANT_COPIES) { |
| nonDefaultAttributes.put(RegionAttributesNames.REDUNDANT_COPIES, Integer.toString(this.redundantCopies)); |
| } |
| |
| |
| if (this.colocatedWith != null && !this.colocatedWith.equals(RegionAttributesDefault.COLOCATED_WITH)) { |
| nonDefaultAttributes.put(RegionAttributesNames.COLOCATED_WITH, this.colocatedWith); |
| } |
| |
| |
| if (this.recoveryDelay != RegionAttributesDefault.RECOVERY_DELAY) { |
| nonDefaultAttributes.put(RegionAttributesNames.RECOVERY_DELAY, Long.toString(this.recoveryDelay)); |
| } |
| |
| |
| if (this.startupRecoveryDelay != RegionAttributesDefault.STARTUP_RECOVERY_DELAY) { |
| nonDefaultAttributes.put(RegionAttributesNames.STARTUP_RECOVERY_DELAY, Long.toString(this.startupRecoveryDelay)); |
| } |
| |
| if (this.partitionResolverName != null && !this.partitionResolverName.equals(RegionAttributesDefault.PARTITION_RESOLVER)) { |
| nonDefaultAttributes.put(RegionAttributesNames.PARTITION_RESOLVER, this.partitionResolverName); |
| } |
| } |
| |
| public int getTotalNumBuckets() { |
| return totalNumBuckets; |
| } |
| |
| public int getLocalMaxMemory() { |
| return localMaxMemory; |
| } |
| |
| public int getRedundantCopies() { |
| return redundantCopies; |
| } |
| |
| public String getColocatedWith() { |
| return colocatedWith; |
| } |
| |
| public long getRecoveryDelay() { |
| return recoveryDelay; |
| } |
| |
| public long getStartupRecoveryDelay() { |
| return startupRecoveryDelay; |
| } |
| |
| public String getPartitionResolverName() { |
| return partitionResolverName; |
| } |
| |
| public List<FixedPartitionAttributesInfo> getFixedPartitionAttributesInfo() { |
| return fpaInfoList; |
| } |
| |
| |
| public boolean equals (Object obj) { |
| if (obj instanceof PartitionAttributesInfo) { |
| PartitionAttributesInfo paInfo = (PartitionAttributesInfo) obj; |
| return this.getColocatedWith() == paInfo.getColocatedWith() |
| && this.getLocalMaxMemory() == paInfo.getLocalMaxMemory() |
| && this.getPartitionResolverName() == paInfo.getPartitionResolverName() |
| && this.getRecoveryDelay() == paInfo.getRecoveryDelay() |
| && this.getRedundantCopies() == paInfo.getRedundantCopies() |
| && this.getStartupRecoveryDelay() == paInfo.getStartupRecoveryDelay() |
| && this.getTotalNumBuckets() == paInfo.getTotalNumBuckets() |
| && this.getFixedPartitionAttributesInfo().equals(paInfo.getFixedPartitionAttributesInfo()); |
| } else { |
| return false; |
| } |
| } |
| |
| public int hashCode() { |
| return 42; // any arbitrary constant will do |
| |
| } |
| |
| public Map<String, String> getNonDefaultAttributes() { |
| return nonDefaultAttributes; |
| } |
| } |