use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
queryUpdateExecuted = false;
queryDestroyExecuted = false;
notADeltaInstanceObj = false;
isFailed = false;
procced = false;
numValidCqEvents = 0;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
if (subscriptionEnable.booleanValue()) {
deltaPR.registerInterest("ALL_KEYS");
}
pool = p;
if (isCq.booleanValue()) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
@SuppressWarnings("synthetic-access")
public void onEvent(CqEvent cqEvent) {
if (LAST_KEY.equals(cqEvent.getKey().toString())) {
lastKeyReceived = true;
} else if (!(cqEvent.getNewValue() instanceof Delta)) {
notADeltaInstanceObj = true;
} else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryUpdateExecuted = true;
} else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryDestroyExecuted = true;
}
if (forOldNewCQVarification) {
if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
procced = true;
} else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
// this tell us that every thing is fine
isFailed = true;
}
}
}
numValidCqEvents++;
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
cq.execute();
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClientCommandsDUnitTest method startNonDurableClient.
private void startNonDurableClient(VM client, final VM server, final int port) {
client.invoke("start non-durable client", () -> {
Cache cache = GemFireCacheImpl.getInstance();
if (cache == null) {
Properties props = getNonDurableClientProps();
props.setProperty(LOG_FILE, "client_" + OSProcess.getId() + ".log");
props.setProperty(LOG_LEVEL, "fine");
props.setProperty(STATISTIC_ARCHIVE_FILE, "client_" + OSProcess.getId() + ".gfs");
props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
getSystem(props);
final ClientCacheFactory ccf = new ClientCacheFactory(props);
ccf.addPoolServer(getServerHostName(server.getHost()), port);
ccf.setPoolSubscriptionEnabled(true);
ccf.setPoolPingInterval(1);
ccf.setPoolStatisticInterval(1);
ccf.setPoolSubscriptionRedundancy(1);
ccf.setPoolMinConnections(1);
ClientCache clientCache = (ClientCache) getClientCache(ccf);
// Create region
if (clientCache.getRegion(Region.SEPARATOR + regionName) == null && clientCache.getRegion(regionName) == null) {
ClientRegionFactory regionFactory = clientCache.createClientRegionFactory(ClientRegionShortcut.LOCAL).setPoolName(clientCache.getDefaultPool().getName());
Region dataRegion = regionFactory.create(regionName);
assertNotNull(dataRegion);
dataRegion.put("k1", "v1");
dataRegion.put("k2", "v2");
}
} else {
String poolName = "new_pool_" + System.currentTimeMillis();
try {
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(getServerHostName(server.getHost()), port).setThreadLocalConnections(true).setMinConnections(1).setSubscriptionEnabled(true).setPingInterval(1).setStatisticInterval(1).setMinConnections(1).setSubscriptionRedundancy(1).create(poolName);
System.out.println("Created new pool pool " + poolName);
assertNotNull(p);
} catch (Exception eee) {
System.err.println("Exception in creating pool " + poolName + " Exception ==" + CliUtil.stackTraceAsString(eee));
}
}
});
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class AbstractRemoteGatewaySender method initProxy.
public synchronized void initProxy() {
// return if it is being used for WBCL or proxy is already created
if (this.remoteDSId == DEFAULT_DISTRIBUTED_SYSTEM_ID || this.proxy != null && !this.proxy.isDestroyed()) {
return;
}
int locatorCount = 0;
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.setPRSingleHopEnabled(false);
if (this.locatorDiscoveryCallback != null) {
pf.setLocatorDiscoveryCallback(locatorDiscoveryCallback);
}
pf.setReadTimeout(this.socketReadTimeout);
pf.setIdleTimeout(connectionIdleTimeOut);
pf.setSocketBufferSize(socketBufferSize);
pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP);
RemoteLocatorRequest request = new RemoteLocatorRequest(this.remoteDSId, pf.getPoolAttributes().getServerGroup());
String locators = this.cache.getInternalDistributedSystem().getConfig().getLocators();
if (logger.isDebugEnabled()) {
logger.debug("Gateway Sender is attempting to configure pool with remote locator information");
}
StringTokenizer locatorsOnThisVM = new StringTokenizer(locators, ",");
while (locatorsOnThisVM.hasMoreTokens()) {
String localLocator = locatorsOnThisVM.nextToken();
DistributionLocatorId locatorID = new DistributionLocatorId(localLocator);
try {
RemoteLocatorResponse response = (RemoteLocatorResponse) new TcpClient().requestToServer(locatorID.getHost(), locatorID.getPort(), request, WanLocatorDiscoverer.WAN_LOCATOR_CONNECTION_TIMEOUT);
if (response != null) {
if (response.getLocators() == null) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_REMOTE_LOCATOR_FOR_REMOTE_SITE_0_IS_NOT_AVAILABLE_IN_LOCAL_LOCATOR_1, new Object[] { remoteDSId, localLocator }));
}
continue;
}
if (logger.isDebugEnabled()) {
logger.debug("Received the remote site {} location information:", this.remoteDSId, response.getLocators());
}
Iterator<String> itr = response.getLocators().iterator();
while (itr.hasNext()) {
String remoteLocator = itr.next();
try {
DistributionLocatorId locatorId = new DistributionLocatorId(remoteLocator);
pf.addLocator(locatorId.getHost().getHostName(), locatorId.getPort());
locatorCount++;
} catch (Exception e) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PoolFactoryImpl_CAUGHT_EXCEPTION_ATTEMPTING_TO_ADD_REMOTE_LOCATOR_0, new Object[] { remoteLocator }), e);
}
}
}
break;
}
} catch (IOException ioe) {
if (logProxyFailure()) {
// don't print stack trace for connection failures
String ioeStr = "";
if (!logger.isDebugEnabled() && ioe instanceof ConnectException) {
ioeStr = ": " + ioe.toString();
ioe = null;
}
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_IS_NOT_ABLE_TO_CONNECT_TO_LOCAL_LOCATOR_1, new Object[] { this.id, localLocator + ioeStr }), ioe);
}
continue;
} catch (ClassNotFoundException e) {
if (logProxyFailure()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_IS_NOT_ABLE_TO_CONNECT_TO_LOCAL_LOCATOR_1, new Object[] { this.id, localLocator }), e);
}
continue;
}
}
if (locatorCount == 0) {
if (logProxyFailure()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_COULD_NOT_GET_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1, new Object[] { this.id, this.remoteDSId }));
}
this.proxyFailureTries++;
throw new GatewaySenderConfigurationException(LocalizedStrings.AbstractGatewaySender_SENDER_0_COULD_NOT_GET_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1.toLocalizedString(new Object[] { this.id, this.remoteDSId }));
}
pf.init(this);
this.proxy = ((PoolImpl) pf.create(this.getId()));
if (this.proxyFailureTries > 0) {
logger.info(LocalizedMessage.create(LocalizedStrings.AbstractGatewaySender_SENDER_0_GOT_REMOTE_LOCATOR_INFORMATION_FOR_SITE_1, new Object[] { this.id, this.remoteDSId, this.proxyFailureTries }));
this.proxyFailureTries = 0;
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class WANLocatorServerDUnitTest method createClient.
public static void createClient(Integer port1, Integer port2, Integer port3) {
ClientCacheFactory cf = new ClientCacheFactory();
cache = (Cache) cf.create();
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.setReadTimeout(0);
pf.setIdleTimeout(-1);
pf.setMinConnections(4);
pf.setServerGroup(GatewayReceiver.RECEIVER_GROUP);
pf.addLocator("localhost", port1);
pf.addLocator("localhost", port2);
pf.addLocator("localhost", port3);
pf.init((GatewaySender) null);
proxy = ((PoolImpl) pf.create("KISHOR_POOL"));
Connection con1 = proxy.acquireConnection();
try {
con1.close(true);
} catch (Exception e) {
fail("createClient failed", e);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class HADispatcherDUnitTest method createClientCache.
private void createClientCache(String hostName, Integer port1, Integer port2, Boolean isListenerPresent) throws CqException, CqExistsException, RegionNotFoundException {
int PORT1 = port1.intValue();
int PORT2 = port2.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1, PORT2 }, true, -1, 2, null);
if (isListenerPresent.booleanValue() == true) {
CacheListener clientListener = new HAClientListener();
factory.setCacheListener(clientListener);
}
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(region);
{
LocalRegion lr = (LocalRegion) region;
final PoolImpl pool = (PoolImpl) (lr.getServerProxy().getPool());
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getPrimary() != null;
}
public String description() {
return null;
}
};
waitForCriterion(ev, 30 * 1000, 200, true);
ev = new WaitCriterion() {
public boolean done() {
return pool.getRedundants().size() >= 1;
}
public String description() {
return null;
}
};
waitForCriterion(ev, 30 * 1000, 200, true);
assertNotNull(pool.getPrimary());
assertTrue("backups=" + pool.getRedundants() + " expected=" + 1, pool.getRedundants().size() >= 1);
assertEquals(PORT1, pool.getPrimaryPort());
}
region.registerInterest(KEY1);
// Register CQ.
createCQ();
}
Aggregations