use of org.apache.geode.cache.wan.GatewayReceiver in project geode by apache.
the class MyDistributedSystemListener method addedDistributedSystem.
/**
* Please note that dynamic addition of the sender id to region is not yet available.
*/
public void addedDistributedSystem(int remoteDsId) {
cache = CacheFactory.getAnyInstance();
// remoteDsId = 2
if (remoteDsId == 2) {
if (cache != null) {
GatewaySender serialSender = cache.createGatewaySenderFactory().setManualStart(true).setPersistenceEnabled(false).setDiskStoreName("LN_" + remoteDsId).create("LN_" + remoteDsId, remoteDsId);
System.out.println("Sender Created : " + serialSender.getId());
Region region = cache.createRegionFactory().create("MyRegion");
System.out.println("Created Region : " + region.getName());
try {
serialSender.start();
System.out.println("Sender Started: " + serialSender.getId());
} catch (Exception e) {
e.printStackTrace();
}
} else {
throw new CacheClosedException("Cache is not initialized here");
}
} else {
// gatewayReceiver with
if (cache != null) {
Region region = cache.createRegionFactory().create("MyRegion");
System.out.println("Created Region :" + region.getName());
GatewayReceiver receiver = cache.createGatewayReceiverFactory().setStartPort(12345).setManualStart(true).create();
System.out.println("Created GatewayReceiver : " + receiver);
try {
receiver.start();
System.out.println("GatewayReceiver Started.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
use of org.apache.geode.cache.wan.GatewayReceiver in project geode by apache.
the class WANBootStrapping_Site2_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, "" + 2).set(LOCATORS, "localhost[" + 20202 + "]").set(START_LOCATOR, "localhost[" + 20202 + "],server=true,peer=true,hostname-for-clients=localhost").set(REMOTE_LOCATORS, "localhost[" + 10101 + "]").set(LOG_LEVEL, "warning").create();
System.out.println("Cache Created");
// get the region whose size should be 100
Region region = cache.getRegion("MyRegion");
while (region == null) {
region = cache.getRegion("MyRegion");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// region size should be 100. This is the data which will recieve from remote site
while (region.size() != 100) {
continue;
}
System.out.println("Checked region size : " + region.size());
GatewayReceiver receiver = cache.getGatewayReceivers().iterator().next();
// to stop gateway receiver ask to run WANBootStrapping_Site1_Remove program
while (receiver.isRunning()) {
System.out.println("Waitng for receiver to stop through DistributedSystemListener");
System.out.println("Start WANBootStrapping_Site1_Remove ");
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("GatewayReciver " + receiver + " is stopped");
System.exit(0);
}
use of org.apache.geode.cache.wan.GatewayReceiver in project geode by apache.
the class WANTestBase method checkGatewayReceiverStatsHA.
public static void checkGatewayReceiverStatsHA(int processBatches, int eventsReceived, int creates) {
Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers();
GatewayReceiver receiver = gatewayReceivers.iterator().next();
CacheServerStats stats = ((CacheServerImpl) receiver.getServer()).getAcceptor().getStats();
assertTrue(stats instanceof GatewayReceiverStats);
GatewayReceiverStats gatewayReceiverStats = (GatewayReceiverStats) stats;
assertTrue(gatewayReceiverStats.getProcessBatchRequests() >= processBatches);
assertTrue(gatewayReceiverStats.getEventsReceived() >= eventsReceived);
assertTrue(gatewayReceiverStats.getCreateRequest() >= creates);
}
use of org.apache.geode.cache.wan.GatewayReceiver in project geode by apache.
the class WANTestBase method createReceiver_PDX.
public static int createReceiver_PDX(int locPort) {
WANTestBase test = new WANTestBase();
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + locPort + "]");
InternalDistributedSystem ds = test.getSystem(props);
CacheConfig cacheConfig = new CacheConfig();
File pdxDir = new File(CacheTestCase.getDiskDir(), "pdx");
cacheConfig.setPdxPersistent(true);
cacheConfig.setPdxDiskStore("pdxStore");
cache = GemFireCacheImpl.create(ds, false, cacheConfig);
cache.createDiskStoreFactory().setDiskDirs(new File[] { pdxDir }).setMaxOplogSize(1).create("pdxStore");
GatewayReceiverFactory fact = cache.createGatewayReceiverFactory();
int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
fact.setStartPort(port);
fact.setEndPort(port);
fact.setManualStart(true);
GatewayReceiver receiver = fact.create();
try {
receiver.start();
} catch (IOException e) {
e.printStackTrace();
fail("Test " + test.getName() + " failed to start GatewayReceiver on port " + port);
}
return port;
}
use of org.apache.geode.cache.wan.GatewayReceiver in project geode by apache.
the class WANTestBase method createReceiverAndServer.
public static void createReceiverAndServer(int locPort) {
WANTestBase test = new WANTestBase();
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + locPort + "]");
InternalDistributedSystem ds = test.getSystem(props);
cache = CacheFactory.create(ds);
GatewayReceiverFactory fact = cache.createGatewayReceiverFactory();
int receiverPort = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
fact.setStartPort(receiverPort);
fact.setEndPort(receiverPort);
fact.setManualStart(true);
GatewayReceiver receiver = fact.create();
try {
receiver.start();
} catch (IOException e) {
e.printStackTrace();
fail("Test " + test.getName() + " failed to start GatewayReceiver on port " + receiverPort);
}
CacheServer server = cache.addCacheServer();
int serverPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(serverPort);
server.setHostnameForClients("localhost");
try {
server.start();
} catch (IOException e) {
org.apache.geode.test.dunit.Assert.fail("Failed to start server ", e);
}
}
Aggregations