use of org.apache.geode.cache.partition.PartitionListener in project geode by apache.
the class CacheXmlParser method endPartitionListener.
/**
* When a <code>partition-listener</code> element is finished, the {@link Parameter}s and class
* names are popped off the stack. The <code>PartitionListener</code> is instantiated and
* initialized with the parameters, if appropriate.
*/
private void endPartitionListener() {
Declarable d = createDeclarable();
if (!(d instanceof PartitionListener)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_1.toLocalizedString(new Object[] { d.getClass().getName(), "PartitionListener" }));
}
PartitionAttributesImpl pai = peekPartitionAttributesImpl(PARTITION_ATTRIBUTES);
pai.addPartitionListener((PartitionListener) d);
}
use of org.apache.geode.cache.partition.PartitionListener in project geode by apache.
the class PartitionAttributesImpl method equals.
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof PartitionAttributesImpl)) {
return false;
}
PartitionAttributesImpl other = (PartitionAttributesImpl) obj;
if (this.redundancy != other.getRedundantCopies() || getLocalMaxMemory() != other.getLocalMaxMemory() || this.offHeap != other.getOffHeap() || this.totalNumBuckets != other.getTotalNumBuckets() || this.totalMaxMemory != other.getTotalMaxMemory() || this.startupRecoveryDelay != other.getStartupRecoveryDelay() || this.recoveryDelay != other.getRecoveryDelay() || ((this.partitionResolver == null) != (other.getPartitionResolver() == null)) || (this.partitionResolver != null && !this.partitionResolver.equals(other.getPartitionResolver())) || ((this.colocatedRegionName == null) != (other.getColocatedWith() == null)) || (this.colocatedRegionName != null && !this.colocatedRegionName.equals(other.getColocatedWith())) || ((this.fixedPAttrs == null) != (other.getFixedPartitionAttributes() == null)) || (this.fixedPAttrs != null && !this.fixedPAttrs.equals(other.getFixedPartitionAttributes()))) {
return false;
}
PartitionListener[] otherPListeners = other.getPartitionListeners();
PartitionListener[] thisPListeners = this.getPartitionListeners();
if (otherPListeners.length != thisPListeners.length) {
return false;
}
Set<String> otherListenerClassName = new HashSet<>();
for (int i = 0; i < otherPListeners.length; i++) {
PartitionListener listener = otherPListeners[i];
otherListenerClassName.add(listener.getClass().getName());
}
Set<String> thisListenerClassName = new HashSet<>();
for (int i = 0; i < thisPListeners.length; i++) {
PartitionListener listener = thisPListeners[i];
thisListenerClassName.add(listener.getClass().getName());
}
if (!thisListenerClassName.equals(otherListenerClassName)) {
return false;
}
return true;
}
use of org.apache.geode.cache.partition.PartitionListener in project geode by apache.
the class CacheXmlGenerator method generate.
/**
* Generates XML for a <code>PartitionAttributes</code>
*/
private void generate(PartitionAttributes pa) throws SAXException {
AttributesImpl atts = new AttributesImpl();
if (generateDefaults() || pa.getRedundantCopies() != 0)
atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies()));
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault())
atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory()));
if (generateDefaults() || pa.getTotalMaxMemory() != PartitionAttributesFactory.GLOBAL_MAX_MEMORY_DEFAULT)
atts.addAttribute("", "", TOTAL_MAX_MEMORY, "", String.valueOf(pa.getTotalMaxMemory()));
if (generateDefaults() || pa.getTotalNumBuckets() != PartitionAttributesFactory.GLOBAL_MAX_BUCKETS_DEFAULT)
atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
if (pa.getColocatedWith() != null)
atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith());
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay()));
if (generateDefaults() || pa.getStartupRecoveryDelay() != PartitionAttributesFactory.STARTUP_RECOVERY_DELAY_DEFAULT)
atts.addAttribute("", "", STARTUP_RECOVERY_DELAY, "", String.valueOf(pa.getStartupRecoveryDelay()));
}
if (!generateDefaults() && atts.getLength() == 0 && pa.getPartitionResolver() == null && pa.getPartitionListeners().length == 0 && (pa.getFixedPartitionAttributes() == null || pa.getFixedPartitionAttributes().isEmpty())) {
return;
}
handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts);
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
PartitionResolver rr = pa.getPartitionResolver();
if (rr != null) {
generate(PARTITION_RESOLVER, rr);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) {
PartitionListener[] listeners = pa.getPartitionListeners();
for (int i = 0; i < listeners.length; i++) {
PartitionListener listener = listeners[i];
if (listener != null) {
generate(PARTITION_LISTENER, listener);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes();
if (staticAttrs != null) {
generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) {
Properties p = pa.getLocalProperties();
generate(p, LOCAL_PROPERTIES);
p = pa.getGlobalProperties();
generate(p, GLOBAL_PROPERTIES);
}
handler.endElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES);
}
use of org.apache.geode.cache.partition.PartitionListener in project geode by apache.
the class PartitionedRegion method postCreateRegion.
@Override
protected void postCreateRegion() {
super.postCreateRegion();
CacheListener[] listeners = fetchCacheListenersField();
if (listeners != null && listeners.length > 0) {
Set others = getRegionAdvisor().adviseGeneric();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof RegionMembershipListener) {
RegionMembershipListener rml = (RegionMembershipListener) listeners[i];
try {
DistributedMember[] otherDms = new DistributedMember[others.size()];
others.toArray(otherDms);
rml.initialMembers(this, otherDms);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
logger.error(LocalizedMessage.create(LocalizedStrings.DistributedRegion_EXCEPTION_OCCURRED_IN_REGIONMEMBERSHIPLISTENER), t);
}
}
}
}
PartitionListener[] partitionListeners = this.getPartitionListeners();
if (partitionListeners != null && partitionListeners.length != 0) {
for (int i = 0; i < partitionListeners.length; i++) {
PartitionListener listener = partitionListeners[i];
if (listener != null) {
listener.afterRegionCreate(this);
}
}
}
Set<String> allGatewaySenderIds = getAllGatewaySenderIds();
if (!allGatewaySenderIds.isEmpty()) {
for (GatewaySender sender : cache.getAllGatewaySenders()) {
if (sender.isParallel() && allGatewaySenderIds.contains(sender.getId())) {
/*
* get the ParallelGatewaySender to create the colocated partitioned region for this
* region.
*/
if (sender.isRunning()) {
AbstractGatewaySender senderImpl = (AbstractGatewaySender) sender;
((ConcurrentParallelGatewaySenderQueue) senderImpl.getQueues().toArray(new RegionQueue[1])[0]).addShadowPartitionedRegionForUserPR(this);
}
}
}
}
}
use of org.apache.geode.cache.partition.PartitionListener in project geode by apache.
the class PartitionAttributesImplJUnitTest method before.
@Before
public void before() {
this.colocatedRegionFullPath = "colocatedRegionFullPath";
this.globalProps = new Properties();
this.globalProps_key1 = "globalProps_key1";
this.globalProps_value1 = "globalProps_value1";
this.globalProps.setProperty(globalProps_key1, this.globalProps_value1);
this.localProps = new Properties();
this.localProps_key1 = "localProps_key1";
this.localProps_value1 = "localProps_value1";
this.localProps.setProperty(localProps_key1, this.localProps_value1);
this.localMaxMemory = 123;
this.offHeap = false;
this.partitionResolver = new PartitionResolver<Object, Object>() {
@Override
public void close() {
}
@Override
public Object getRoutingObject(EntryOperation opDetails) {
return "partitionResolver_getRoutingObject";
}
@Override
public String getName() {
return "partitionResolver_getName";
}
};
this.recoveryDelay = 234;
this.redundancy = 345;
this.startupRecoveryDelay = 456;
this.totalMaxMemory = 567;
this.maxNumberOfBuckets = 678;
this.newTestAvailableOffHeapMemory = 789;
this.greaterLocalMaxMemory = 890;
this.partitionListener = new PartitionListener() {
@Override
public void afterPrimary(int bucketId) {
}
@Override
public void afterRegionCreate(Region<?, ?> region) {
}
@Override
public void afterBucketRemoved(int bucketId, Iterable<?> keys) {
}
@Override
public void afterBucketCreated(int bucketId, Iterable<?> keys) {
}
};
}
Aggregations