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;
}
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;
}
}
use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.
the class CacheXmlGenerator method parse.
/**
* Called by the transformer to parse the "input source". We ignore the input source and, instead,
* generate SAX events to the {@link #setContentHandler ContentHandler}.
*/
public void parse(InputSource input) throws SAXException {
Assert.assertTrue(this.handler != null);
boolean isClientCache = this.creation instanceof ClientCacheCreation;
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
if (this.useSchema) {
if (null == version.getSchemaLocation()) {
// TODO jbarrett - localize
throw new IllegalStateException("No schema for version " + version.getVersion());
}
// add schema location for cache schema.
handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
// add cache schema to default prefix.
handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
addAttribute(atts, VERSION, this.version.getVersion());
}
if (creation.hasLockLease()) {
atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
}
if (creation.hasLockTimeout()) {
atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
}
if (creation.hasSearchTimeout()) {
atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (creation.hasMessageSyncInterval()) {
atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
if (creation.hasServer()) {
atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
}
if (creation.hasCopyOnRead()) {
atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
}
}
if (isClientCache) {
handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
} else {
handler.startElement("", CACHE, CACHE, atts);
}
if (this.cache != null) {
if (!isClientCache) {
generate(this.cache.getCacheTransactionManager());
} else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generate(this.cache.getCacheTransactionManager());
}
generateDynamicRegionFactory(this.cache);
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
Set<GatewaySender> senderSet = cache.getGatewaySenders();
for (GatewaySender sender : senderSet) {
generateGatewaySender(sender);
}
generateGatewayReceiver(this.cache);
generateAsyncEventQueue(this.cache);
}
}
if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
if (this.cache.getGatewayConflictResolver() != null) {
generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
}
}
if (!isClientCache) {
for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
CacheServer bridge = (CacheServer) iter.next();
generate(bridge);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
Iterator pools;
if (this.cache instanceof GemFireCacheImpl) {
pools = PoolManager.getAll().values().iterator();
} else {
pools = this.creation.getPools().values().iterator();
}
while (pools.hasNext()) {
Pool cp = (Pool) pools.next();
generate(cp);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache gfc = (InternalCache) this.cache;
for (DiskStore ds : gfc.listDiskStores()) {
generate(ds);
}
} else {
for (DiskStore ds : this.creation.listDiskStores()) {
generate(ds);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generatePdx();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
Map namedAttributes = this.cache.listRegionAttributes();
for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String id = (String) entry.getKey();
RegionAttributes attrs = (RegionAttributes) entry.getValue();
// Since CacheCreation predefines these even in later versions
// we need to exclude them in all versions.
// It would be better if CacheCreation could only predefine them
// for versions 6.5 and later but that is not easy to do
{
if (this.creation instanceof ClientCacheCreation) {
try {
ClientRegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
} else {
try {
RegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
}
}
generate(id, attrs);
}
}
if (cache instanceof GemFireCacheImpl) {
generateRegions();
} else {
TreeSet rSet = new TreeSet(new RegionComparator());
rSet.addAll(this.cache.rootRegions());
Iterator it = rSet.iterator();
while (it.hasNext()) {
Region root = (Region) it.next();
generateRegion(root);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
generateFunctionService();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
generateResourceManager();
generateSerializerRegistration();
}
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache internalCache = (InternalCache) this.cache;
for (File file : internalCache.getBackupFiles()) {
generateBackupFile(file);
}
} else {
for (File file : this.creation.getBackupFiles()) {
generateBackupFile(file);
}
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generateInitializer();
}
}
if (cache instanceof Extensible) {
@SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
generate(extensible);
}
if (isClientCache) {
handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
} else {
handler.endElement("", CACHE, CACHE);
}
handler.endDocument();
}
use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.
the class CacheCreation method create.
/**
* Fills in the contents of a {@link Cache} based on this creation object's state.
*/
void create(InternalCache cache) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
this.extensionPoint.beforeCreate(cache);
cache.setDeclarativeCacheConfig(this.cacheConfig);
if (cache.isClient()) {
throw new IllegalStateException("You must use client-cache in the cache.xml when ClientCacheFactory is used.");
}
if (this.hasLockLease()) {
cache.setLockLease(this.lockLease);
}
if (this.hasLockTimeout()) {
cache.setLockTimeout(this.lockTimeout);
}
if (this.hasSearchTimeout()) {
cache.setSearchTimeout(this.searchTimeout);
}
if (this.hasMessageSyncInterval()) {
cache.setMessageSyncInterval(this.getMessageSyncInterval());
}
if (this.gatewayConflictResolver != null) {
cache.setGatewayConflictResolver(this.gatewayConflictResolver);
}
// create connection pools
Map<String, Pool> pools = getPools();
if (!pools.isEmpty()) {
for (Pool pool : pools.values()) {
PoolFactoryImpl poolFactory = (PoolFactoryImpl) PoolManager.createFactory();
poolFactory.init(pool);
poolFactory.create(pool.getName());
}
}
if (hasResourceManager()) {
// moved this up to fix bug 42128
getResourceManager().configure(cache.getResourceManager());
}
DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache);
cache.initializePdxRegistry();
for (DiskStore diskStore : this.diskStores.values()) {
DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) diskStore;
if (creation != pdxRegDSC) {
createDiskStore(creation, cache);
}
}
if (this.hasDynamicRegionFactory()) {
DynamicRegionFactory.get().open(this.getDynamicRegionFactoryConfig());
}
if (this.hasServer()) {
cache.setIsServer(this.isServer);
}
if (this.hasCopyOnRead()) {
cache.setCopyOnRead(this.copyOnRead);
}
if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) {
cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners());
}
if (this.txMgrCreation != null && cache.getCacheTransactionManager() != null) {
cache.getCacheTransactionManager().setWriter(this.txMgrCreation.getWriter());
}
for (GatewaySender senderCreation : this.getGatewaySenders()) {
GatewaySenderFactory factory = cache.createGatewaySenderFactory();
((InternalGatewaySenderFactory) factory).configureGatewaySender(senderCreation);
GatewaySender gatewaySender = factory.create(senderCreation.getId(), senderCreation.getRemoteDSId());
// Start the sender if it is not set to manually start
if (gatewaySender.isManualStart()) {
cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, gatewaySender);
}
}
for (AsyncEventQueue asyncEventQueueCreation : this.getAsyncEventQueues()) {
AsyncEventQueueFactoryImpl asyncQueueFactory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
asyncQueueFactory.configureAsyncEventQueue(asyncEventQueueCreation);
AsyncEventQueue asyncEventQueue = cache.getAsyncEventQueue(asyncEventQueueCreation.getId());
if (asyncEventQueue == null) {
asyncQueueFactory.create(asyncEventQueueCreation.getId(), asyncEventQueueCreation.getAsyncEventListener());
}
}
cache.initializePdxRegistry();
for (String id : this.regionAttributesNames) {
RegionAttributesCreation creation = (RegionAttributesCreation) getRegionAttributes(id);
creation.inheritAttributes(cache, false);
// Don't let the RegionAttributesCreation escape to the user
AttributesFactory<?, ?> factory = new AttributesFactory<>(creation);
RegionAttributes<?, ?> attrs = factory.create();
cache.setRegionAttributes(id, attrs);
}
initializeRegions(this.roots, cache);
cache.readyDynamicRegionFactory();
// Create and start the BridgeServers. This code was moved from
// before region initialization to after it to fix bug 33587.
// Create and start the CacheServers after the gateways have been initialized
// to fix bug 39736.
Integer serverPort = CacheServerLauncher.getServerPort();
String serverBindAdd = CacheServerLauncher.getServerBindAddress();
Boolean disableDefaultServer = CacheServerLauncher.getDisableDefaultServer();
startCacheServers(getCacheServers(), cache, serverPort, serverBindAdd, disableDefaultServer);
for (GatewayReceiver receiverCreation : this.getGatewayReceivers()) {
GatewayReceiverFactory factory = cache.createGatewayReceiverFactory();
factory.setBindAddress(receiverCreation.getBindAddress());
factory.setMaximumTimeBetweenPings(receiverCreation.getMaximumTimeBetweenPings());
factory.setStartPort(receiverCreation.getStartPort());
factory.setEndPort(receiverCreation.getEndPort());
factory.setSocketBufferSize(receiverCreation.getSocketBufferSize());
factory.setManualStart(receiverCreation.isManualStart());
for (GatewayTransportFilter filter : receiverCreation.getGatewayTransportFilters()) {
factory.addGatewayTransportFilter(filter);
}
factory.setHostnameForSenders(receiverCreation.getHost());
GatewayReceiver receiver = factory.create();
if (receiver.isManualStart()) {
cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, receiver);
}
}
cache.setBackupFiles(this.backups);
cache.addDeclarableProperties(this.declarablePropertiesMap);
runInitializer();
cache.setInitializer(getInitializer(), getInitializerProps());
// Create all extensions
this.extensionPoint.fireCreate(cache);
}
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;
}
Aggregations