use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ConnectionPoolImplJUnitTest method testExecuteOp.
@Test
public void testExecuteOp() throws Exception {
CacheServer server1 = cache.addCacheServer();
CacheServer server2 = cache.addCacheServer();
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
int port1 = ports[0];
int port2 = ports[1];
server1.setPort(port1);
server2.setPort(port2);
server1.start();
server2.start();
PoolFactory cpf = PoolManager.createFactory();
cpf.addServer("localhost", port2);
cpf.addServer("localhost", port1);
PoolImpl pool = (PoolImpl) cpf.create("pool1");
ServerLocation location1 = new ServerLocation("localhost", port1);
ServerLocation location2 = new ServerLocation("localhost", port2);
Op testOp = new Op() {
int attempts = 0;
public Object attempt(Connection cnx) throws Exception {
if (attempts == 0) {
attempts++;
throw new SocketTimeoutException();
} else {
return cnx.getServer();
}
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
};
// TODO - set retry attempts, and throw in some assertions
// about how many times we retry
ServerLocation usedServer = (ServerLocation) pool.execute(testOp);
assertTrue("expected " + location1 + " or " + location2 + ", got " + usedServer, location1.equals(usedServer) || location2.equals(usedServer));
testOp = new Op() {
public Object attempt(Connection cnx) throws Exception {
throw new SocketTimeoutException();
}
@Override
public boolean useThreadLocalConnection() {
return true;
}
};
try {
usedServer = (ServerLocation) pool.execute(testOp);
fail("Should have failed");
} catch (ServerConnectivityException expected) {
// do nothing
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class AbstractOp method sendMessage.
/**
* New implementations of AbstractOp should override this method if the implementation should be
* excluded from client authentication. e.g. PingOp#sendMessage(Connection cnx)
*
* @see AbstractOp#needsUserId()
* @see AbstractOp#processSecureBytes(Connection, Message)
* @see ServerConnection#updateAndGetSecurityPart()
*/
protected void sendMessage(Connection cnx) throws Exception {
if (cnx.getServer().getRequiresCredentials()) {
// Security is enabled on client as well as on server
getMessage().setMessageHasSecurePartFlag();
long userId = -1;
if (UserAttributes.userAttributes.get() == null) {
// single user mode
userId = cnx.getServer().getUserId();
} else {
// multi user mode
Object id = UserAttributes.userAttributes.get().getServerToId().get(cnx.getServer());
if (id == null) {
// the retryCount is exhausted. Fix for Bug 41501
throw new ServerConnectivityException("Connection error while authenticating user");
}
userId = (Long) id;
}
HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
try {
hdos.writeLong(cnx.getConnectionID());
hdos.writeLong(userId);
getMessage().setSecurePart(((ConnectionImpl) cnx).getHandShake().encryptBytes(hdos.toByteArray()));
} finally {
hdos.close();
}
}
getMessage().send(false);
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ServerFunctionExecutor method executeOnServer.
private ResultCollector executeOnServer(Function function, ResultCollector rc, byte hasResult) {
FunctionStats stats = FunctionStats.getFunctionStats(function.getId());
try {
validateExecution(function, null);
long start = stats.startTime();
stats.startFunctionExecution(true);
ExecuteFunctionOp.execute(this.pool, function, this, args, memberMappedArg, this.allServers, hasResult, rc, this.isFnSerializationReqd, UserAttributes.userAttributes.get(), groups);
stats.endFunctionExecution(start, true);
rc.endResults();
return rc;
} catch (FunctionException functionException) {
stats.endFunctionExecutionWithException(true);
throw functionException;
} catch (ServerConnectivityException exception) {
throw exception;
} catch (Exception exception) {
stats.endFunctionExecutionWithException(true);
throw new FunctionException(exception);
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ServerFunctionExecutor method executeOnServerNoAck.
private void executeOnServerNoAck(String functionId, byte hasResult, boolean isHA, boolean optimizeForWrite) {
FunctionStats stats = FunctionStats.getFunctionStats(functionId);
try {
validateExecution(null, null);
long start = stats.startTime();
stats.startFunctionExecution(false);
ExecuteFunctionNoAckOp.execute(this.pool, functionId, args, memberMappedArg, this.allServers, hasResult, this.isFnSerializationReqd, isHA, optimizeForWrite, groups);
stats.endFunctionExecution(start, false);
} catch (FunctionException functionException) {
stats.endFunctionExecutionWithException(false);
throw functionException;
} catch (ServerConnectivityException exception) {
throw exception;
} catch (Exception exception) {
stats.endFunctionExecutionWithException(false);
throw new FunctionException(exception);
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientTypeRegistration method getType.
public PdxType getType(int typeId) {
Collection<Pool> pools = getAllPools();
ServerConnectivityException lastException = null;
for (Pool pool : pools) {
try {
PdxType type = GetPDXTypeByIdOp.execute((ExecutablePool) pool, typeId);
if (type != null) {
return type;
}
} catch (ServerConnectivityException e) {
logger.debug("Received an exception getting pdx type from pool {}, {}", pool, e.getMessage(), e);
// ignore, try the next pool.
lastException = e;
}
}
if (lastException != null) {
throw lastException;
} else {
throw returnCorrectExceptionForFailure(pools, typeId, lastException);
}
}
Aggregations