Search in sources :

Example 96 with Execution

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

the class PeerToPeerSessionCache method touchSessions.

@Override
public void touchSessions(Set<String> sessionIds) {
    // Get the region attributes id to determine the region type. This is
    // problematic since the region attributes id doesn't really define the
    // region type. This should look at the actual session region.
    String regionAttributesID = getSessionManager().getRegionAttributesId().toLowerCase();
    // Invoke the appropriate function depending on the type of region
    ResultCollector collector = null;
    if (regionAttributesID.startsWith("partition")) {
        // Execute the partitioned touch function on the primary server(s)
        Execution execution = FunctionService.onRegion(getSessionRegion()).withFilter(sessionIds);
        collector = execution.execute(TouchPartitionedRegionEntriesFunction.ID, true, false, true);
    } else {
        // Execute the member touch function on all the server(s)
        Execution execution = FunctionService.onMembers().setArguments(new Object[] { this.sessionRegion.getFullPath(), sessionIds });
        collector = execution.execute(TouchReplicatedRegionEntriesFunction.ID, true, false, false);
    }
    // Get the result
    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)

Example 97 with Execution

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

the class ClientServerSessionCache method touchSessions.

@Override
public void touchSessions(Set<String> sessionIds) {
    // Get the region attributes id to determine the region type. This is
    // problematic since the region attributes id doesn't really define the
    // region type. Currently there is no way to know the type of region created
    // on the server. Maybe the CreateRegionFunction should return it.
    String regionAttributesID = getSessionManager().getRegionAttributesId().toLowerCase();
    // Invoke the appropriate function depending on the type of region
    if (regionAttributesID.startsWith("partition")) {
        // Execute the partitioned touch function on the primary server(s)
        Execution execution = FunctionService.onRegion(getSessionRegion()).withFilter(sessionIds);
        try {
            ResultCollector collector = execution.execute(TouchPartitionedRegionEntriesFunction.ID, true, false, true);
            collector.getResult();
        } catch (Exception e) {
            // If an exception occurs in the function, log it.
            getSessionManager().getLogger().warn("Caught unexpected exception:", e);
        }
    } else {
        // Execute the member touch function on all the server(s)
        Execution execution = FunctionService.onServers(getCache()).setArguments(new Object[] { this.sessionRegion.getFullPath(), sessionIds });
        try {
            ResultCollector collector = execution.execute(TouchReplicatedRegionEntriesFunction.ID, true, false, false);
            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)

Example 98 with Execution

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

the class ClientServerSessionCache method createSessionRegionOnServers.

private void createSessionRegionOnServers() {
    // Create the RegionConfiguration
    RegionConfiguration configuration = createRegionConfiguration();
    // Send it to the server tier
    Execution execution = FunctionService.onServer(this.cache).setArguments(configuration);
    ResultCollector collector = execution.execute(CreateRegionFunction.ID);
    // Verify the region was successfully created on the servers
    List<RegionStatus> results = (List<RegionStatus>) collector.getResult();
    for (RegionStatus status : results) {
        if (status == RegionStatus.INVALID) {
            StringBuilder builder = new StringBuilder();
            builder.append("An exception occurred on the server while attempting to create or validate region named ").append(getSessionManager().getRegionName()).append(". See the server log for additional details.");
            throw new IllegalStateException(builder.toString());
        }
    }
}
Also used : RegionConfiguration(org.apache.geode.modules.util.RegionConfiguration) Execution(org.apache.geode.cache.execute.Execution) RegionStatus(org.apache.geode.modules.util.RegionStatus) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 99 with Execution

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

the class ClientServerSessionCache method size.

@Override
public int size() {
    // Add a single dummy key to force the function to go to one server
    Set<String> filters = new HashSet<String>();
    filters.add("test-key");
    // Execute the function on the session region
    Execution execution = FunctionService.onRegion(getSessionRegion()).withFilter(filters);
    ResultCollector collector = execution.execute(RegionSizeFunction.ID, true, true, true);
    List<Integer> result = (List<Integer>) collector.getResult();
    // Return the first (and only) element
    return result.get(0);
}
Also used : Execution(org.apache.geode.cache.execute.Execution) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 100 with Execution

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

the class BootstrappingFunction method bootstrapMember.

private void bootstrapMember(InternalDistributedMember member) {
    // Create and execute the function
    Cache cache = CacheFactory.getAnyInstance();
    Execution execution = FunctionService.onMember(member);
    ResultCollector collector = execution.execute(this);
    // Get the result. Nothing is being done with it.
    try {
        collector.getResult();
    } catch (Exception e) {
        // If an exception occurs in the function, log it.
        cache.getLogger().warning("Caught unexpected exception:", e);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) ResultCollector(org.apache.geode.cache.execute.ResultCollector) 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