Search in sources :

Example 36 with GatewaySender

use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.

the class MyGatewayEventSubstitutionFilter method validateAsyncEventQueueAttributes.

/**
   * Validate whether all the attributes set on AsyncEventQueueFactory are set on the sender
   * underneath the AsyncEventQueue.
   */
public static void validateAsyncEventQueueAttributes(String asyncChannelId, int maxQueueMemory, int batchSize, int batchTimeInterval, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, boolean batchConflationEnabled) {
    AsyncEventQueue theChannel = null;
    Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncChannel : asyncEventChannels) {
        if (asyncChannelId.equals(asyncChannel.getId())) {
            theChannel = asyncChannel;
        }
    }
    GatewaySender theSender = ((AsyncEventQueueImpl) theChannel).getSender();
    assertEquals("maxQueueMemory", maxQueueMemory, theSender.getMaximumQueueMemory());
    assertEquals("batchSize", batchSize, theSender.getBatchSize());
    assertEquals("batchTimeInterval", batchTimeInterval, theSender.getBatchTimeInterval());
    assertEquals("isPersistent", isPersistent, theSender.isPersistenceEnabled());
    assertEquals("diskStoreName", diskStoreName, theSender.getDiskStoreName());
    assertEquals("isDiskSynchronous", isDiskSynchronous, theSender.isDiskSynchronous());
    assertEquals("batchConflation", batchConflationEnabled, theSender.isBatchConflationEnabled());
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)

Example 37 with GatewaySender

use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.

the class MyGatewayEventSubstitutionFilter method setRemoveFromQueueOnException.

public static void setRemoveFromQueueOnException(String senderId, boolean removeFromQueue) {
    Set<GatewaySender> senders = cache.getGatewaySenders();
    GatewaySender sender = null;
    for (GatewaySender s : senders) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    assertNotNull(sender);
    ((AbstractGatewaySender) sender).setRemoveFromQueueOnException(removeFromQueue);
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender)

Example 38 with GatewaySender

use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.

the class WANBootStrapping_Site1_Add method main.

public static void main(String[] args) {
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DistributedSystemListener", "com.main.MyDistributedSystemListener");
    // Create a locator and a cache
    System.out.println("Creating cache ...It will take some time..");
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").set(DISTRIBUTED_SYSTEM_ID, "" + 1).set(LOCATORS, "localhost[" + 10101 + "]").set(START_LOCATOR, "localhost[" + 10101 + "],server=true,peer=true,hostname-for-clients=localhost").set(LOG_LEVEL, "warning").create();
    System.out.println("Cache Created");
    // to create region and a gateway sender ask to run
    // WANBootStrapping_Site2_Add program
    System.out.println("Run WANBootStrapping_Site2_Add");
    // get the region
    Region region = cache.getRegion("MyRegion");
    while (region == null) {
        region = cache.getRegion("MyRegion");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    // put data in region
    for (int i = 0; i < 100; i++) {
        System.out.println("Create Entry : key_" + i + ", value_" + i);
        region.put("key_" + i, "value_" + i);
    }
    System.out.println("Entry Create Operation completed");
    Set<GatewaySender> gatewaySenders = cache.getGatewaySenders();
    GatewaySender sender = gatewaySenders.iterator().next();
    // make sure that gateway sender is running
    if (sender.isRunning()) {
        System.out.println("Sender " + sender.getId() + " is running");
    }
    // to stop gateway sender ask to run WANBootStrapping_Site2_Remove program
    while (sender.isRunning()) {
        System.out.println("Waitng for sender to stop through DistributedSystemListener");
        System.out.println("Start WANBootStrapping_Site2_Remove");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Sender " + sender.getId() + " is stopped");
    System.exit(0);
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 39 with GatewaySender

use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.

the class MyDistributedSystemListener method removedDistributedSystem.

public void removedDistributedSystem(int remoteDsId) {
    cache = CacheFactory.getAnyInstance();
    if (remoteDsId == 2) {
        // with remoteDsId = 2
        if (cache != null) {
            GatewaySender sender = cache.getGatewaySender("LN_" + 2);
            sender.stop();
        }
    } else {
        // When a site with distributed-system-id = -1 joins, stop gatewayReceiver
        GatewayReceiver receiver = cache.getGatewayReceivers().iterator().next();
        receiver.stop();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver)

Example 40 with GatewaySender

use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.

the class GemFireCacheImpl method close.

public void close(String reason, Throwable systemFailureCause, boolean keepAlive, boolean keepDS) {
    this.securityService.close();
    if (isClosed()) {
        return;
    }
    final boolean isDebugEnabled = logger.isDebugEnabled();
    synchronized (GemFireCacheImpl.class) {
        // static synchronization is necessary due to static resources
        if (isClosed()) {
            return;
        }
        /*
       * First close the ManagementService as it uses a lot of infra which will be closed by
       * cache.close()
       */
        this.system.handleResourceEvent(ResourceEvent.CACHE_REMOVE, this);
        if (this.resourceEventsListener != null) {
            this.system.removeResourceListener(this.resourceEventsListener);
            this.resourceEventsListener = null;
        }
        if (systemFailureCause != null) {
            this.forcedDisconnect = systemFailureCause instanceof ForcedDisconnectException;
            if (this.forcedDisconnect) {
                this.disconnectCause = new ForcedDisconnectException(reason);
            } else {
                this.disconnectCause = systemFailureCause;
            }
        }
        this.keepAlive = keepAlive;
        this.isClosing = true;
        logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_NOW_CLOSING, this));
        // available to anyone "fishing" for a cache...
        if (GemFireCacheImpl.instance == this) {
            GemFireCacheImpl.instance = null;
        }
        // threads may be hung trying to communicate with the map locked
        if (systemFailureCause == null) {
            PartitionedRegion.clearPRIdMap();
        }
        TXStateProxy tx = null;
        try {
            if (this.transactionManager != null) {
                tx = this.transactionManager.internalSuspend();
            }
            // do this before closing regions
            this.resourceManager.close();
            try {
                this.resourceAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            try {
                this.jmxAdvisor.close();
            } catch (CancelException ignore) {
            // ignore
            }
            for (GatewaySender sender : this.allGatewaySenders) {
                try {
                    sender.stop();
                    GatewaySenderAdvisor advisor = ((AbstractGatewaySender) sender).getSenderAdvisor();
                    if (advisor != null) {
                        if (isDebugEnabled) {
                            logger.debug("Stopping the GatewaySender advisor");
                        }
                        advisor.close();
                    }
                } catch (CancelException ignore) {
                }
            }
            destroyGatewaySenderLockService();
            if (this.eventThreadPool != null) {
                if (isDebugEnabled) {
                    logger.debug("{}: stopping event thread pool...", this);
                }
                this.eventThreadPool.shutdown();
            }
            /*
         * IMPORTANT: any operation during shut down that can time out (create a CancelException)
         * must be inside of this try block. If all else fails, we *must* ensure that the cache gets
         * closed!
         */
            try {
                this.stopServers();
                stopMemcachedServer();
                stopRedisServer();
                stopRestAgentServer();
                // cacheServers or gatewayHubs
                if (this.partitionedRegions != null) {
                    if (isDebugEnabled) {
                        logger.debug("{}: clearing partitioned regions...", this);
                    }
                    synchronized (this.partitionedRegions) {
                        int prSize = -this.partitionedRegions.size();
                        this.partitionedRegions.clear();
                        getCachePerfStats().incPartitionedRegions(prSize);
                    }
                }
                prepareDiskStoresForClose();
                if (GemFireCacheImpl.pdxInstance == this) {
                    GemFireCacheImpl.pdxInstance = null;
                }
                List<LocalRegion> rootRegionValues;
                synchronized (this.rootRegions) {
                    rootRegionValues = new ArrayList<>(this.rootRegions.values());
                }
                {
                    final Operation op;
                    if (this.forcedDisconnect) {
                        op = Operation.FORCED_DISCONNECT;
                    } else if (isReconnecting()) {
                        op = Operation.CACHE_RECONNECT;
                    } else {
                        op = Operation.CACHE_CLOSE;
                    }
                    LocalRegion prRoot = null;
                    for (LocalRegion lr : rootRegionValues) {
                        if (isDebugEnabled) {
                            logger.debug("{}: processing region {}", this, lr.getFullPath());
                        }
                        if (PartitionedRegionHelper.PR_ROOT_REGION_NAME.equals(lr.getName())) {
                            prRoot = lr;
                        } else {
                            if (lr.getName().contains(ParallelGatewaySenderQueue.QSTRING)) {
                                // this region will be closed internally by parent region
                                continue;
                            }
                            if (isDebugEnabled) {
                                logger.debug("{}: closing region {}...", this, lr.getFullPath());
                            }
                            try {
                                lr.handleCacheClose(op);
                            } catch (RuntimeException e) {
                                if (isDebugEnabled || !this.forcedDisconnect) {
                                    logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_CLOSING_REGION_1, new Object[] { this, lr.getFullPath() }), e);
                                }
                            }
                        }
                    }
                    try {
                        if (isDebugEnabled) {
                            logger.debug("{}: finishing partitioned region close...", this);
                        }
                        PartitionedRegion.afterRegionsClosedByCacheClose(this);
                        if (prRoot != null) {
                            // do the PR meta root region last
                            prRoot.handleCacheClose(op);
                        }
                    } catch (CancelException e) {
                        logger.warn(LocalizedMessage.create(LocalizedStrings.GemFireCache_0_ERROR_IN_LAST_STAGE_OF_PARTITIONEDREGION_CACHE_CLOSE, this), e);
                    }
                    destroyPartitionedRegionLockService();
                }
                closeDiskStores();
                this.diskMonitor.close();
                // Close the CqService Handle.
                try {
                    if (isDebugEnabled) {
                        logger.debug("{}: closing CQ service...", this);
                    }
                    this.cqService.close();
                } catch (RuntimeException ignore) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_1));
                }
                PoolManager.close(keepAlive);
                if (isDebugEnabled) {
                    logger.debug("{}: notifying admins of close...", this);
                }
                try {
                    SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CLOSE);
                } catch (CancelException ignore) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ignored cancellation while notifying admins");
                    }
                }
                if (isDebugEnabled) {
                    logger.debug("{}: stopping destroyed entries processor...", this);
                }
                this.tombstoneService.stop();
                // NOTICE: the CloseCache message is the *last* message you can send!
                DM distributionManager = null;
                try {
                    distributionManager = this.system.getDistributionManager();
                    distributionManager.removeMembershipListener(this.transactionManager);
                } catch (CancelException ignore) {
                // distributionManager = null;
                }
                if (distributionManager != null) {
                    // Send CacheClosedMessage (and NOTHING ELSE) here
                    if (isDebugEnabled) {
                        logger.debug("{}: sending CloseCache to peers...", this);
                    }
                    Set otherMembers = distributionManager.getOtherDistributionManagerIds();
                    ReplyProcessor21 processor = new ReplyProcessor21(this.system, otherMembers);
                    CloseCacheMessage msg = new CloseCacheMessage();
                    msg.setRecipients(otherMembers);
                    msg.setProcessorId(processor.getProcessorId());
                    distributionManager.putOutgoing(msg);
                    try {
                        processor.waitForReplies();
                    } catch (InterruptedException ignore) {
                    // Thread.currentThread().interrupt(); // TODO ??? should we reset this bit later?
                    // Keep going, make best effort to shut down.
                    } catch (ReplyException ignore) {
                    // keep going
                    }
                // set closed state after telling others and getting responses
                // to avoid complications with others still in the process of
                // sending messages
                }
                // NO MORE Distributed Messaging AFTER THIS POINT!!!!
                ClientMetadataService cms = this.clientMetadataService;
                if (cms != null) {
                    cms.close();
                }
                closeHeapEvictor();
                closeOffHeapEvictor();
            } catch (CancelException ignore) {
                // make sure the disk stores get closed
                closeDiskStores();
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            }
            // Close the CqService Handle.
            try {
                this.cqService.close();
            } catch (RuntimeException ignore) {
                logger.info(LocalizedMessage.create(LocalizedStrings.GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_2));
            }
            this.cachePerfStats.close();
            TXLockService.destroyServices();
            EventTracker.stopTrackerServices(this);
            synchronized (this.ccpTimerMutex) {
                if (this.ccpTimer != null) {
                    this.ccpTimer.cancel();
                }
            }
            this.expirationScheduler.cancel();
            // Stop QueryMonitor if running.
            if (this.queryMonitor != null) {
                this.queryMonitor.stopMonitoring();
            }
            stopDiskStoreTaskPool();
        } finally {
            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
            if (this.transactionManager != null) {
                this.transactionManager.close();
            }
            ((DynamicRegionFactoryImpl) DynamicRegionFactory.get()).close();
            if (this.transactionManager != null) {
                this.transactionManager.internalResume(tx);
            }
            TXCommitMessage.getTracker().clearForCacheClose();
        }
        // Added to close the TransactionManager's cleanup thread
        TransactionManagerImpl.refresh();
        if (!keepDS) {
            // keepDS is used by ShutdownAll. It will override DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE
            if (!this.DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE) {
                this.system.disconnect();
            }
        }
        TypeRegistry.close();
        // do this late to prevent 43412
        TypeRegistry.setPdxSerializer(null);
        for (CacheLifecycleListener listener : cacheLifecycleListeners) {
            listener.cacheClosed(this);
        }
        // Fix for #49856
        SequenceLoggerImpl.signalCacheClose();
        SystemFailure.signalCacheClose();
    }
// static synchronization on GemFireCache.class
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentHashSet(org.apache.geode.internal.concurrent.ConcurrentHashSet) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) DM(org.apache.geode.distributed.internal.DM) GatewaySenderAdvisor(org.apache.geode.internal.cache.wan.GatewaySenderAdvisor) Operation(org.apache.geode.cache.Operation) ReplyException(org.apache.geode.distributed.internal.ReplyException) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) CancelException(org.apache.geode.CancelException) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Aggregations

GatewaySender (org.apache.geode.cache.wan.GatewaySender)116 RegionQueue (org.apache.geode.internal.cache.RegionQueue)28 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)28 Test (org.junit.Test)17 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 Region (org.apache.geode.cache.Region)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)9 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)9 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)9 DiskStore (org.apache.geode.cache.DiskStore)8 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)8 ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)8 Expectations (org.jmock.Expectations)8 GatewayTransportFilter (org.apache.geode.cache.wan.GatewayTransportFilter)7 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)7 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5