use of org.apache.geode.cache.wan.GatewaySender in project geode by apache.
the class GatewaySenderCreateFunction method execute.
@Override
public void execute(FunctionContext context) {
ResultSender<Object> resultSender = context.getResultSender();
Cache cache = CacheFactory.getAnyInstance();
String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
GatewaySenderFunctionArgs gatewaySenderCreateArgs = (GatewaySenderFunctionArgs) context.getArguments();
try {
GatewaySender createdGatewaySender = createGatewaySender(cache, gatewaySenderCreateArgs);
XmlEntity xmlEntity = new XmlEntity(CacheXml.GATEWAY_SENDER, "id", gatewaySenderCreateArgs.getId());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_GATEWAYSENDER__MSG__GATEWAYSENDER_0_CREATED_ON_1, new Object[] { createdGatewaySender.getId(), memberNameOrId })));
} catch (GatewaySenderException e) {
resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
} catch (Exception e) {
String exceptionMsg = e.getMessage();
if (exceptionMsg == null) {
exceptionMsg = CliUtil.stackTraceAsString(e);
}
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, 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 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);
}
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();
}
}
Aggregations