@Deprecated public static Region createProxyRegion(ClientCache cache, String regionName) { return cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName); }
factory.setStatisticsEnabled(true); factory.setCustomEntryIdleTimeout(new SessionCustomExpiry()); factory.addCacheListener(new SessionExpirationCacheListener()); factory.addCacheListener(new SessionExpirationCacheListener()); Region region = factory.create(getSessionManager().getRegionName());
@Override public Object call() throws Exception { ClientRegionFactory factory = ((ClientCache) getCache()) .createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY); if (valueConstraint != null) { factory.setValueConstraint(valueConstraint); } factory.create(regionName); return true; } });
private Region<String, HttpSession> createLocalSessionRegion() { ClientRegionFactory<String, HttpSession> factory = null; boolean enableLocalCache = (Boolean) properties.get(CacheProperty.ENABLE_LOCAL_CACHE); String regionName = (String) properties.get(CacheProperty.REGION_NAME); if (enableLocalCache) { // Create the region factory with caching and heap LRU enabled factory = this.cache .<String, HttpSession>createClientRegionFactory( ClientRegionShortcut.CACHING_PROXY_HEAP_LRU) .setCustomEntryIdleTimeout(new SessionCustomExpiry()); LOG.info("Created new local client session region: {}", regionName); } else { // Create the region factory without caching enabled factory = this.cache.createClientRegionFactory(ClientRegionShortcut.PROXY); LOG.info("Created new local client (uncached) session region: {} without any session expiry", regionName); } // Create the region return factory.create(regionName); } }
when(mockClientRegionFactory.addCacheListener(any(CacheListener.class))) .thenAnswer(newAdder(cacheListeners, mockClientRegionFactory)); when(mockClientRegionFactory.initCacheListeners(any(CacheListener[].class))).thenAnswer(invocation -> { cacheListeners.clear(); Collections.addAll(cacheListeners, invocation.getArgument(0)); when(mockClientRegionFactory.setCloningEnabled(anyBoolean())) .thenAnswer(newSetter(cloningEnabled, mockClientRegionFactory)); when(mockClientRegionFactory.setCompressor(any(Compressor.class))) .thenAnswer(newSetter(compressor, mockClientRegionFactory)); .when(mockClientRegionFactory).setConcurrencyChecksEnabled(anyBoolean()); when(mockClientRegionFactory.setConcurrencyLevel(anyInt())) .thenAnswer(newSetter(concurrencyLevel, mockClientRegionFactory)); when(mockClientRegionFactory.setCustomEntryIdleTimeout(any(CustomExpiry.class))) .thenAnswer(newSetter(customEntryIdleTimeout, mockClientRegionFactory)); when(mockClientRegionFactory.setCustomEntryTimeToLive(any(CustomExpiry.class))) .thenAnswer(newSetter(customEntryTimeToLive, mockClientRegionFactory)); when(mockClientRegionFactory.setDiskStoreName(anyString())) .thenAnswer(newSetter(diskStoreName, mockClientRegionFactory)); when(mockClientRegionFactory.setDiskSynchronous(anyBoolean())) .thenAnswer(newSetter(diskSynchronous, mockClientRegionFactory));
private Optional<String> configureWithRegionAttributes(ClientRegionFactory<K, V> clientRegionFactory) { AtomicReference<String> regionAttributesPoolName = new AtomicReference<>(null); Optional.ofNullable(getAttributes()).ifPresent(regionAttributes -> { regionAttributesPoolName.set(regionAttributes.getPoolName()); stream(nullSafeArray(regionAttributes.getCacheListeners(), CacheListener.class)) .forEach(clientRegionFactory::addCacheListener); clientRegionFactory.setCloningEnabled(regionAttributes.getCloningEnabled()); clientRegionFactory.setCompressor(regionAttributes.getCompressor()); clientRegionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled()); clientRegionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel()); clientRegionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout()); clientRegionFactory.setCustomEntryTimeToLive(regionAttributes.getCustomEntryTimeToLive()); clientRegionFactory.setDiskStoreName(regionAttributes.getDiskStoreName()); clientRegionFactory.setDiskSynchronous(regionAttributes.isDiskSynchronous()); clientRegionFactory.setEntryIdleTimeout(regionAttributes.getEntryIdleTimeout()); clientRegionFactory.setEntryTimeToLive(regionAttributes.getEntryTimeToLive()); clientRegionFactory.setEvictionAttributes(regionAttributes.getEvictionAttributes()); clientRegionFactory.setInitialCapacity(regionAttributes.getInitialCapacity()); clientRegionFactory.setKeyConstraint(regionAttributes.getKeyConstraint()); clientRegionFactory.setLoadFactor(regionAttributes.getLoadFactor()); clientRegionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout()); clientRegionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive()); clientRegionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled()); clientRegionFactory.setValueConstraint(regionAttributes.getValueConstraint()); }); return Optional.ofNullable(regionAttributesPoolName.get()).filter(StringUtils::hasText); }
/** * Constructs a new {@link Region} using the provided {@link ClientRegionFactory} as either * a {@link Region root Region} or a {@link Region sub-Region} if {@link Region parent} * is not {@literal null}. * * @param clientRegionFactory {@link ClientRegionFactory} containing the configuration * for the new {@link Region}. * @param parent {@link Region} designated as the parent of the new {@link Region} * if the new {@link Region} is a {@link Region sub-Region}. * @param regionName {@link String name} of the new {@link Region}. * @return the new {@link Region} initialized with the given {@link String name}. */ private Region<K, V> newRegion(ClientRegionFactory<K, V> clientRegionFactory, Region<?, ?> parent, String regionName) { if (parent != null) { logInfo("Creating client sub-Region [%1$s] with parent Region [%2$s]", regionName, parent.getName()); return clientRegionFactory.<K, V>createSubregion(parent, regionName); } else { logInfo("Creating client Region [%s]", regionName); return clientRegionFactory.create(regionName); } }
public static void main(String[] args) { // connect to the locator using default port 10334 ClientCache cache = new ClientCacheFactory().set("log-level", "WARN").create(); final String poolName = "subscriptionPool"; PoolManager.createFactory().addLocator("127.0.0.1", 10334).setSubscriptionEnabled(true) .create(poolName); // create a local region that matches the server region final ClientRegionFactory<Integer, String> incomingRegionFactory = cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.PROXY); Region<Integer, String> incomingRegion = incomingRegionFactory.setPoolName(poolName).create(INCOMING_REGION_NAME); // create another local region that matches the server region final ClientRegionFactory<String, String> outgoingRegionFactory = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.PROXY); Region<String, String> outgoingRegion = outgoingRegionFactory.setPoolName(poolName).create(OUTGOING_REGION_NAME); new Example().checkWords(incomingRegion, outgoingRegion, Arrays.asList(new String[] {"that", "teh", "wil", "i'"})); cache.close(); }
clientRegionFactory.setStatisticsEnabled(resolveStatisticsEnabled());
private Optional<String> configureWithRegionAttributes(ClientRegionFactory<K, V> clientRegionFactory) { AtomicReference<String> regionAttributesPoolName = new AtomicReference<>(null); Optional.ofNullable(getAttributes()).ifPresent(regionAttributes -> { regionAttributesPoolName.set(regionAttributes.getPoolName()); stream(nullSafeArray(regionAttributes.getCacheListeners(), CacheListener.class)) .forEach(clientRegionFactory::addCacheListener); clientRegionFactory.setCloningEnabled(regionAttributes.getCloningEnabled()); clientRegionFactory.setCompressor(regionAttributes.getCompressor()); clientRegionFactory.setConcurrencyChecksEnabled(regionAttributes.getConcurrencyChecksEnabled()); clientRegionFactory.setConcurrencyLevel(regionAttributes.getConcurrencyLevel()); clientRegionFactory.setCustomEntryIdleTimeout(regionAttributes.getCustomEntryIdleTimeout()); clientRegionFactory.setCustomEntryTimeToLive(regionAttributes.getCustomEntryTimeToLive()); clientRegionFactory.setDiskStoreName(regionAttributes.getDiskStoreName()); clientRegionFactory.setDiskSynchronous(regionAttributes.isDiskSynchronous()); clientRegionFactory.setEntryIdleTimeout(regionAttributes.getEntryIdleTimeout()); clientRegionFactory.setEntryTimeToLive(regionAttributes.getEntryTimeToLive()); clientRegionFactory.setEvictionAttributes(regionAttributes.getEvictionAttributes()); clientRegionFactory.setInitialCapacity(regionAttributes.getInitialCapacity()); clientRegionFactory.setKeyConstraint(regionAttributes.getKeyConstraint()); clientRegionFactory.setLoadFactor(regionAttributes.getLoadFactor()); clientRegionFactory.setRegionIdleTimeout(regionAttributes.getRegionIdleTimeout()); clientRegionFactory.setRegionTimeToLive(regionAttributes.getRegionTimeToLive()); clientRegionFactory.setStatisticsEnabled(regionAttributes.getStatisticsEnabled()); clientRegionFactory.setValueConstraint(regionAttributes.getValueConstraint()); }); return Optional.ofNullable(regionAttributesPoolName.get()).filter(StringUtils::hasText); }
/** * Constructs a new {@link Region} using the provided {@link ClientRegionFactory} as either * a {@link Region root Region} or a {@link Region sub-Region} if {@link Region parent} * is not {@literal null}. * * @param clientRegionFactory {@link ClientRegionFactory} containing the configuration * for the new {@link Region}. * @param parent {@link Region} designated as the parent of the new {@link Region} * if the new {@link Region} is a {@link Region sub-Region}. * @param regionName {@link String name} of the new {@link Region}. * @return the new {@link Region} initialized with the given {@link String name}. */ private Region<K, V> newRegion(ClientRegionFactory<K, V> clientRegionFactory, Region<?, ?> parent, String regionName) { if (parent != null) { logInfo("Creating client sub-Region [%1$s] with parent Region [%2$s]", regionName, parent.getName()); return clientRegionFactory.<K, V>createSubregion(parent, regionName); } else { logInfo("Creating client Region [%s]", regionName); return clientRegionFactory.create(regionName); } }
clientRegionFactory.setStatisticsEnabled(resolveStatisticsEnabled());
public Region createProxyRegion(String regionPath) { return cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionPath); }
factory.setStatisticsEnabled(true); factory.setCustomEntryIdleTimeout(new SessionCustomExpiry()); factory.addCacheListener(new SessionExpirationCacheListener()); factory.addCacheListener(new SessionExpirationCacheListener()); Region region = factory.create(getSessionManager().getRegionName());
private Region<String, PdxInstance> getRegion(String table) { Region<String, PdxInstance> r = cache.getRegion(table); if (r == null) { try { if (isClient) { ClientRegionFactory<String, PdxInstance> crf = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY); r = crf.create(table); } else { RegionFactory<String, PdxInstance> rf = ((Cache) cache).createRegionFactory(RegionShortcut.PARTITION); r = rf.create(table); } } catch (RegionExistsException e) { // another thread created the region r = cache.getRegion(table); } } return r; } }
@Test public void serverUsesFilteredCache() { serverVM.invoke(() -> { Cache serverCache = (Cache) cache; serverCache.createRegionFactory(RegionShortcut.REPLICATE).create("region"); }); clientVM.invoke(() -> { ClientCache clientCache = (ClientCache) cache; Region<String, String> region = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create("region"); region.put("Object1", "Value1"); }); serverVM.invoke(() -> { Cache serverCache = (Cache) cache; CacheServer server = serverCache.getCacheServers().stream().findFirst().get(); CacheServerImpl impl = (CacheServerImpl) server; assertThat(impl.getAcceptor().getCachedRegionHelper().getCache()) .isInstanceOf(InternalCacheForClientAccess.class); }); }
@Test(expected = GemFireConfigException.class) public void clientIsPreventedFromConnectingToLocatorAsServer() { IgnoredException.addIgnoredException("Improperly configured client detected"); ClientCacheFactory clientCacheFactory = new ClientCacheFactory(); clientCacheFactory.addPoolServer("localhost", DistributedTestUtils.getDUnitLocatorPort()); clientCacheFactory.setPoolSubscriptionEnabled(true); getClientCache(clientCacheFactory); Region region = ((ClientCache) cache).createClientRegionFactory(ClientRegionShortcut.PROXY) .create(REGION_NAME1); region.registerInterest(k1); }
private void testAllOperations() { ClientCache clientCache = (ClientCache) cache; Region<String, String> region = clientCache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create("internalRegion"); assertFailure(() -> region.create("Object1", "Value1")); assertFailure(() -> region.put("Object1", "Value1")); assertFailure(() -> region.putIfAbsent("Object1", "Value1")); assertFailure(() -> region.get("Object1")); Map<String, String> map = new HashMap<>(); map.put("Object1", "Value1"); assertFailure(() -> region.putAll(map)); List<String> list = new ArrayList<>(); list.add("Object1"); assertFailure(() -> region.getAll(list)); assertFailure(() -> region.removeAll(list)); assertFailure(() -> region.destroy("Object1")); assertFailure(() -> region.remove("Object1")); assertFailure(() -> region.replace("Object1", "oldValue", "newValue")); assertFailure(() -> region.invalidate("Object1")); assertFailure(region::keySetOnServer); assertFailure(() -> region.registerInterest("Object1")); }
cc.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName); pool = (PoolImpl) ((GemFireCacheImpl) cc).getDefaultPool();
private Example(String username) { Properties props = new Properties(); props.setProperty("security-username", username); props.setProperty("security-client-auth-init", ExampleAuthInit.class.getName()); props.setProperty("ssl-enabled-components", "all"); props.setProperty("ssl-keystore", "keystore.jks"); props.setProperty("ssl-keystore-password", "password"); props.setProperty("ssl-truststore", "truststore.jks"); props.setProperty("ssl-truststore-password", "password"); // connect to the locator using default port 10334 cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true) .addPoolLocator("localhost", 10334).create(); region1 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create(REGION1); region2 = cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) .create(REGION2); }