com.gemstone.gemfire.management.internal.cli.domain.RegionDescription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.management.internal.cli.domain;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionShortcut;
import com.gemstone.gemfire.cache.Scope;
/***
* Data class which contains description of a region and provides the aggregated
* view of the region Used by describe region command
*
* @author Sourabh Bansod
*
*/
public class RegionDescription implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private boolean isPartition;
private boolean isPersistent;
private boolean isReplicate;
private boolean haslocalDataStorage;
private boolean isLocal = false;
private boolean isReplicatedProxy = false;;
private boolean isAccessor = false;
// Common Non Default Attributes
private Map cndRegionAttributes;
private Map cndPartitionAttributes;
private Map cndEvictionAttributes;
private Map regionDescPerMemberMap = null;
private Scope scope;
private DataPolicy dataPolicy;
public RegionDescription() {
}
public DataPolicy getDataPolicy() {
return this.dataPolicy;
}
public Scope getScope() {
return this.scope;
}
/**
* Adds the RegionDescription per member to the aggregated view
*
* @param regionDescPerMember
*
*/
public boolean add(RegionDescriptionPerMember regionDescPerMember) {
boolean isAdded = false;
if (regionDescPerMemberMap == null) {
regionDescPerMemberMap = new HashMap();
regionDescPerMemberMap.put(regionDescPerMember.getHostingMember(), regionDescPerMember);
this.scope = regionDescPerMember.getScope();
this.dataPolicy = regionDescPerMember.getDataPolicy();
this.name = regionDescPerMember.getName();
isPartition = this.dataPolicy.withPartitioning();
isPersistent = this.dataPolicy.withPersistence();
isReplicate = this.dataPolicy.withReplication();
haslocalDataStorage = this.dataPolicy.withStorage();
isLocal = this.scope.isLocal();
isAccessor = regionDescPerMember.isAccessor();
//COPY
this.cndRegionAttributes = new HashMap();
this.cndRegionAttributes.putAll(regionDescPerMember.getNonDefaultRegionAttributes());
this.cndPartitionAttributes = new HashMap();
this.cndPartitionAttributes.putAll(regionDescPerMember.getNonDefaultPartitionAttributes());
this.cndEvictionAttributes = new HashMap();
this.cndEvictionAttributes.putAll(regionDescPerMember.getNonDefaultEvictionAttributes());
if (this.dataPolicy.equals(DataPolicy.EMPTY) && this.scope.equals(Scope.DISTRIBUTED_ACK)) {
isReplicatedProxy = true;
}
//Don't have to show the scope for PR's
isAdded = true;
} else {
if (this.scope.equals(regionDescPerMember.getScope())
&& this.name.equals(regionDescPerMember.getName())
&& this.dataPolicy.equals(regionDescPerMember.getDataPolicy())
&& this.isAccessor == regionDescPerMember.isAccessor()) {
regionDescPerMemberMap.put(regionDescPerMember.getHostingMember(), regionDescPerMember);
findCommon(cndRegionAttributes, regionDescPerMember.getNonDefaultRegionAttributes());
findCommon(cndEvictionAttributes, regionDescPerMember.getNonDefaultEvictionAttributes());
findCommon(cndPartitionAttributes, regionDescPerMember.getNonDefaultPartitionAttributes());
isAdded = true;
}
}
return isAdded;
}
private void findCommon(Map commonNdMap, Map incomingNdMap) {
//First get the intersection of the both maps
Set commonNdKeySet = commonNdMap.keySet();
Set incomingNdKeySet = incomingNdMap.keySet();
commonNdKeySet.retainAll(incomingNdKeySet);
//Now compare the values
//Take a copy of the set to avoid a CME
Iterator commonKeysIter = (new HashSet(commonNdKeySet)).iterator();
while (commonKeysIter.hasNext()) {
String attribute = commonKeysIter.next();
String commonNdValue = commonNdMap.get(attribute);
String incomingNdValue = incomingNdMap.get(attribute);
if (commonNdValue != null) {
if (!commonNdValue.equals(incomingNdValue)) {
//Remove it from the commonNdMa
commonNdMap.remove(attribute);
}
} else {
if (incomingNdValue != null) {
commonNdMap.remove(attribute);
}
}
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof RegionDescription) {
RegionDescription regionDesc = (RegionDescription) obj;
return this.getName().equals(regionDesc.getName())
&& this.scope.equals(regionDesc.getScope())
&& this.dataPolicy.equals(regionDesc.getDataPolicy());
}
return true;
}
public Set getHostingMembers() {
return regionDescPerMemberMap.keySet();
}
public String getName() {
return this.name;
}
public boolean isPersistent() {
return this.isPersistent;
}
public boolean isPartition() {
return this.isPartition;
}
public boolean isReplicate() {
return this.isReplicate;
}
public boolean hasLocalStorage() {
return this.haslocalDataStorage;
}
public boolean isLocal() {
return this.isLocal;
}
public boolean isReplicatedProxy() {
return this.isReplicatedProxy;
}
public boolean isAccessor() {
return this.isAccessor;
}
/***
* Get
* @return Map containing attribute name and its associated value
*/
public Map getCndRegionAttributes() {
return this.cndRegionAttributes;
}
/***
* Gets the common non-default Eviction Attributes
* @return Map containing attribute name and its associated value
*/
public Map getCndEvictionAttributes() {
return this.cndEvictionAttributes;
}
/***
* Gets the common non-default PartitionAttributes
* @return Map containing attribute name and its associated value
*/
public Map getCndPartitionAttributes() {
return this.cndPartitionAttributes;
}
public Map getRegionDescriptionPerMemberMap(){
return this.regionDescPerMemberMap;
}
public String toString() {
StringBuilder sb = new StringBuilder();
return sb.toString();
}
}