Search in sources :

Example 1 with ProxyRegion

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

the class FunctionServiceManager method onRegion.

/**
   * Returns an {@link Execution} object that can be used to execute a data dependent function on
   * the specified Region.<br>
   * When invoked from a GemFire client, the method returns an Execution instance that sends a
   * message to one of the connected servers as specified by the {@link Pool} for the region. <br>
   * Depending on the filters setup on the {@link Execution}, the function is executed on all
   * GemFire members that define the data region, or a subset of members.
   * {@link Execution#withFilter(Set)}).
   * 
   * For DistributedRegions with DataPolicy.NORMAL, it throws UnsupportedOperationException. For
   * DistributedRegions with DataPolicy.EMPTY, execute the function on any random member which has
   * DataPolicy.REPLICATE <br>
   * . For DistributedRegions with DataPolicy.REPLICATE, execute the function locally. For Regions
   * with DataPolicy.PARTITION, it executes on members where the data resides as specified by the
   * filter.
   * 
   * @return Execution
   * @throws FunctionException if the region passed in is null
   * @since GemFire 6.0
   */
public Execution onRegion(Region region) {
    if (region == null) {
        throw new FunctionException(LocalizedStrings.FunctionService_0_PASSED_IS_NULL.toLocalizedString("Region instance "));
    }
    ProxyCache proxyCache = null;
    String poolName = region.getAttributes().getPoolName();
    if (poolName != null) {
        Pool pool = PoolManager.find(poolName);
        if (pool.getMultiuserAuthentication()) {
            if (region instanceof ProxyRegion) {
                ProxyRegion proxyRegion = (ProxyRegion) region;
                region = proxyRegion.getRealRegion();
                proxyCache = proxyRegion.getAuthenticatedCache();
            } else {
                throw new UnsupportedOperationException();
            }
        }
    }
    if (isClientRegion(region)) {
        return new ServerRegionFunctionExecutor(region, proxyCache);
    }
    if (PartitionRegionHelper.isPartitionedRegion(region)) {
        return new PartitionedRegionFunctionExecutor(region);
    }
    return new DistributedRegionFunctionExecutor(region);
}
Also used : PartitionedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor) ProxyRegion(org.apache.geode.cache.client.internal.ProxyRegion) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) FunctionException(org.apache.geode.cache.execute.FunctionException) ServerRegionFunctionExecutor(org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor) Pool(org.apache.geode.cache.client.Pool) DistributedRegionFunctionExecutor(org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutor)

Example 2 with ProxyRegion

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

the class ClientRegionFactoryJUnitTest method testMultiUserRootRegions.

@Test
public void testMultiUserRootRegions() throws Exception {
    DistributedSystem ds = DistributedSystem.connect(createGemFireProperties());
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).setMultiuserAuthentication(true).create("muPool");
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666).create("suPool");
    ClientCache cc = new ClientCacheFactory().create();
    cc.createClientRegionFactory(PROXY).setPoolName("muPool").create("p");
    cc.createClientRegionFactory(CACHING_PROXY).setPoolName("suPool").create("cp");
    cc.createClientRegionFactory(LOCAL).create("l");
    assertEquals(3, cc.rootRegions().size());
    {
        Properties muProps = new Properties();
        muProps.setProperty("user", "foo");
        RegionService rs = cc.createAuthenticatedView(muProps, "muPool");
        assertNotNull(rs.getRegion("p"));
        try {
            rs.getRegion("cp");
            fail("expected IllegalStateException");
        } catch (IllegalStateException expected) {
        }
        try {
            rs.getRegion("l");
            fail("expected IllegalStateException");
        } catch (IllegalStateException expected) {
        }
        assertEquals(1, rs.rootRegions().size());
        assertEquals(true, rs.getRegion("p") instanceof ProxyRegion);
        assertEquals(true, rs.rootRegions().iterator().next() instanceof ProxyRegion);
    }
}
Also used : ProxyRegion(org.apache.geode.cache.client.internal.ProxyRegion) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

ProxyRegion (org.apache.geode.cache.client.internal.ProxyRegion)2 Properties (java.util.Properties)1 Pool (org.apache.geode.cache.client.Pool)1 ProxyCache (org.apache.geode.cache.client.internal.ProxyCache)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 DistributedRegionFunctionExecutor (org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutor)1 PartitionedRegionFunctionExecutor (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor)1 ServerRegionFunctionExecutor (org.apache.geode.internal.cache.execute.ServerRegionFunctionExecutor)1 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1