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;
}
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);
}
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);
}
}
});
}
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());
}
}
});
}
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);
}
Aggregations