use of org.apache.geode.cache.client.AllConnectionsInUseException in project geode by apache.
the class GetOp method execute.
/**
* Does a region get on a server using connections from the given pool to communicate with the
* server.
*
* @param pool the pool to use to communicate with the server.
* @param region the region to do the get on
* @param key the entry key to do the get on
* @param callbackArg an optional callback arg to pass to any cache callbacks
* @param clientEvent holder for returning version information
* @return the entry value found by the get if any
*/
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object callbackArg, boolean prSingleHopEnabled, EntryEventImpl clientEvent) {
ClientMetadataService cms = region.getCache().getClientMetadataService();
GetOpImpl op = new GetOpImpl(region, key, callbackArg, prSingleHopEnabled, clientEvent);
if (logger.isDebugEnabled()) {
logger.debug("GetOp invoked for key {}", key);
}
if (prSingleHopEnabled) {
ServerLocation server = cms.getBucketServerLocation(region, Operation.GET, key, null, callbackArg);
if (server != null) {
try {
PoolImpl poolImpl = (PoolImpl) pool;
boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
return pool.executeOn(new ServerLocation(server.getHostName(), server.getPort()), op, true, onlyUseExistingCnx);
} catch (AllConnectionsInUseException e) {
} catch (ServerConnectivityException e) {
if (e instanceof ServerOperationException) {
// fixed 44656
throw e;
}
cms.removeBucketServerLocation(server);
} catch (CacheLoaderException e) {
if (e.getCause() instanceof ServerConnectivityException)
cms.removeBucketServerLocation(server);
}
}
}
return pool.execute(op);
}
use of org.apache.geode.cache.client.AllConnectionsInUseException in project geode by apache.
the class ConnectionManagerJUnitTest method testBug41516.
@Test
public void testBug41516() throws InterruptedException, AllConnectionsInUseException, NoAvailableServersException {
final long idleTimeout = 300;
manager = new ConnectionManagerImpl("pool", factory, endpointManager, 2, 1, idleTimeout, -1, logger, 60 * 1000, cancelCriterion, poolStats);
manager.start(background);
Connection conn1 = manager.borrowConnection(500);
Connection conn2 = manager.borrowConnection(500);
// Return some connections, let them idle expire
manager.returnConnection(conn1);
manager.returnConnection(conn2);
{
long start = System.currentTimeMillis();
synchronized (factory) {
long remaining = TIMEOUT;
while (factory.destroys < 1 && remaining > 0) {
factory.wait(remaining);
remaining = TIMEOUT - (System.currentTimeMillis() - start);
}
}
long elapsed = System.currentTimeMillis() - start;
Assert.assertTrue("Elapsed " + elapsed + " is less than idle timeout " + idleTimeout, elapsed + ALLOWABLE_ERROR_IN_EXPIRATION >= idleTimeout);
Assert.assertEquals(1, factory.destroys);
Assert.assertEquals(1, factory.closes);
Assert.assertEquals(1, poolStats.getIdleExpire());
}
// Ok, now get some connections that fill our queue
Connection ping1 = manager.borrowConnection(new ServerLocation("localhost", 5), 500, false);
Connection ping2 = manager.borrowConnection(new ServerLocation("localhost", 5), 500, false);
manager.returnConnection(ping1);
manager.returnConnection(ping2);
Connection conn3 = manager.borrowConnection(500);
Connection conn4 = manager.borrowConnection(500);
long start = System.currentTimeMillis();
try {
Connection conn5 = manager.borrowConnection(500);
fail("Didn't get an exception");
} catch (AllConnectionsInUseException e) {
// expected
}
long elapsed = System.currentTimeMillis() - start;
Assert.assertTrue("Elapsed = " + elapsed, elapsed >= 500);
}
use of org.apache.geode.cache.client.AllConnectionsInUseException in project geode by apache.
the class ConnectionManagerJUnitTest method testExplicitServer.
@Test
public void testExplicitServer() throws Exception {
manager = new ConnectionManagerImpl("pool", factory, endpointManager, 1, 0, -1, -1, logger, 60 * 1000, cancelCriterion, poolStats);
manager.start(background);
Connection conn1 = manager.borrowConnection(0);
try {
manager.borrowConnection(10);
fail("Should have received an error");
} catch (AllConnectionsInUseException expected) {
// do nothing
}
Connection conn3 = manager.borrowConnection(new ServerLocation("localhost", -2), 10, false);
Assert.assertEquals(2, factory.creates);
Assert.assertEquals(0, factory.destroys);
Assert.assertEquals(0, factory.closes);
manager.returnConnection(conn3);
Assert.assertEquals(2, factory.creates);
Assert.assertEquals(1, factory.destroys);
Assert.assertEquals(1, factory.closes);
manager.returnConnection(conn1);
Assert.assertEquals(2, factory.creates);
Assert.assertEquals(1, factory.destroys);
Assert.assertEquals(1, factory.closes);
}
use of org.apache.geode.cache.client.AllConnectionsInUseException in project geode by apache.
the class PutOp method execute.
/**
* Does a region put on a server using connections from the given pool to communicate with the
* server.
*
* @param pool the pool to use to communicate with the server.
* @param region the region to do the put on
* @param key the entry key to do the put on
* @param value the entry value to put
* @param event the event for this put
* @param requireOldValue
* @param expectedOldValue
* @param callbackArg an optional callback arg to pass to any cache callbacks
*/
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object value, byte[] deltaBytes, EntryEventImpl event, Operation operation, boolean requireOldValue, Object expectedOldValue, Object callbackArg, boolean prSingleHopEnabled) {
PutOpImpl op = new PutOpImpl(region, key, value, deltaBytes, event, operation, requireOldValue, expectedOldValue, callbackArg, false, /* donot send full obj; send delta */
prSingleHopEnabled);
if (prSingleHopEnabled) {
ClientMetadataService cms = region.getCache().getClientMetadataService();
ServerLocation server = cms.getBucketServerLocation(region, Operation.UPDATE, key, value, callbackArg);
if (server != null) {
try {
PoolImpl poolImpl = (PoolImpl) pool;
boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
return pool.executeOn(new ServerLocation(server.getHostName(), server.getPort()), op, true, onlyUseExistingCnx);
} catch (AllConnectionsInUseException e) {
} catch (ServerConnectivityException e) {
if (e instanceof ServerOperationException) {
// fixed 44656
throw e;
}
cms.removeBucketServerLocation(server);
}
}
}
return pool.execute(op);
}
use of org.apache.geode.cache.client.AllConnectionsInUseException in project geode by apache.
the class DestroyOp method execute.
/**
* Does a region entry destroy on a server using connections from the given pool to communicate
* with the server.
*
* @param pool the pool to use to communicate with the server.
* @param region the region to do the entry destroy on
* @param key the entry key to do the destroy on
* @param event the event for this destroy operation
* @param callbackArg an optional callback arg to pass to any cache callbacks
*/
public static Object execute(ExecutablePool pool, LocalRegion region, Object key, Object expectedOldValue, Operation operation, EntryEventImpl event, Object callbackArg, boolean prSingleHopEnabled) {
if (logger.isDebugEnabled()) {
logger.debug("Preparing DestroyOp for {} operation={}", key, operation);
}
DestroyOpImpl op = new DestroyOpImpl(region, key, expectedOldValue, operation, event, callbackArg, prSingleHopEnabled);
if (prSingleHopEnabled) {
ClientMetadataService cms = region.getCache().getClientMetadataService();
ServerLocation server = cms.getBucketServerLocation(region, Operation.DESTROY, key, null, callbackArg);
if (server != null) {
try {
PoolImpl poolImpl = (PoolImpl) pool;
boolean onlyUseExistingCnx = ((poolImpl.getMaxConnections() != -1 && poolImpl.getConnectionCount() >= poolImpl.getMaxConnections()) ? true : false);
op.setAllowDuplicateMetadataRefresh(!onlyUseExistingCnx);
return pool.executeOn(server, op, true, onlyUseExistingCnx);
} catch (AllConnectionsInUseException e) {
} catch (ServerConnectivityException e) {
if (e instanceof ServerOperationException) {
// fixed 44656
throw e;
}
cms.removeBucketServerLocation(server);
}
}
}
return pool.execute(op);
}
Aggregations