Search in sources :

Example 6 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class PeerToPeerSessionCache method createOrRetrieveRegion.

@SuppressWarnings("unchecked")
protected void createOrRetrieveRegion() {
    // Create the RegionConfiguration
    RegionConfiguration configuration = createRegionConfiguration();
    configuration.setSessionExpirationCacheListener(true);
    // Attempt to retrieve the region
    // If it already exists, validate it
    // If it doesn't already exist, create it
    Region region = this.cache.getRegion(getSessionManager().getRegionName());
    if (region == null) {
        // Create the region
        region = RegionHelper.createRegion((Cache) getCache(), configuration);
        if (getSessionManager().getLogger().isDebugEnabled()) {
            getSessionManager().getLogger().debug("Created new session region: " + region);
        }
    } else {
        // Validate the existing region
        if (getSessionManager().getLogger().isDebugEnabled()) {
            getSessionManager().getLogger().debug("Retrieved existing session region: " + region);
        }
        RegionHelper.validateRegion((Cache) getCache(), configuration, region);
    }
    // Set the session region
    this.sessionRegion = region;
}
Also used : RegionConfiguration(org.apache.geode.modules.util.RegionConfiguration) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) GemFireCache(org.apache.geode.cache.GemFireCache)

Example 7 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class InternalInstantiator method sendRegistrationMessageToClients.

/**
   * Sends Instantiator registration message to all cache clients
   */
private static void sendRegistrationMessageToClients(Instantiator instantiator) {
    Cache cache = GemFireCacheImpl.getInstance();
    if (cache == null) {
        // we can't propagate it to clients
        return;
    }
    byte[][] serializedInstantiators = new byte[3][];
    try {
        serializedInstantiators[0] = CacheServerHelper.serialize(instantiator.getClass().toString().substring(6));
        serializedInstantiators[1] = CacheServerHelper.serialize(instantiator.getInstantiatedClass().toString().substring(6));
        {
            byte[] idBytes = new byte[4];
            Part.encodeInt(instantiator.getId(), idBytes);
            serializedInstantiators[2] = idBytes;
        }
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("IOException encountered while serializing instantiators using CacheServerHelper.serialize() method");
        }
    }
    ClientInstantiatorMessage clientInstantiatorMessage = new ClientInstantiatorMessage(EnumListenerEvent.AFTER_REGISTER_INSTANTIATOR, serializedInstantiators, (ClientProxyMembershipID) instantiator.getContext(), (EventID) instantiator.getEventId());
    // Deliver it to all the clients
    CacheClientNotifier.routeClientMessage(clientInstantiatorMessage);
}
Also used : IOException(java.io.IOException) ClientInstantiatorMessage(org.apache.geode.internal.cache.tier.sockets.ClientInstantiatorMessage) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache)

Example 8 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class ClientServerRegisterInterestsDUnitTest method setupGemFireCacheServer.

private void setupGemFireCacheServer() {
    Host localhost = Host.getHost(0);
    gemfireServerVm = localhost.getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    gemfireServerVm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0").set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory();
                regionFactory.setDataPolicy(DataPolicy.REPLICATE);
                regionFactory.setKeyConstraint(String.class);
                regionFactory.setValueConstraint(String.class);
                Region<String, String> example = regionFactory.create("Example");
                assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
                assertEquals("/Example", example.getFullPath());
                assertEquals("Example", example.getName());
                assertTrue(example.isEmpty());
                example.put("1", "ONE");
                assertFalse(example.isEmpty());
                assertEquals(1, example.size());
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();
                clientSubscriptionConfig.setCapacity(100);
                clientSubscriptionConfig.setEvictionPolicy("entry");
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException(String.format("Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", serverPort.get()), e);
            }
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) RegionFactory(org.apache.geode.cache.RegionFactory) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 9 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class RemoveAllCacheListenerClientServerRegressionTest method setupGemFireCacheServer.

// ================================================================================
private void setupGemFireCacheServer(RegionShortcut shortcut, boolean concChecks) {
    serverVM = Host.getHost(0).getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    String serverName = this.getClass().getSimpleName() + "_server";
    serverVM.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", serverName).set(MCAST_PORT, "0").set(LOG_FILE, serverName + ".log").set(LOG_LEVEL, "config").set("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory(shortcut);
                regionFactory.addCacheListener(new TestListener());
                regionFactory.setConcurrencyChecksEnabled(concChecks);
                regionFactory.create(REGION_NAME);
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException("Failed to start cache server " + serverName + " on port " + serverPort.get() + ": " + e.getStackTrace());
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 10 with Cache

use of org.apache.geode.cache.Cache in project geode by apache.

the class NonDistinctOrderByDUnitImpl method testMultiColOrderByWithMultiIndexResultProjection.

@Test
public void testMultiColOrderByWithMultiIndexResultProjection() throws Exception {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    final VM vm3 = host.getVM(3);
    Cache cache = this.getCache();
    NonDistinctOrderByTestImplementation test = createTestInstance();
    test.testMultiColOrderByWithMultiIndexResultProjection();
    this.closeCache(vm0, vm1, vm2, vm3);
}
Also used : NonDistinctOrderByTestImplementation(org.apache.geode.cache.query.functional.NonDistinctOrderByTestImplementation) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

Cache (org.apache.geode.cache.Cache)1044 Region (org.apache.geode.cache.Region)478 Test (org.junit.Test)476 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)292 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)277 VM (org.apache.geode.test.dunit.VM)264 Host (org.apache.geode.test.dunit.Host)230 AttributesFactory (org.apache.geode.cache.AttributesFactory)229 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)177 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)176 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)164 LocalRegion (org.apache.geode.internal.cache.LocalRegion)153 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)123 ClientCache (org.apache.geode.cache.client.ClientCache)117 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)112 Properties (java.util.Properties)101 CacheException (org.apache.geode.cache.CacheException)101 RegionAttributes (org.apache.geode.cache.RegionAttributes)99 QueryService (org.apache.geode.cache.query.QueryService)95 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)93