Search in sources :

Example 91 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class ClientServerSessionCache method bootstrapServers.

////////////////////////////////////////////////////////////////////////
// Private methods
private void bootstrapServers() {
    Execution execution = FunctionService.onServers(this.cache);
    ResultCollector collector = execution.execute(new BootstrappingFunction());
    // Get the result. Nothing is being done with it.
    try {
        collector.getResult();
    } catch (Exception e) {
        // If an exception occurs in the function, log it.
        LOG.warn("Caught unexpected exception:", e);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ResultCollector(org.apache.geode.cache.execute.ResultCollector) BootstrappingFunction(org.apache.geode.modules.util.BootstrappingFunction)

Example 92 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class ClientServerSessionCache method bootstrapServers.

private void bootstrapServers() {
    Execution execution = FunctionService.onServers(this.cache);
    ResultCollector collector = execution.execute(new BootstrappingFunction());
    // Get the result. Nothing is being done with it.
    try {
        collector.getResult();
    } catch (Exception e) {
        // If an exception occurs in the function, log it.
        getSessionManager().getLogger().warn("Caught unexpected exception:", e);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ResultCollector(org.apache.geode.cache.execute.ResultCollector) BootstrappingFunction(org.apache.geode.modules.util.BootstrappingFunction)

Example 93 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class GemFireDeadlockDetector method find.

/**
   * Find any deadlocks the exist in this distributed system.
   * 
   * The deadlocks are returned as a list of dependencies. See {@link DeadlockDetector}
   */
public DependencyGraph find() {
    final DeadlockDetector detector = new DeadlockDetector();
    ResultCollector<HashSet<Dependency>, Serializable> collector = new ResultCollector<HashSet<Dependency>, Serializable>() {

        public synchronized Serializable getResult() throws FunctionException {
            return null;
        }

        public synchronized Serializable getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
            return null;
        }

        public synchronized void addResult(DistributedMember memberID, HashSet<Dependency> resultOfSingleExecution) {
            detector.addDependencies(resultOfSingleExecution);
        }

        public void endResults() {
        }

        public void clearResults() {
        }
    };
    Execution execution;
    if (targetMembers != null) {
        execution = FunctionService.onMembers(targetMembers).withCollector(collector);
    } else {
        execution = FunctionService.onMembers().withCollector(collector);
    }
    ((AbstractExecution) execution).setIgnoreDepartedMembers(true);
    collector = execution.execute(new CollectDependencyFunction());
    // Wait for results
    collector.getResult();
    return detector.getDependencyGraph();
}
Also used : Serializable(java.io.Serializable) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) TimeUnit(java.util.concurrent.TimeUnit) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 94 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class ClientExporter method export.

@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
    try {
        ClientArgs<K, V> args = new ClientArgs<K, V>(region.getFullPath(), pool.getPRSingleHopEnabled(), options);
        ClientExportCollector results = new ClientExportCollector(sink);
        // For single hop we rely on tcp queuing to throttle the export; otherwise
        // we allow the WindowedExporter to provide back pressure.
        Execution exec = pool.getPRSingleHopEnabled() ? FunctionService.onRegion(region) : FunctionService.onServer(pool);
        ResultCollector<?, ?> rc = exec.setArguments(args).withCollector(results).execute(new ProxyExportFunction<K, V>());
        // check for errors.
        return (Long) rc.getResult();
    } catch (FunctionException e) {
        throw new IOException(e);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) AtomicLong(java.util.concurrent.atomic.AtomicLong) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 95 with Execution

use of org.apache.geode.cache.execute.Execution in project geode by apache.

the class MemberRegionFunction method execute.

@Override
public void execute(FunctionContext context) {
    Object[] args = (Object[]) context.getArguments();
    String region = (String) args[0];
    String functionId = (String) args[1];
    Cache cache = CacheFactory.getAnyInstance();
    try {
        Function function = FunctionService.getFunction(functionId);
        if (function == null) {
            context.getResultSender().lastResult("For region on a member did not get function " + functionId);
        }
        Execution execution = FunctionService.onRegion(cache.getRegion(region));
        if (execution == null) {
            context.getResultSender().lastResult("For region on a member could not execute");
        } else {
            execution.execute(function);
            context.getResultSender().lastResult("succeeded in executing on region " + region);
        }
    } catch (FunctionException e) {
        context.getResultSender().lastResult("FunctionException in MemberRegionFunction =" + e.getMessage());
    } catch (Exception e) {
        context.getResultSender().lastResult("Exception in MemberRegionFunction =" + e.getMessage());
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) Cache(org.apache.geode.cache.Cache)

Aggregations

Execution (org.apache.geode.cache.execute.Execution)217 ResultCollector (org.apache.geode.cache.execute.ResultCollector)163 HashSet (java.util.HashSet)144 ArrayList (java.util.ArrayList)139 FunctionException (org.apache.geode.cache.execute.FunctionException)131 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)127 Function (org.apache.geode.cache.execute.Function)121 TestFunction (org.apache.geode.internal.cache.functions.TestFunction)108 IgnoredException (org.apache.geode.test.dunit.IgnoredException)108 List (java.util.List)106 Test (org.junit.Test)85 Iterator (java.util.Iterator)79 Region (org.apache.geode.cache.Region)79 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)74 VM (org.apache.geode.test.dunit.VM)70 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)69 Host (org.apache.geode.test.dunit.Host)69 Set (java.util.Set)65 CacheClosedException (org.apache.geode.cache.CacheClosedException)59