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 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 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);
}
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientTypeRegistration method addImportedType.
@Override
public void addImportedType(int typeId, PdxType importedType) {
Collection<Pool> pools = getAllPools();
ServerConnectivityException lastException = null;
for (Pool pool : pools) {
try {
sendTypeToPool(importedType, typeId, pool);
} catch (ServerConnectivityException e) {
lastException = e;
break;
}
}
if (lastException == null) {
return;
}
throw returnCorrectExceptionForFailure(pools, typeId, lastException);
}
use of org.apache.geode.cache.client.ServerConnectivityException in project geode by apache.
the class ClientTypeRegistration method defineType.
public int defineType(PdxType newType) {
Collection<Pool> pools = getAllPools();
ServerConnectivityException lastException = null;
int newTypeId = -1;
for (Pool pool : pools) {
try {
newTypeId = GetPDXIdForTypeOp.execute((ExecutablePool) pool, newType);
newType.setTypeId(newTypeId);
sendTypeToPool(newType, newTypeId, pool);
return newTypeId;
} catch (ServerConnectivityException e) {
// ignore, try the next pool.
lastException = e;
}
}
throw returnCorrectExceptionForFailure(pools, newTypeId, lastException);
}
Aggregations