Search in sources :

Example 1 with GetAllOpImpl

use of org.apache.geode.cache.client.internal.GetAllOp.GetAllOpImpl in project geode by apache.

the class SingleHopClientExecutor method submitGetAll.

static Map<ServerLocation, Object> submitGetAll(Map<ServerLocation, HashSet> serverToFilterMap, List callableTasks, ClientMetadataService cms, LocalRegion region) {
    if (callableTasks != null && !callableTasks.isEmpty()) {
        Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                List keys = ((GetAllOpImpl) task.getOperation()).getKeyList();
                ServerLocation server = task.getServer();
                try {
                    VersionedObjectList valuesFromServer = (VersionedObjectList) fut.get();
                    valuesFromServer.setKeys(keys);
                    for (VersionedObjectList.Iterator it = valuesFromServer.iterator(); it.hasNext(); ) {
                        VersionedObjectList.Entry entry = it.next();
                        Object key = entry.getKey();
                        Object value = entry.getValue();
                        if (!entry.isKeyNotOnServer()) {
                            if (value instanceof Throwable) {
                                logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { value, key }), (Throwable) value);
                            }
                        }
                    }
                    if (logger.isDebugEnabled()) {
                        logger.debug("GetAllOp#got result from {}: {}", server, valuesFromServer);
                    }
                    resultMap.put(server, valuesFromServer);
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof ServerOperationException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        throw (ServerOperationException) ee.getCause();
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return null;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData((LocalRegion) region, false);
                        resultMap.put(server, ee.getCause());
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            return resultMap;
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) GetAllOpImpl(org.apache.geode.cache.client.internal.GetAllOp.GetAllOpImpl) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)1 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)1 GetAllOpImpl (org.apache.geode.cache.client.internal.GetAllOp.GetAllOpImpl)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)1