Search in sources :

Example 61 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class SingleHopClientExecutor method submitBulkOp.

/**
   * execute bulk op (putAll or removeAll) on multiple PR servers, returning a map of the results.
   * Results are either a VersionedObjectList or a BulkOpPartialResultsException
   * 
   * @param callableTasks
   * @param cms
   * @param region
   * @param failedServers
   * @return the per-server results
   */
static Map<ServerLocation, Object> submitBulkOp(List callableTasks, ClientMetadataService cms, LocalRegion region, Map<ServerLocation, RuntimeException> failedServers) {
    if (callableTasks != null && !callableTasks.isEmpty()) {
        Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
        boolean anyPartialResults = false;
        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();
            RuntimeException rte = null;
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    VersionedObjectList versions = (VersionedObjectList) fut.get();
                    if (logger.isDebugEnabled()) {
                        logger.debug("submitBulkOp#got result from {}:{}", server, versions);
                    }
                    resultMap.put(server, versions);
                } catch (InterruptedException e) {
                    InternalGemFireException ige = new InternalGemFireException(e);
                    // only to make this server as failed server, not to throw right now
                    failedServers.put(server, ige);
                    if (rte == null) {
                        rte = ige;
                    }
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof ServerOperationException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("submitBulkOp#ExecutionException from server {}", server, ee);
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        // only to make this server as failed server, not to throw right now
                        failedServers.put(server, soe);
                        if (rte == null) {
                            rte = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("submitBulkOp#ExecutionException for server {}", server, ee);
                        }
                        cms = region.getCache().getClientMetadataService();
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        failedServers.put(server, (ServerConnectivityException) ee.getCause());
                    } else {
                        Throwable t = ee.getCause();
                        if (t instanceof PutAllPartialResultException) {
                            resultMap.put(server, t);
                            anyPartialResults = true;
                            failedServers.put(server, (PutAllPartialResultException) t);
                        } else {
                            RuntimeException other_rte = executionThrowable(ee.getCause());
                            failedServers.put(server, other_rte);
                            if (rte == null) {
                                rte = other_rte;
                            }
                        }
                    }
                }
            // catch
            }
            // so the partial results can be processed
            if (rte != null && !anyPartialResults) {
                throw rte;
            }
        }
        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) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) 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)

Example 62 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class SerializationHelper method readServerLocationList.

public static ArrayList readServerLocationList(DataInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    if (size < 0) {
        return null;
    }
    ArrayList serverLocations = new ArrayList(size);
    for (int i = 0; i < size; i++) {
        ServerLocation next = new ServerLocation();
        InternalDataSerializer.invokeFromData(next, in);
        serverLocations.add(next);
    }
    return serverLocations;
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ArrayList(java.util.ArrayList)

Example 63 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class ClientReplacementRequest method fromData.

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
    super.fromData(in);
    this.currentServer = new ServerLocation();
    InternalDataSerializer.invokeFromData(this.currentServer, in);
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation)

Example 64 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class SerializationHelper method writeBucketServerLocations.

private static void writeBucketServerLocations(Collection<BucketServerLocation66> bucketServerLocations, DataOutput out) throws IOException {
    if (bucketServerLocations == null) {
        out.writeInt(-1);
        return;
    }
    int length = bucketServerLocations.size();
    out.writeInt(length);
    for (Iterator itr = bucketServerLocations.iterator(); itr.hasNext(); ) {
        ServerLocation next = (ServerLocation) itr.next();
        InternalDataSerializer.invokeToData(next, out);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Iterator(java.util.Iterator)

Example 65 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class SerializationHelper method readServerLocationSet.

public static HashSet readServerLocationSet(DataInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    if (size < 0) {
        return null;
    }
    HashSet serverLocations = new HashSet(size);
    for (int i = 0; i < size; i++) {
        ServerLocation next = new ServerLocation();
        InternalDataSerializer.invokeFromData(next, in);
        serverLocations.add(next);
    }
    return serverLocations;
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashSet(java.util.HashSet)

Aggregations

ServerLocation (org.apache.geode.distributed.internal.ServerLocation)95 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 List (java.util.List)18 HashMap (java.util.HashMap)17 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)17 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)13 Map (java.util.Map)12 Iterator (java.util.Iterator)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Set (java.util.Set)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 LinkedHashSet (java.util.LinkedHashSet)7 Host (org.apache.geode.test.dunit.Host)7 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5