Search in sources :

Example 1 with GatewaySender

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

the class AsyncEventQueueFactoryImpl method create.

public AsyncEventQueue create(String asyncQueueId, AsyncEventListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException(LocalizedStrings.AsyncEventQueue_ASYNC_EVENT_LISTENER_CANNOT_BE_NULL.toLocalizedString());
    }
    AsyncEventQueue asyncEventQueue = null;
    if (this.cache instanceof GemFireCacheImpl) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating GatewaySender that underlies the AsyncEventQueue");
        }
        addAsyncEventListener(listener);
        GatewaySender sender = create(AsyncEventQueueImpl.getSenderIdFromAsyncEventQueueId(asyncQueueId));
        AsyncEventQueueImpl queue = new AsyncEventQueueImpl(sender, listener);
        asyncEventQueue = queue;
        this.cache.addAsyncEventQueue(queue);
    } else if (this.cache instanceof CacheCreation) {
        asyncEventQueue = new AsyncEventQueueCreation(asyncQueueId, attrs, listener);
        ((CacheCreation) cache).addAsyncEventQueue(asyncEventQueue);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Returning AsyncEventQueue" + asyncEventQueue);
    }
    return asyncEventQueue;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) SerialAsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.SerialAsyncEventQueueCreation) AsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.AsyncEventQueueCreation) ParallelAsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.ParallelAsyncEventQueueCreation) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation)

Example 2 with GatewaySender

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

the class DynamicRegionFactory method doInternalInit.

/**
   * The method is for internal use only. It is called implicitly during cache creation.
   * <p>
   * This method is called internally during cache initialization at the correct time. Initialize
   * the factory with a GemFire Cache. We create the metadata Region which holds all our dynamically
   * created regions.
   * 
   * @param theCache The GemFire {@code Cache}
   */
protected void doInternalInit(InternalCache theCache) throws CacheException {
    if (isClosed()) {
        // DynamicRegions are not enabled in this vm. Just return.
        return;
    }
    try {
        this.cache = theCache;
        this.dynamicRegionList = theCache.getRegion(dynamicRegionListName);
        final boolean isClient = this.config.getPoolName() != null;
        if (this.dynamicRegionList == null) {
            InternalRegionArguments ira = new InternalRegionArguments().setDestroyLockFlag(true).setInternalRegion(true).setSnapshotInputStream(null).setImageTarget(null);
            AttributesFactory af = new AttributesFactory();
            if (this.config.getPersistBackup()) {
                af.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
                af.setDiskWriteAttributes(new DiskWriteAttributesFactory().create());
                if (this.config.getDiskDir() != null) {
                    af.setDiskDirs(new File[] { this.config.getDiskDir() });
                }
            }
            if (isClient) {
                af.setScope(Scope.LOCAL);
                // MirrorType(MirrorType.NONE);
                af.setDataPolicy(DataPolicy.NORMAL);
                af.setStatisticsEnabled(true);
                String cpName = this.config.getPoolName();
                if (cpName != null) {
                    Pool cp = PoolManager.find(cpName);
                    if (cp == null) {
                        throw new IllegalStateException("Invalid pool name specified. This pool is not registered with the cache: " + cpName);
                    } else {
                        if (!cp.getSubscriptionEnabled()) {
                            throw new IllegalStateException("The client pool of a DynamicRegionFactory must be configured with queue-enabled set to true.");
                        }
                        af.setPoolName(cpName);
                    }
                }
                ira.setInternalMetaRegion(new LocalMetaRegion(af.create(), ira));
            } else {
                af.setScope(Scope.DISTRIBUTED_ACK);
                if (!this.config.getPersistBackup()) {
                    // if persistBackup, the data policy has already
                    // been set
                    // setMirrorType(MirrorType.KEYS_VALUES);
                    af.setDataPolicy(DataPolicy.REPLICATE);
                }
                for (GatewaySender gs : this.cache.getGatewaySenders()) {
                    if (!gs.isParallel())
                        af.addGatewaySenderId(gs.getId());
                }
                // bug fix 35432
                ira.setInternalMetaRegion(new DistributedMetaRegion(af.create()));
            }
            try {
                this.dynamicRegionList = theCache.createVMRegion(dynamicRegionListName, af.create(), ira);
            } catch (IOException e) {
                // only if loading snapshot, not here
                throw new InternalGemFireError(LocalizedStrings.DynamicRegionFactory_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
            } catch (ClassNotFoundException e) {
                // only if loading snapshot, not here
                throw new InternalGemFireError(LocalizedStrings.DynamicRegionFactory_UNEXPECTED_EXCEPTION.toLocalizedString(), e);
            }
            if (isClient) {
                this.dynamicRegionList.registerInterest("ALL_KEYS");
            }
            if (theCache.getLoggerI18n().fineEnabled()) {
                theCache.getLoggerI18n().fine("Created dynamic region: " + this.dynamicRegionList);
            }
        } else {
            if (theCache.getLoggerI18n().fineEnabled()) {
                theCache.getLoggerI18n().fine("Retrieved dynamic region: " + this.dynamicRegionList);
            }
        }
        createDefinedDynamicRegions();
    } catch (CacheException e) {
        theCache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR_INITIALIZING_DYNAMICREGIONFACTORY, e);
        throw e;
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) IOException(java.io.IOException) Pool(org.apache.geode.cache.client.Pool) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 3 with GatewaySender

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

the class AbstractGatewaySenderEventProcessor method addPDXEvent.

private List<GatewaySenderEventImpl> addPDXEvent() throws IOException {
    List<GatewaySenderEventImpl> pdxEventsToBeDispatched = new ArrayList<GatewaySenderEventImpl>();
    // getPDXRegion
    InternalCache cache = this.sender.getCache();
    Region<Object, Object> pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
    if (rebuildPdxList) {
        pdxEventsMap.clear();
        pdxSenderEventsList.clear();
        rebuildPdxList = false;
    }
    // PDX region
    if (pdxRegion != null && pdxRegion.size() != pdxEventsMap.size()) {
        for (Map.Entry<Object, Object> typeEntry : pdxRegion.entrySet()) {
            if (!pdxEventsMap.containsKey(typeEntry.getKey())) {
                // event should never be off-heap so it does not need to be released
                EntryEventImpl event = EntryEventImpl.create((LocalRegion) pdxRegion, Operation.UPDATE, typeEntry.getKey(), typeEntry.getValue(), null, false, cache.getMyId());
                event.disallowOffHeapValues();
                event.setEventId(new EventID(cache.getInternalDistributedSystem()));
                List<Integer> allRemoteDSIds = new ArrayList<Integer>();
                for (GatewaySender sender : cache.getGatewaySenders()) {
                    allRemoteDSIds.add(sender.getRemoteDSId());
                }
                GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(event.getRawCallbackArgument(), this.sender.getMyDSId(), allRemoteDSIds);
                event.setCallbackArgument(geCallbackArg);
                GatewaySenderEventImpl pdxSenderEvent = // OFFHEAP:
                new GatewaySenderEventImpl(EnumListenerEvent.AFTER_UPDATE, event, null);
                // event for
                // pdx type
                // meta data
                // so it
                // should
                // never be
                // off-heap
                pdxEventsMap.put(typeEntry.getKey(), pdxSenderEvent);
                pdxSenderEventsList.add(pdxSenderEvent);
            }
        }
    }
    Iterator<GatewaySenderEventImpl> iterator = pdxSenderEventsList.iterator();
    while (iterator.hasNext()) {
        GatewaySenderEventImpl pdxEvent = iterator.next();
        if (pdxEvent.isAcked) {
            // Since this is acked, it means it has reached to remote site.Dont add
            // to pdxEventsToBeDispatched
            iterator.remove();
            continue;
        }
        if (pdxEvent.isDispatched) {
            // containing this event.Dont add to pdxEventsToBeDispatched
            continue;
        }
        pdxEventsToBeDispatched.add(pdxEvent);
    }
    if (!pdxEventsToBeDispatched.isEmpty() && logger.isDebugEnabled()) {
        logger.debug("List of PDX Event to be dispatched : {}", pdxEventsToBeDispatched);
    }
    // add all these pdx events before filtered events
    return pdxEventsToBeDispatched;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with GatewaySender

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

the class ManagementAdapter method cleanUpMonitors.

private void cleanUpMonitors() {
    MemberMBean bean = (MemberMBean) service.getMemberMXBean();
    if (bean != null) {
        bean.stopMonitor();
    }
    Set<GatewaySender> senders = internalCache.getGatewaySenders();
    if (senders != null && senders.size() > 0) {
        for (GatewaySender sender : senders) {
            GatewaySenderMBean senderMBean = (GatewaySenderMBean) service.getLocalGatewaySenderMXBean(sender.getId());
            if (senderMBean != null) {
                senderMBean.stopMonitor();
            }
        }
    }
    GatewayReceiverMBean receiver = (GatewayReceiverMBean) service.getLocalGatewayReceiverMXBean();
    if (receiver != null) {
        receiver.stopMonitor();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender)

Example 5 with GatewaySender

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

the class GatewaySenderDestroyFunction method execute.

@Override
public void execute(FunctionContext context) {
    ResultSender<Object> resultSender = context.getResultSender();
    Cache cache = CacheFactory.getAnyInstance();
    String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    GatewaySenderDestroyFunctionArgs gatewaySenderDestroyFunctionArgs = (GatewaySenderDestroyFunctionArgs) context.getArguments();
    try {
        GatewaySender gatewaySender = cache.getGatewaySender(gatewaySenderDestroyFunctionArgs.getId());
        if (gatewaySender != null) {
            gatewaySender.stop();
            gatewaySender.destroy();
        } else {
            throw new GatewaySenderException("GateWaySender with Id  " + gatewaySenderDestroyFunctionArgs.getId() + " not found");
        }
        resultSender.lastResult(new CliFunctionResult(memberNameOrId, true, CliStrings.format(CliStrings.DESTROY_GATEWAYSENDER__MSG__GATEWAYSENDER_0_DESTROYED_ON_1, new Object[] { gatewaySenderDestroyFunctionArgs.getId(), memberNameOrId })));
    } catch (GatewaySenderException gse) {
        resultSender.lastResult(handleException(memberNameOrId, gse.getMessage(), gse));
    } catch (Exception e) {
        String exceptionMsg = e.getMessage();
        if (exceptionMsg == null) {
            exceptionMsg = CliUtil.stackTraceAsString(e);
        }
        resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) Cache(org.apache.geode.cache.Cache)

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