use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class ExecuteRegionFunctionSingleHopOp method constructAndGetExecuteFunctionTasks.
static List<SingleHopOperationCallable> constructAndGetExecuteFunctionTasks(String region, ServerRegionFunctionExecutor serverRegionExecutor, final Map<ServerLocation, ? extends HashSet> serverToFilterMap, final PoolImpl pool, final String functionId, byte hasResult, ResultCollector rc, ClientMetadataService cms, boolean allBucket, boolean isHA, boolean optimizeForWrite) {
final List<SingleHopOperationCallable> tasks = new ArrayList<SingleHopOperationCallable>();
ArrayList<ServerLocation> servers = new ArrayList<ServerLocation>(serverToFilterMap.keySet());
if (logger.isDebugEnabled()) {
logger.debug("Constructing tasks for the servers {}", servers);
}
for (ServerLocation server : servers) {
ServerRegionFunctionExecutor executor = (ServerRegionFunctionExecutor) serverRegionExecutor.withFilter(serverToFilterMap.get(server));
AbstractOp op = new ExecuteRegionFunctionSingleHopOpImpl(region, functionId, executor, rc, hasResult, new HashSet<String>(), allBucket, isHA, optimizeForWrite);
SingleHopOperationCallable task = new SingleHopOperationCallable(new ServerLocation(server.getHostName(), server.getPort()), pool, op, UserAttributes.userAttributes.get());
tasks.add(task);
}
return tasks;
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class ExplicitConnectionSourceImpl method findServer.
@Override
public synchronized ServerLocation findServer(Set excludedServers) {
if (PoolImpl.TEST_DURABLE_IS_NET_DOWN) {
return null;
}
ServerLocation nextServer;
int startIndex = nextServerIndex;
do {
nextServer = (ServerLocation) serverList.get(nextServerIndex);
if (++nextServerIndex >= serverList.size()) {
nextServerIndex = 0;
}
if (!excludedServers.contains(nextServer)) {
return nextServer;
}
} while (nextServerIndex != startIndex);
return null;
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class ExplicitConnectionSourceImpl method findDurableQueues.
private List findDurableQueues(Set excludedServers, int numServers) {
ArrayList durableServers = new ArrayList();
ArrayList otherServers = new ArrayList();
logger.debug("ExplicitConnectionSource - looking for durable queue");
for (Iterator itr = serverList.iterator(); itr.hasNext(); ) {
ServerLocation server = (ServerLocation) itr.next();
if (excludedServers.contains(server)) {
continue;
}
// the pool will automatically create a connection to this server
// and store it for future use.
Boolean hasQueue;
try {
hasQueue = (Boolean) pool.executeOn(server, HasQueueOp.SINGLETON);
} catch (GemFireSecurityException e) {
throw e;
} catch (Exception e) {
if (e.getCause() instanceof GemFireSecurityException) {
throw (GemFireSecurityException) e.getCause();
}
if (logger.isDebugEnabled()) {
logger.debug("Unabled to check for durable queue on server {}: {}", server, e);
}
continue;
}
if (hasQueue != null) {
if (hasQueue.booleanValue()) {
if (logger.isDebugEnabled()) {
logger.debug("Durable queue found on {}", server);
}
durableServers.add(server);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Durable queue was not found on {}", server);
}
otherServers.add(server);
}
}
}
int remainingServers = numServers - durableServers.size();
if (remainingServers > otherServers.size()) {
remainingServers = otherServers.size();
}
// but that's ok because we already shuffled the list in our constructor.
if (remainingServers > 0) {
durableServers.addAll(otherServers.subList(0, remainingServers));
nextQueueIndex = remainingServers % serverList.size();
}
if (logger.isDebugEnabled()) {
logger.debug("found {} servers out of {}", durableServers.size(), numServers);
}
return durableServers;
}
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);
}
Aggregations