use of org.apache.geode.Delta in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
queryUpdateExecuted = false;
queryDestroyExecuted = false;
notADeltaInstanceObj = false;
isFailed = false;
procced = false;
numValidCqEvents = 0;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
if (subscriptionEnable.booleanValue()) {
deltaPR.registerInterest("ALL_KEYS");
}
pool = p;
if (isCq.booleanValue()) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
@SuppressWarnings("synthetic-access")
public void onEvent(CqEvent cqEvent) {
if (LAST_KEY.equals(cqEvent.getKey().toString())) {
lastKeyReceived = true;
} else if (!(cqEvent.getNewValue() instanceof Delta)) {
notADeltaInstanceObj = true;
} else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryUpdateExecuted = true;
} else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryDestroyExecuted = true;
}
if (forOldNewCQVarification) {
if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
procced = true;
} else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
// this tell us that every thing is fine
isFailed = true;
}
}
}
numValidCqEvents++;
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
cq.execute();
}
}
use of org.apache.geode.Delta in project geode by apache.
the class LocalRegion method extractDeltaIntoEvent.
private void extractDeltaIntoEvent(Object value, EntryEventImpl event) {
// 11. Wrap any checked exception in InternalGemFireException before throwing it.
try {
// How costly is this if check?
if (getSystem().getConfig().getDeltaPropagation() && value instanceof Delta) {
boolean extractDelta = false;
if (!this.hasServerProxy()) {
if (this instanceof PartitionedRegion) {
if (((PartitionedRegion) this).getRedundantCopies() > 0) {
extractDelta = true;
} else {
InternalDistributedMember ids = (InternalDistributedMember) PartitionRegionHelper.getPrimaryMemberForKey(this, event.getKey());
if (ids != null) {
extractDelta = !this.getSystem().getMemberId().equals(ids.getId()) || hasAdjunctRecipientsNeedingDelta(event);
} else {
extractDelta = true;
}
}
} else if (this instanceof DistributedRegion && !((DistributedRegion) this).scope.isDistributedNoAck() && !((CacheDistributionAdvisee) this).getCacheDistributionAdvisor().adviseCacheOp().isEmpty()) {
extractDelta = true;
}
if (!extractDelta && ClientHealthMonitor.getInstance() != null) {
extractDelta = ClientHealthMonitor.getInstance().hasDeltaClients();
}
} else if (HandShake.isDeltaEnabledOnServer()) {
// This is a client region
extractDelta = true;
}
if (extractDelta && ((org.apache.geode.Delta) value).hasDelta()) {
HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
long start = DistributionStats.getStatTime();
try {
((org.apache.geode.Delta) value).toDelta(hdos);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new DeltaSerializationException(LocalizedStrings.DistributionManager_CAUGHT_EXCEPTION_WHILE_SENDING_DELTA.toLocalizedString(), e);
}
event.setDeltaBytes(hdos.toByteArray());
this.getCachePerfStats().endDeltaPrepared(start);
}
}
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new InternalGemFireException(e);
}
}
Aggregations