org.apache.geode.cache.Cache Java Examples
The following examples show how to use
org.apache.geode.cache.Cache.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocatorsConfigurationIntegrationTests.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
@Test public void peerCacheLocatorPropertiesArePresent() { Cache peerCache = newApplicationContext(PeerCacheTestConfiguration.class).getBean("gemfireCache", Cache.class); assertThat(peerCache).isNotNull(); assertThat(peerCache.getDistributedSystem()).isNotNull(); Properties gemfireProperties = peerCache.getDistributedSystem().getProperties(); assertThat(gemfireProperties).isNotNull(); assertThat(gemfireProperties).containsKeys(LOCATORS_PROPERTY, REMOTE_LOCATORS_PROPERTY); assertThat(gemfireProperties.getProperty(LOCATORS_PROPERTY)).isEqualTo("mailbox[11235],skullbox[12480]"); assertThat(gemfireProperties.getProperty(REMOTE_LOCATORS_PROPERTY)).isEqualTo("remotehost[10334]"); }
Example #2
Source File: SpringBootApacheGeodePeerCacheApplication.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
@Bean public ApplicationRunner peerCacheAssertRunner(Cache peerCache) { return args -> { assertThat(peerCache).isNotNull(); assertThat(peerCache.getName()).isEqualTo(SpringBootApacheGeodePeerCacheApplication.class.getSimpleName()); assertThat(peerCache.getDistributedSystem()).isNotNull(); assertThat(peerCache.getDistributedSystem().getProperties()).isNotNull(); assertThat(peerCache.getDistributedSystem().getProperties().getProperty("disable-auto-reconnect")) .isEqualTo("false"); assertThat(peerCache.getDistributedSystem().getProperties().getProperty("use-cluster-configuration")) .isEqualTo("true"); this.logger.info("Peer Cache [{}] configured and bootstrapped successfully!", peerCache.getName()); //System.err.printf("Peer Cache [%s] configured and bootstrapped successfully!%n", peerCache.getName()); }; }
Example #3
Source File: MembershipListenerAdapterUnitTests.java From spring-boot-data-geode with Apache License 2.0 | 6 votes |
@Test public void registersListenerWithPeerCache() { Cache mockCache = mock(Cache.class); doReturn(this.mockDistributedSystem).when(mockCache).getDistributedSystem(); doReturn(this.mockDistributionManager).when(this.mockDistributedSystem).getDistributionManager(); MembershipListenerAdapter<?> listener = new TestMembershipListener(); assertThat(listener.register(mockCache)).isSameAs(listener); verify(mockCache, times(1)).getDistributedSystem(); verify(this.mockDistributedSystem, times(1)).getDistributionManager(); verify(this.mockDistributionManager, times(1)) .addMembershipListener(eq(listener)); }
Example #4
Source File: BootGeodeMultiSiteCachingServerApplication.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Bean(CUSTOMERS_BY_NAME_REGION) ReplicatedRegionFactoryBean<String, Customer> customersByNameRegion(Cache cache, @Autowired(required = false) List<RegionConfigurer> regionConfigurers) { ReplicatedRegionFactoryBean<String, Customer> customersByName = new ReplicatedRegionFactoryBean<>(); customersByName.setCache(cache); customersByName.setPersistent(PERSISTENT); customersByName.setRegionConfigurers(regionConfigurers); return customersByName; }
Example #5
Source File: GenericKeyTest.java From immutables with Apache License 2.0 | 5 votes |
GenericKeyTest(Cache cache) { ImmutableGeodeSetup setup = GeodeSetup.builder() .regionResolver(RegionResolver.defaultResolver(cache)) .keyExtractorFactory(genericExtractor()) .build(); AutocreateRegion autocreate = new AutocreateRegion(cache); Backend backend = WithSessionCallback.wrap(new GeodeBackend(setup), autocreate); this.repository = new PersonRepository(backend); this.region = cache.getRegion("person"); this.generator = new PersonGenerator(); }
Example #6
Source File: GeodeBookstoreTest.java From calcite with Apache License 2.0 | 5 votes |
@BeforeAll public static void setUp() throws Exception { Cache cache = POLICY.cache(); Region<?, ?> bookMaster = cache.<String, Object>createRegionFactory().create("BookMaster"); new JsonLoader(bookMaster).loadClasspathResource("/book_master.json"); Region<?, ?> bookCustomer = cache.<String, Object>createRegionFactory().create("BookCustomer"); new JsonLoader(bookCustomer).loadClasspathResource("/book_customer.json"); }
Example #7
Source File: GeodeAllDataTypesTest.java From calcite with Apache License 2.0 | 5 votes |
@BeforeAll public static void setUp() { final Cache cache = POLICY.cache(); final Region<?, ?> region = cache.<String, Object>createRegionFactory() .create("allDataTypesRegion"); final List<Map<String, Object>> mapList = createMapList(); new JsonLoader(region).loadMapList(mapList); }
Example #8
Source File: GeodeZipsTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testWhereWithOrForLargeValueList() throws Exception { Cache cache = POLICY.cache(); QueryService queryService = cache.getQueryService(); Query query = queryService.newQuery("select state as state from /zips"); SelectResults results = (SelectResults) query.execute(); Set<String> stateList = (Set<String>) results.stream().map(s -> { StructImpl struct = (StructImpl) s; return struct.get("state"); }) .collect(Collectors.toCollection(LinkedHashSet::new)); String stateListPredicate = stateList.stream() .map(s -> String.format(Locale.ROOT, "state = '%s'", s)) .collect(Collectors.joining(" OR ")); String stateListStr = "'" + String.join("', '", stateList) + "'"; String queryToBeExecuted = "SELECT state as state FROM view WHERE " + stateListPredicate; String expectedQuery = "SELECT state AS state FROM /zips WHERE state " + "IN SET(" + stateListStr + ")"; calciteAssert() .query(queryToBeExecuted) .returnsCount(149) .queryContains( GeodeAssertions.query(expectedQuery)); }
Example #9
Source File: EventServerConfig.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Bean AsyncEventQueueFactoryBean orderAsyncEventQueue(GemFireCache gemFireCache, AsyncEventListener orderAsyncEventListener) { AsyncEventQueueFactoryBean asyncEventQueueFactoryBean = new AsyncEventQueueFactoryBean((Cache) gemFireCache); asyncEventQueueFactoryBean.setBatchTimeInterval(1000); asyncEventQueueFactoryBean.setBatchSize(5); asyncEventQueueFactoryBean.setAsyncEventListener(orderAsyncEventListener); return asyncEventQueueFactoryBean; }
Example #10
Source File: SiteAWanEnabledServerConfig.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Bean GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) { GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); gatewayReceiverFactoryBean.setStartPort(15000); gatewayReceiverFactoryBean.setEndPort(15010); gatewayReceiverFactoryBean.setManualStart(false); return gatewayReceiverFactoryBean; }
Example #11
Source File: SiteBWanServerConfig.java From spring-data-examples with Apache License 2.0 | 5 votes |
@Bean GatewayReceiverFactoryBean createGatewayReceiver(GemFireCache gemFireCache) { GatewayReceiverFactoryBean gatewayReceiverFactoryBean = new GatewayReceiverFactoryBean((Cache) gemFireCache); gatewayReceiverFactoryBean.setStartPort(25000); gatewayReceiverFactoryBean.setEndPort(25010); return gatewayReceiverFactoryBean; }
Example #12
Source File: ExampleAsyncEventListener.java From geode-examples with Apache License 2.0 | 5 votes |
@Override public boolean processEvents(List<AsyncEvent> events) { final ExecutorService exService = Executors.newSingleThreadExecutor(); for (AsyncEvent<Integer, String> event : events) { final String oldValue = event.getDeserializedValue(); final String newValue = spellCheck(oldValue); exService.submit(() -> { Cache cache = (Cache) event.getRegion().getRegionService(); Region<String, String> region = cache.getRegion(Example.OUTGOING_REGION_NAME); region.put(oldValue, newValue); }); } return true; }
Example #13
Source File: MembershipListenerAdapter.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
/** * Registers this {@link MembershipListener} with the given {@literal peer} {@link Cache}. * * @param peerCache {@literal peer} {@link Cache} on which to register this {@link MembershipListener}. * @return this {@link MembershipListenerAdapter}. * @see org.apache.geode.cache.Cache */ @SuppressWarnings("unchecked") public T register(Cache peerCache) { Optional.ofNullable(peerCache) .map(Cache::getDistributedSystem) .filter(InternalDistributedSystem.class::isInstance) .map(InternalDistributedSystem.class::cast) .map(InternalDistributedSystem::getDistributionManager) .ifPresent(distributionManager -> distributionManager .addMembershipListener(this)); return (T) this; }
Example #14
Source File: GeodeGatewayReceiversHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) { AtomicInteger globalIndex = new AtomicInteger(0); Set<GatewayReceiver> gatewayReceivers = getGemFireCache() .map(Cache.class::cast) .map(Cache::getGatewayReceivers) .orElseGet(Collections::emptySet); builder.withDetail("geode.gateway-receiver.count", gatewayReceivers.size()); gatewayReceivers.stream() .filter(Objects::nonNull) .forEach(gatewayReceiver -> { int index = globalIndex.getAndIncrement(); builder.withDetail(gatewayReceiverKey(index, "bind-address"), gatewayReceiver.getBindAddress()) .withDetail(gatewayReceiverKey(index, "end-port"), gatewayReceiver.getEndPort()) .withDetail(gatewayReceiverKey(index, "host"), gatewayReceiver.getHost()) .withDetail(gatewayReceiverKey(index, "max-time-between-pings"), gatewayReceiver.getMaximumTimeBetweenPings()) .withDetail(gatewayReceiverKey(index, "port"), gatewayReceiver.getPort()) .withDetail(gatewayReceiverKey(index, "running"), toYesNoString(gatewayReceiver.isRunning())) .withDetail(gatewayReceiverKey(index, "socket-buffer-size"), gatewayReceiver.getSocketBufferSize()) .withDetail(gatewayReceiverKey(index, "start-port"), gatewayReceiver.getStartPort()); }); builder.up(); return; } builder.unknown(); }
Example #15
Source File: GeodeAsyncEventQueuesHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) { Set<AsyncEventQueue> asyncEventQueues = getGemFireCache() .map(Cache.class::cast) .map(Cache::getAsyncEventQueues) .orElseGet(Collections::emptySet); builder.withDetail("geode.async-event-queue.count", asyncEventQueues.size()); asyncEventQueues.stream() .filter(Objects::nonNull) .forEach(asyncEventQueue -> { String asyncEventQueueId = asyncEventQueue.getId(); builder.withDetail(asyncEventQueueKey(asyncEventQueueId, "batch-conflation-enabled"), toYesNoString(asyncEventQueue.isBatchConflationEnabled())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "batch-size"), asyncEventQueue.getBatchSize()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "batch-time-interval"), asyncEventQueue.getBatchTimeInterval()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "disk-store-name"), asyncEventQueue.getDiskStoreName()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "disk-synchronous"), toYesNoString(asyncEventQueue.isDiskSynchronous())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "dispatcher-threads"), asyncEventQueue.getDispatcherThreads()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "forward-expiration-destroy"), toYesNoString(asyncEventQueue.isForwardExpirationDestroy())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "max-queue-memory"), asyncEventQueue.getMaximumQueueMemory()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "order-policy"), asyncEventQueue.getOrderPolicy()) .withDetail(asyncEventQueueKey(asyncEventQueueId, "parallel"), toYesNoString(asyncEventQueue.isParallel())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "persistent"), toYesNoString(asyncEventQueue.isPersistent())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "primary"), toYesNoString(asyncEventQueue.isPrimary())) .withDetail(asyncEventQueueKey(asyncEventQueueId, "size"), asyncEventQueue.size()); }); builder.up(); return; } builder.unknown(); }
Example #16
Source File: ExampleAsyncEventListener.java From geode-examples with Apache License 2.0 | 5 votes |
@Override public boolean processEvents(List<AsyncEvent> events) { final ExecutorService exService = Executors.newSingleThreadExecutor(); for (AsyncEvent<Integer, String> event : events) { final String oldValue = event.getDeserializedValue(); final String newValue = spellCheck(oldValue); exService.submit(() -> { Cache cache = (Cache) event.getRegion().getRegionService(); Region<String, String> region = cache.getRegion(Example.OUTGOING_REGION_NAME); region.put(oldValue, newValue); }); } return true; }
Example #17
Source File: BootGeodeMultiSiteCachingServerApplication.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Bean GatewaySenderFactoryBean customersByNameGatewaySender(Cache cache, @Value("${geode.distributed-system.remote.id:1}") int remoteDistributedSystemId) { GatewaySenderFactoryBean gatewaySender = new GatewaySenderFactoryBean(cache); gatewaySender.setPersistent(PERSISTENT); gatewaySender.setRemoteDistributedSystemId(remoteDistributedSystemId); return gatewaySender; }
Example #18
Source File: SimpleCacheResolver.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
/** * Attempts to resolve an {@link Optional} {@link Cache} instance. * * @return an {@link Optional} {@link Cache} instance. * @see org.springframework.geode.util.CacheUtils#isPeerCache(RegionService) * @see org.apache.geode.cache.CacheFactory#getAnyInstance() * @see org.apache.geode.cache.Cache * @see java.util.Optional */ public Optional<Cache> resolvePeerCache() { try { return Optional.ofNullable(CacheFactory.getAnyInstance()) .filter(CacheUtils::isPeerCache); } catch (Throwable ignore) { return Optional.empty(); } }
Example #19
Source File: BootGeodeMultiSiteCachingServerApplication.java From spring-boot-data-geode with Apache License 2.0 | 5 votes |
@Bean ApplicationRunner geodeClusterObjectsBootstrappedAssertionRunner(Environment environment, Cache cache, Region<?, ?> customersByName, GatewayReceiver gatewayReceiver, GatewaySender gatewaySender) { return args -> { assertThat(cache).isNotNull(); assertThat(cache.getName()).startsWith(BootGeodeMultiSiteCachingServerApplication.class.getSimpleName()); assertThat(customersByName).isNotNull(); assertThat(customersByName.getAttributes()).isNotNull(); assertThat(customersByName.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.REPLICATE); assertThat(customersByName.getAttributes().getGatewaySenderIds()).containsExactly(gatewaySender.getId()); assertThat(customersByName.getName()).isEqualTo(CUSTOMERS_BY_NAME_REGION); assertThat(customersByName.getRegionService()).isEqualTo(cache); assertThat(cache.getRegion(RegionUtils.toRegionPath(CUSTOMERS_BY_NAME_REGION))).isEqualTo(customersByName); assertThat(gatewayReceiver).isNotNull(); assertThat(gatewayReceiver.isRunning()).isTrue(); assertThat(cache.getGatewayReceivers()).containsExactly(gatewayReceiver); assertThat(gatewaySender).isNotNull(); assertThat(gatewaySender.isRunning()).isTrue(); assertThat(cache.getGatewaySenders().stream().map(GatewaySender::getId).collect(Collectors.toSet())) .containsExactly(gatewaySender.getId()); System.err.printf("Apache Geode Cluster [%s] configured and bootstrapped successfully!%n", environment.getProperty("spring.application.name", "UNKNOWN")); }; }
Example #20
Source File: AutocreateRegion.java From immutables with Apache License 2.0 | 4 votes |
AutocreateRegion(Cache cache) { this(cache, ContainerNaming.DEFAULT); }
Example #21
Source File: GeodeCacheServersHealthIndicator.java From spring-boot-data-geode with Apache License 2.0 | 4 votes |
@Override protected void doHealthCheck(Health.Builder builder) { if (getGemFireCache().filter(CacheUtils::isPeer).isPresent()) { AtomicInteger globalIndex = new AtomicInteger(0); List<CacheServer> cacheServers = getGemFireCache() .map(Cache.class::cast) .map(Cache::getCacheServers) .orElseGet(Collections::emptyList); builder.withDetail("geode.cache.server.count", cacheServers.size()); cacheServers.stream() .filter(Objects::nonNull) .forEach(cacheServer -> { int cacheServerIndex = globalIndex.getAndIncrement(); builder.withDetail(cacheServerKey(cacheServerIndex, "bind-address"), cacheServer.getBindAddress()) .withDetail(cacheServerKey(cacheServerIndex, "hostname-for-clients"), cacheServer.getHostnameForClients()) .withDetail(cacheServerKey(cacheServerIndex, "load-poll-interval"), cacheServer.getLoadPollInterval()) .withDetail(cacheServerKey(cacheServerIndex, "max-connections"), cacheServer.getMaxConnections()) .withDetail(cacheServerKey(cacheServerIndex, "max-message-count"), cacheServer.getMaximumMessageCount()) .withDetail(cacheServerKey(cacheServerIndex, "max-threads"), cacheServer.getMaxThreads()) .withDetail(cacheServerKey(cacheServerIndex, "max-time-between-pings"), cacheServer.getMaximumTimeBetweenPings()) .withDetail(cacheServerKey(cacheServerIndex, "message-time-to-live"), cacheServer.getMessageTimeToLive()) .withDetail(cacheServerKey(cacheServerIndex, "port"), cacheServer.getPort()) .withDetail(cacheServerKey(cacheServerIndex, "running"), toYesNoString(cacheServer.isRunning())) .withDetail(cacheServerKey(cacheServerIndex, "socket-buffer-size"), cacheServer.getSocketBufferSize()) .withDetail(cacheServerKey(cacheServerIndex, "tcp-no-delay"), toYesNoString(cacheServer.getTcpNoDelay())); Optional.ofNullable(cacheServer.getLoadProbe()) .filter(ActuatorServerLoadProbeWrapper.class::isInstance) .map(ActuatorServerLoadProbeWrapper.class::cast) .flatMap(ActuatorServerLoadProbeWrapper::getCurrentServerMetrics) .ifPresent(serverMetrics -> { builder.withDetail(cacheServerMetricsKey(cacheServerIndex, "client-count"), serverMetrics.getClientCount()) .withDetail(cacheServerMetricsKey(cacheServerIndex, "max-connection-count"), serverMetrics.getMaxConnections()) .withDetail(cacheServerMetricsKey(cacheServerIndex, "open-connection-count"), serverMetrics.getConnectionCount()) .withDetail(cacheServerMetricsKey(cacheServerIndex, "subscription-connection-count"), serverMetrics.getSubscriptionConnectionCount()); ServerLoad serverLoad = cacheServer.getLoadProbe().getLoad(serverMetrics); if (serverLoad != null) { builder.withDetail(cacheServerLoadKey(cacheServerIndex, "connection-load"), serverLoad.getConnectionLoad()) .withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-connection"), serverLoad.getLoadPerConnection()) .withDetail(cacheServerLoadKey(cacheServerIndex, "subscription-connection-load"), serverLoad.getSubscriptionConnectionLoad()) .withDetail(cacheServerLoadKey(cacheServerIndex, "load-per-subscription-connection"), serverLoad.getLoadPerSubscriptionConnection()); } }); }); builder.up(); return; } builder.unknown(); }
Example #22
Source File: GeodeEmbeddedPolicy.java From calcite with Apache License 2.0 | 4 votes |
/** * Returns current cache instance which was initialized for tests. * @throws IllegalStateException if server process didn't start */ Cache cache() { requireStatus(AbstractLauncher.Status.ONLINE); return CacheFactory.getAnyInstance(); }
Example #23
Source File: GeodeZipsTest.java From calcite with Apache License 2.0 | 4 votes |
@BeforeAll public static void setUp() throws Exception { Cache cache = POLICY.cache(); Region<?, ?> region = cache.<String, Object>createRegionFactory().create("zips"); new JsonLoader(region).loadClasspathResource("/zips-mini.json"); }
Example #24
Source File: GeodeExtension.java From immutables with Apache License 2.0 | 4 votes |
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return Cache.class.isAssignableFrom(parameterContext.getParameter().getType()); }
Example #25
Source File: GeodeExtension.java From immutables with Apache License 2.0 | 4 votes |
/** * Returns current cache instance which was initialized for tests. * @throws IllegalStateException if server process didn't start */ Cache cache() { requireStatus(AbstractLauncher.Status.ONLINE); return CacheFactory.getAnyInstance(); }
Example #26
Source File: JsonLoader.java From calcite-test-dataset with Apache License 2.0 | 4 votes |
public JsonLoader(Cache cache, String regionName, String rootPackage) { this.cache = cache; this.rootPackage = rootPackage; this.region = cache.getRegion(regionName); this.mapper = new ObjectMapper(); }
Example #27
Source File: AutocreateRegion.java From immutables with Apache License 2.0 | 4 votes |
AutocreateRegion(Cache cache, ContainerNaming containerNaming) { this.cache = cache; this.naming = containerNaming; }
Example #28
Source File: GetAllOptimizationTest.java From immutables with Apache License 2.0 | 4 votes |
GetAllOptimizationTest(Cache cache) { this.cache = cache; this.calls = new ArrayList<>(); }
Example #29
Source File: GeodeAggregationTest.java From immutables with Apache License 2.0 | 4 votes |
GeodeAggregationTest(Cache cache) { AutocreateRegion autocreate = new AutocreateRegion(cache); backend = WithSessionCallback.wrap(new GeodeBackend(GeodeSetup.of(cache)), autocreate); }
Example #30
Source File: GeodePersonTest.java From immutables with Apache License 2.0 | 4 votes |
public GeodePersonTest(Cache cache) { AutocreateRegion autocreate = new AutocreateRegion(cache); backend = WithSessionCallback.wrap(new GeodeBackend(GeodeSetup.of(cache)), autocreate); }