use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class GetAllOp method execute.
public static VersionedObjectList execute(ExecutablePool pool, Region region, List keys, int retryAttempts, Object callback) {
AbstractOp op = new GetAllOpImpl(region.getFullPath(), keys, callback);
ClientMetadataService cms = ((LocalRegion) region).getCache().getClientMetadataService();
Map<ServerLocation, HashSet> serverToFilterMap = cms.getServerToFilterMap(keys, region, true);
if (serverToFilterMap == null || serverToFilterMap.isEmpty()) {
op.initMessagePart();
return ((VersionedObjectList) pool.execute(op)).setKeys(keys);
} else {
VersionedObjectList result = null;
ServerConnectivityException se = null;
List retryList = new ArrayList();
List callableTasks = constructGetAllTasks(region.getFullPath(), serverToFilterMap, (PoolImpl) pool, callback);
Map<ServerLocation, Object> results = SingleHopClientExecutor.submitGetAll(serverToFilterMap, callableTasks, cms, (LocalRegion) region);
for (ServerLocation server : results.keySet()) {
Object serverResult = results.get(server);
if (serverResult instanceof ServerConnectivityException) {
se = (ServerConnectivityException) serverResult;
retryList.addAll(serverToFilterMap.get(server));
} else {
if (result == null) {
result = (VersionedObjectList) serverResult;
} else {
result.addAll((VersionedObjectList) serverResult);
}
}
}
if (se != null) {
if (retryAttempts == 0) {
throw se;
} else {
VersionedObjectList retryResult = GetAllOp.execute(pool, region.getFullPath(), retryList, callback);
if (result == null) {
result = retryResult;
} else {
result.addAll(retryResult);
}
}
}
return result;
}
}
use of org.apache.geode.distributed.internal.ServerLocation 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.distributed.internal.ServerLocation in project geode by apache.
the class ConnectionFactoryImpl method createClientToServerConnection.
public Connection createClientToServerConnection(Set excludedServers) throws GemFireSecurityException {
final Set origExcludedServers = excludedServers;
excludedServers = new HashSet(excludedServers);
Set blackListedServers = blackList.getBadServers();
excludedServers.addAll(blackListedServers);
Connection conn = null;
// long startTime = System.currentTimeMillis();
RuntimeException fatalException = null;
boolean tryBlackList = true;
do {
ServerLocation server = source.findServer(excludedServers);
if (server == null) {
if (tryBlackList) {
// Nothing worked! Let's try without the blacklist.
tryBlackList = false;
int size = excludedServers.size();
excludedServers.removeAll(blackListedServers);
// make sure we didn't remove any of the ones that the caller set not to use
excludedServers.addAll(origExcludedServers);
if (excludedServers.size() < size) {
// We are able to remove some exclusions, so lets give this another whirl.
continue;
}
}
if (logger.isDebugEnabled()) {
logger.debug("Source was unable to locate any servers");
}
if (fatalException != null) {
throw fatalException;
}
return null;
}
try {
conn = createClientToServerConnection(server, false);
} catch (CancelException e) {
// propagate this up immediately
throw e;
} catch (GemFireSecurityException e) {
// propagate this up immediately
throw e;
} catch (GatewayConfigurationException e) {
// propagate this up immediately
throw e;
} catch (ServerRefusedConnectionException srce) {
fatalException = srce;
if (logger.isDebugEnabled()) {
logger.debug("ServerRefusedConnectionException attempting to connect to {}", server, srce);
}
} catch (Exception e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ConnectException_COULD_NOT_CONNECT_TO_0, server), e);
}
excludedServers.add(server);
} while (conn == null);
// }
return conn;
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class ConnectionFactoryImpl method findBestServer.
public ServerLocation findBestServer(ServerLocation currentServer, Set excludedServers) {
if (currentServer != null && source.isBalanced()) {
return currentServer;
}
final Set origExcludedServers = excludedServers;
excludedServers = new HashSet(excludedServers);
Set blackListedServers = blackList.getBadServers();
excludedServers.addAll(blackListedServers);
ServerLocation server = source.findReplacementServer(currentServer, excludedServers);
if (server == null) {
// Nothing worked! Let's try without the blacklist.
if (excludedServers.size() > origExcludedServers.size()) {
// We had some guys black listed so lets give this another whirl.
server = source.findReplacementServer(currentServer, origExcludedServers);
}
}
if (server == null && logger.isDebugEnabled()) {
logger.debug("Source was unable to findForReplacement any servers");
}
return server;
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class OpExecutorImpl method getNextOpServerLocation.
public ServerLocation getNextOpServerLocation() {
ServerLocation retVal = null;
Connection conn = (Connection) (threadLocalConnections ? localConnection.get() : null);
if (conn == null || conn.isDestroyed()) {
conn = connectionManager.borrowConnection(serverTimeout);
retVal = conn.getServer();
this.connectionManager.returnConnection(conn);
} else {
retVal = conn.getServer();
}
return retVal;
}
Aggregations