org.springframework.data.gemfire.client.ClientRegionFactoryBean Java Examples

The following examples show how to use org.springframework.data.gemfire.client.ClientRegionFactoryBean. 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: GeodeConfiguration.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Bean
RegionConfigurer interestRegisteringRegionConfigurer() {

	return new RegionConfigurer() {

		@Override
		@SuppressWarnings("unchecked")
		public void configure(String beanName, ClientRegionFactoryBean<?, ?> clientRegion) {

			Interest interest = new RegexInterest(".*", InterestResultPolicy.NONE,
				false, true);

			clientRegion.setInterests(ArrayUtils.asArray(interest));
		}
	};
}
 
Example #2
Source File: GeodeConfiguration.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Bean
RegionConfigurer subscriptionCacheListenerRegionConfigurer() {

	return new RegionConfigurer() {

		@Override
		@SuppressWarnings("unchecked")
		public void configure(String beanName, ClientRegionFactoryBean<?, ?> clientRegion) {

			CacheListener subscriptionCacheListener =
					new AbstractCommonEventProcessingCacheListener() {

				@Override
				protected void processEntryEvent(EntryEvent event, EntryEventType eventType) {

					if (event.isOriginRemote()) {
						System.err.printf("[%1$s] EntryEvent for [%2$s] with value [%3$s]%n",
							event.getKey(), event.getOperation(), event.getNewValue());
					}
				}
			};

			clientRegion.setCacheListeners(ArrayUtils.asArray(subscriptionCacheListener));
		}
	};
}
 
Example #3
Source File: MultiSiteCachingIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Bean
@SuppressWarnings({ "rawtypes", "unchecked" })
RegionConfigurer customersByNameCacheListenerConfigurer(@Qualifier("customersByNameCacheListener")
		CacheListener<String, Customer> customersByNameCacheListener) {

	return new RegionConfigurer() {

		@Override
		public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {

			if ("CustomersByName".equals(beanName)) {
				bean.setCacheListeners(ArrayUtils.<CacheListener>asArray(customersByNameCacheListener));
				bean.setInterests(ArrayUtils.<Interest>asArray(new RegexInterest(".*",
					InterestResultPolicy.KEYS, false, false)));
			}
		}
	};
}
 
Example #4
Source File: GeodeConfiguration.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Bean("YellowPages")
public ClientRegionFactoryBean<Object, Object> yellowPagesRegion(GemFireCache gemfireCache) {

	ClientRegionFactoryBean<Object, Object> clientRegion = new ClientRegionFactoryBean<>();

	clientRegion.setCache(gemfireCache);
	clientRegion.setClose(false);
	clientRegion.setShortcut(ClientRegionShortcut.CACHING_PROXY);

	clientRegion.setRegionConfigurers(
		interestRegisteringRegionConfigurer(),
		subscriptionCacheListenerRegionConfigurer()
	);

	return clientRegion;
}
 
Example #5
Source File: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithInlineCachingWhenPredicateReturnsFalse() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean<>());

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(clientRegionFactoryBean, never()).setCacheWriter(any(CacheWriter.class));
	verify(this.mockPredicate, times(2)).test(eq("Example"));
}
 
Example #6
Source File: WanClientConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean("Customers")
protected ClientRegionFactoryBean<Long, Customer> configureProxyClientCustomerRegion(GemFireCache gemFireCache) {
	ClientRegionFactoryBean<Long, Customer> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
	clientRegionFactoryBean.setCache(gemFireCache);
	clientRegionFactoryBean.setName("Customers");
	clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
	return clientRegionFactoryBean;
}
 
Example #7
Source File: FunctionInvocationClientApplicationConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean("Orders")
protected ClientRegionFactoryBean<Long, Order> configureProxyClientOrderRegion(GemFireCache gemFireCache) {
	ClientRegionFactoryBean<Long, Order> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
	clientRegionFactoryBean.setCache(gemFireCache);
	clientRegionFactoryBean.setName("Orders");
	clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
	return clientRegionFactoryBean;
}
 
Example #8
Source File: FunctionInvocationClientApplicationConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean("Products")
protected ClientRegionFactoryBean<Long, Product> configureProxyClientProductRegion(GemFireCache gemFireCache) {
	ClientRegionFactoryBean<Long, Product> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
	clientRegionFactoryBean.setCache(gemFireCache);
	clientRegionFactoryBean.setName("Products");
	clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
	return clientRegionFactoryBean;
}
 
Example #9
Source File: FunctionInvocationClientApplicationConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean("Customers")
protected ClientRegionFactoryBean<Long, Customer> configureProxyClientCustomerRegion(GemFireCache gemFireCache) {
	ClientRegionFactoryBean<Long, Customer> clientRegionFactoryBean = new ClientRegionFactoryBean<>();
	clientRegionFactoryBean.setCache(gemFireCache);
	clientRegionFactoryBean.setName("Customers");
	clientRegionFactoryBean.setShortcut(ClientRegionShortcut.PROXY);
	return clientRegionFactoryBean;
}
 
Example #10
Source File: ExistingRegionTemplateByRegionAutoConfigurationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Bean("Example")
public ClientRegionFactoryBean<Object, Object> exampleRegion(GemFireCache gemfireCache) {

	ClientRegionFactoryBean<Object, Object> clientRegion = new ClientRegionFactoryBean<>();

	clientRegion.setCache(gemfireCache);
	clientRegion.setClose(false);
	clientRegion.setShortcut(ClientRegionShortcut.LOCAL);

	return clientRegion;
}
 
Example #11
Source File: ClusterNotAvailableConfiguration.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
protected <K, V> ClientRegionFactoryBean configureAsLocalClientRegion(Environment environment,
		ClientRegionFactoryBean<K, V> clientRegion) {

	ClientRegionShortcut shortcut =
		environment.getProperty(SPRING_DATA_GEMFIRE_CACHE_CLIENT_REGION_SHORTCUT_PROPERTY,
			ClientRegionShortcut.class, LOCAL_CLIENT_REGION_SHORTCUT);

	clientRegion.setPoolName(null);
	clientRegion.setShortcut(shortcut);

	return clientRegion;
}
 
Example #12
Source File: ClusterNotAvailableConfiguration.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Bean
@SuppressWarnings("unused")
RegionConfigurer localClientRegionConfigurer(Environment environment) {

	return new RegionConfigurer() {

		@Override
		public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {
			configureAsLocalClientRegion(environment, bean);
		}
	};
}
 
Example #13
Source File: RepositoryCacheLoaderRegionConfigurer.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {

	if (getRegionBeanName().test(beanName)) {
		bean.setCacheLoader(newRepositoryCacheLoader());
	}
}
 
Example #14
Source File: RepositoryCacheWriterRegionConfigurer.java    From spring-boot-data-geode with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {

	if (getRegionBeanName().test(beanName)) {
		bean.setCacheWriter(newRepositoryCacheWriter());
	}
}
 
Example #15
Source File: ClusterNotAvailableConfiguration.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
protected Object configureAsLocalClientRegion(Environment environment, Object clientRegion) {

		return clientRegion instanceof ClientRegionFactoryBean
			? configureAsLocalClientRegion(environment, (ClientRegionFactoryBean<?, ?>) clientRegion)
			: configureAsLocalClientRegion(environment, (CacheTypeAwareRegionFactoryBean<?, ?>) clientRegion);
	}
 
Example #16
Source File: RepositoryCacheWriterRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithRepositoryCacheWriterWhenPredicateReturnsFalse() {

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	RepositoryCacheWriterRegionConfigurer regionConfigurer =
		new RepositoryCacheWriterRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, never()).setCacheWriter(any(CacheWriter.class));
	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #17
Source File: ClusterNotAvailableConfiguration.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
protected boolean isClientRegion(Object bean) {
	return bean instanceof CacheTypeAwareRegionFactoryBean || bean instanceof ClientRegionFactoryBean;
}
 
Example #18
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void doesNotConfigureClientRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsFalse() {

	when(this.mockPredicate.test(anyString())).thenReturn(false);

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, never()).setCacheLoader(any(CacheLoader.class));
	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #19
Source File: InlineCachingRegionConfigurer.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {
	this.compositeRegionConfigurer.configure(beanName, bean);
}
 
Example #20
Source File: InlineCachingRegionConfigurer.java    From spring-boot-data-geode with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(String beanName, ClientRegionFactoryBean<?, ?> bean) {
	regionConfigurers.forEach(regionConfigurer -> regionConfigurer.configure(beanName, bean));
}
 
Example #21
Source File: RepositoryCacheWriterRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configuresClientRegionFactoryBeanWithRepositoryCacheWriterWhenPredicateReturnsTrue() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	doAnswer(answer -> {

		CacheWriter cacheWriter = answer.getArgument(0);

		assertThat(cacheWriter).isInstanceOf(RepositoryCacheWriter.class);
		assertThat(((RepositoryCacheWriter) cacheWriter).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheWriter(isA(CacheWriter.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	RepositoryCacheWriterRegionConfigurer regionConfigurer =
		new RepositoryCacheWriterRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, times(1))
		.setCacheWriter(isA(RepositoryCacheWriter.class));

	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #22
Source File: RepositoryCacheLoaderRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configuresClientRegionFactoryBeanWithRepositoryCacheLoaderWhenPredicateReturnsTrue() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean());

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheLoader(isA(CacheLoader.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	RepositoryCacheLoaderRegionConfigurer regionConfigurer =
		new RepositoryCacheLoaderRegionConfigurer(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(this.mockPredicate, times(1)).test(eq("Example"));
}
 
Example #23
Source File: SpringBootApacheGeodeClientCacheApplicationIntegrationTests.java    From spring-boot-data-geode with Apache License 2.0 3 votes vote down vote up
@Bean("Example")
public ClientRegionFactoryBean<Object, Object> exampleRegion(GemFireCache gemfireCache) {

	ClientRegionFactoryBean<Object, Object> clientRegion = new ClientRegionFactoryBean<>();

	clientRegion.setCache(gemfireCache);
	clientRegion.setShortcut(ClientRegionShortcut.LOCAL);

	return clientRegion;
}
 
Example #24
Source File: InlineCachingRegionConfigurerUnitTests.java    From spring-boot-data-geode with Apache License 2.0 2 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void configureClientRegionFactoryBeanWithInlineCachingWhenPredicateReturnsTrue() {

	ClientRegionFactoryBean<?, ?> clientRegionFactoryBean = spy(new ClientRegionFactoryBean<>());

	doAnswer(answer -> {

		CacheLoader cacheLoader = answer.getArgument(0);

		assertThat(cacheLoader).isInstanceOf(RepositoryCacheLoader.class);
		assertThat(((RepositoryCacheLoader) cacheLoader).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheLoader(any(CacheLoader.class));

	doAnswer(answer -> {

		CacheWriter cacheWriter = answer.getArgument(0);

		assertThat(cacheWriter).isInstanceOf(RepositoryCacheWriter.class);
		assertThat(((RepositoryCacheWriter) cacheWriter).getRepository()).isEqualTo(this.mockRepository);

		return null;

	}).when(clientRegionFactoryBean).setCacheWriter(any(CacheWriter.class));

	when(this.mockPredicate.test(anyString())).thenReturn(true);

	InlineCachingRegionConfigurer<?, ?> regionConfigurer =
		new InlineCachingRegionConfigurer<>(this.mockRepository, this.mockPredicate);

	regionConfigurer.configure("Example", clientRegionFactoryBean);

	verify(clientRegionFactoryBean, times(1))
		.setCacheLoader(isA(RepositoryCacheLoader.class));

	verify(clientRegionFactoryBean, times(1))
		.setCacheWriter(isA(RepositoryCacheWriter.class));

	verify(this.mockPredicate, times(2)).test(eq("Example"));
}