Search in sources :

Example 1 with Delta

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();
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) DeltaTestImpl(org.apache.geode.DeltaTestImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CqEvent(org.apache.geode.cache.query.CqEvent) Delta(org.apache.geode.Delta) CqAttributes(org.apache.geode.cache.query.CqAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 2 with Delta

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);
    }
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) TimeoutException(org.apache.geode.cache.TimeoutException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InternalGemFireException(org.apache.geode.InternalGemFireException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ExecutionException(java.util.concurrent.ExecutionException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) EntryExistsException(org.apache.geode.cache.EntryExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) StatisticsDisabledException(org.apache.geode.cache.StatisticsDisabledException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) FailedSynchronizationException(org.apache.geode.cache.FailedSynchronizationException) NoSuchElementException(java.util.NoSuchElementException) QueryException(org.apache.geode.cache.query.QueryException) RedundancyAlreadyMetException(org.apache.geode.internal.cache.partitioned.RedundancyAlreadyMetException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) LowMemoryException(org.apache.geode.cache.LowMemoryException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) SystemException(javax.transaction.SystemException) SubscriptionNotEnabledException(org.apache.geode.cache.client.SubscriptionNotEnabledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) RegionReinitializedException(org.apache.geode.cache.RegionReinitializedException) CancelException(org.apache.geode.CancelException) DiskAccessException(org.apache.geode.cache.DiskAccessException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) TransactionException(org.apache.geode.cache.TransactionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RollbackException(javax.transaction.RollbackException) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) MultiIndexCreationException(org.apache.geode.cache.query.MultiIndexCreationException) DeltaSerializationException(org.apache.geode.DeltaSerializationException) CacheRuntimeException(org.apache.geode.cache.CacheRuntimeException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Delta(org.apache.geode.Delta) DeltaSerializationException(org.apache.geode.DeltaSerializationException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Aggregations

Delta (org.apache.geode.Delta)2 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 CancelException (org.apache.geode.CancelException)1 DeltaSerializationException (org.apache.geode.DeltaSerializationException)1 DeltaTestImpl (org.apache.geode.DeltaTestImpl)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 CacheException (org.apache.geode.cache.CacheException)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 CacheRuntimeException (org.apache.geode.cache.CacheRuntimeException)1 CacheWriterException (org.apache.geode.cache.CacheWriterException)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)1