Refine search
@BeforeClass public static void init() throws Exception { cacheFactoryBean = new CacheFactoryBean(); cacheFactoryBean.afterPropertiesSet(); Cache cache = (Cache) cacheFactoryBean.getObject(); region = cache.createRegionFactory().setScope(Scope.LOCAL).create("sig-tests"); }
/** * Sets and then returns a reference to Pivotal GemFire/Apache Geode {@link Properties} used to configure the cache. * * @param properties reference to Pivotal GemFire/Apache Geode {@link Properties} used to configure the cache. * @return a reference to Pivotal GemFire/Apache Geode {@link Properties} used to configure the cache. * @see java.util.Properties * @see #setProperties(Properties) * @see #getProperties() */ protected Properties setAndGetProperties(Properties properties) { setProperties(properties); return getProperties(); }
/** * Initializes this {@link CacheFactoryBean} after properties have been set by the Spring container. * * @throws Exception if initialization fails. * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() * @see #applyCacheConfigurers() * @see #initBeanFactoryLocator() */ @Override public void afterPropertiesSet() throws Exception { applyCacheConfigurers(); initBeanFactoryLocator(); }
@BeforeClass public static void init() throws Exception { cacheFactoryBean = new CacheFactoryBean(); Cache cache = (Cache) cacheFactoryBean.getObject(); region = cache.createRegionFactory().setScope(Scope.LOCAL).create("sig-tests"); }
/** * Configures PDX for this peer {@link Cache} instance. * * @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with PDX. * @return the given {@link CacheFactory}. * @see org.apache.geode.cache.CacheFactory */ private CacheFactory configurePdx(CacheFactory cacheFactory) { Optional.ofNullable(getPdxSerializer()).ifPresent(cacheFactory::setPdxSerializer); Optional.ofNullable(getPdxDiskStoreName()).filter(StringUtils::hasText) .ifPresent(cacheFactory::setPdxDiskStore); Optional.ofNullable(getPdxIgnoreUnreadFields()).ifPresent(cacheFactory::setPdxIgnoreUnreadFields); Optional.ofNullable(getPdxPersistent()).ifPresent(cacheFactory::setPdxPersistent); Optional.ofNullable(getPdxReadSerialized()).ifPresent(cacheFactory::setPdxReadSerialized); return cacheFactory; }
protected <T extends GemFireCache> T postProcess(T cache) { loadCacheXml(cache); Optional.ofNullable(getCopyOnRead()).ifPresent(cache::setCopyOnRead); Optional.ofNullable(getGatewayConflictResolver()).ifPresent(((Cache) cache)::setGatewayConflictResolver); Optional.ofNullable(getLockLease()).ifPresent(((Cache) cache)::setLockLease); Optional.ofNullable(getLockTimeout()).ifPresent(((Cache) cache)::setLockTimeout); Optional.ofNullable(getMessageSyncInterval()).ifPresent(((Cache) cache)::setMessageSyncInterval); Optional.ofNullable(getSearchTimeout()).ifPresent(((Cache) cache)::setSearchTimeout); configureHeapPercentages(cache); configureOffHeapPercentages(cache); registerJndiDataSources(cache); registerTransactionListeners(cache); registerTransactionWriter(cache);
@SuppressWarnings("unchecked") private void configureSerialization(CacheFactoryBean cacheFactoryBean, SessionSerializer sessionSerializer) { if (sessionSerializer instanceof DataSerializer) { if (sessionSerializer instanceof DataSerializableSessionSerializer) { DataSerializableSessionSerializer.register(); } else { DataSerializer.register(sessionSerializer.getClass()); } setUseDataSerialization(true); } else if (sessionSerializer instanceof PdxSerializer) { cacheFactoryBean.setPdxSerializer(ComposablePdxSerializer.compose( (PdxSerializer) sessionSerializer, cacheFactoryBean.getPdxSerializer())); } else { Optional.ofNullable(sessionSerializer) .filter(it -> !isDataSerializerSessionSerializerAdapterPresent()) .ifPresent(serializer -> cacheFactoryBean.setPdxSerializer(ComposablePdxSerializer.compose( new PdxSerializerSessionSerializerAdapter<>(sessionSerializer), cacheFactoryBean.getPdxSerializer())) ); } }
/** * Resolves the Pivotal GemFire/Apache Geode {@link Properties} used to configure the {@link Cache}. * * @return the resolved Pivotal GemFire/Apache Geode {@link Properties} used to configure the {@link Cache}. * @see #setAndGetProperties(Properties) * @see #getProperties() */ protected Properties resolveProperties() { return Optional.ofNullable(getProperties()).orElseGet(() -> setAndGetProperties(new Properties())); }
private void configureMemberName(CacheFactoryBean cacheFactoryBean) { getMemberName().ifPresent(memberName -> cacheFactoryBean.getProperties().setProperty(GEMFIRE_NAME_PROPERTY, memberName)); } }
/** * Configures Pivotal GemFire/Apache Geode cache PDX Serialization. * * @param cacheFactoryBean {@link CacheFactoryBean} instance on which to configure PDX. * with PDX de/serialization capabilities. * @see org.springframework.data.gemfire.CacheFactoryBean * @see <a href="http://gemfire.docs.pivotal.io/docs-gemfire/latest/developing/data_serialization/gemfire_pdx_serialization.html">GemFire PDX Serialization</a> */ protected void configurePdx(CacheFactoryBean cacheFactoryBean) { getDiskStoreName().ifPresent(cacheFactoryBean::setPdxDiskStoreName); cacheFactoryBean.setPdxIgnoreUnreadFields(isIgnoreUnreadFields()); cacheFactoryBean.setPdxPersistent(isPersistent()); cacheFactoryBean.setPdxReadSerialized(isReadSerialized()); cacheFactoryBean.setPdxSerializer(resolvePdxSerializer()); }
/** * Configures the {@link CacheFactoryBean} with common cache configuration settings. * * @param <T> {@link Class} specific sub-type of the {@link CacheFactoryBean}. * @param gemfireCache {@link CacheFactoryBean} to configure. * @return the given {@link CacheFactoryBean} with common cache configuration settings applied. * @see org.springframework.data.gemfire.client.ClientCacheFactoryBean * @see org.springframework.data.gemfire.CacheFactoryBean */ protected <T extends CacheFactoryBean> T configureCacheFactoryBean(T gemfireCache) { gemfireCache.setBeanClassLoader(getBeanClassLoader()); gemfireCache.setBeanFactory(getBeanFactory()); gemfireCache.setCacheXml(getCacheXml()); gemfireCache.setClose(isClose()); gemfireCache.setCopyOnRead(getCopyOnRead()); gemfireCache.setCriticalHeapPercentage(getCriticalHeapPercentage()); gemfireCache.setCriticalOffHeapPercentage(getCriticalOffHeapPercentage()); gemfireCache.setDynamicRegionSupport(getDynamicRegionSupport()); gemfireCache.setEvictionHeapPercentage(getEvictionHeapPercentage()); gemfireCache.setEvictionOffHeapPercentage(getEvictionOffHeapPercentage()); gemfireCache.setGatewayConflictResolver(getGatewayConflictResolver()); gemfireCache.setJndiDataSources(getJndiDataSources()); gemfireCache.setProperties(gemfireProperties()); gemfireCache.setTransactionListeners(getTransactionListeners()); gemfireCache.setTransactionWriter(getTransactionWriter()); return gemfireCache; }
/** * Resolves the {@link Cache} by first attempting to lookup an existing {@link Cache} instance in the JVM. * If an existing {@link Cache} could not be found, then this method proceeds in attempting to create * a new {@link Cache} instance. * * @param <T> parameterized {@link Class} type extension of {@link GemFireCache}. * @return the resolved {@link Cache} instance. * @see org.apache.geode.cache.Cache * @see #fetchCache() * @see #resolveProperties() * @see #createFactory(java.util.Properties) * @see #configureFactory(Object) * @see #createCache(Object) */ @SuppressWarnings("unchecked") protected <T extends GemFireCache> T resolveCache() { try { this.cacheResolutionMessagePrefix = "Found existing"; return (T) fetchCache(); } catch (CacheClosedException cause) { this.cacheResolutionMessagePrefix = "Created new"; initDynamicRegionFactory(); return (T) createCache(postProcess(configureFactory(initializeFactory(createFactory(resolveProperties()))))); } }
/** * Applies the composite {@link PeerCacheConfigurer PeerCacheConfigurers} to this {@link CacheFactoryBean} * before creating the {@link Cache peer Cache}. * * @see #getCompositePeerCacheConfigurer() * @see #applyPeerCacheConfigurers(PeerCacheConfigurer...) */ protected void applyCacheConfigurers() { PeerCacheConfigurer autoReconnectClusterConfigurationConfigurer = (beanName, cacheFactoryBean) -> { Properties gemfireProperties = resolveProperties(); gemfireProperties.setProperty("disable-auto-reconnect", String.valueOf(!Boolean.TRUE.equals(getEnableAutoReconnect()))); gemfireProperties.setProperty("use-cluster-configuration", String.valueOf(Boolean.TRUE.equals(getUseClusterConfiguration()))); }; this.peerCacheConfigurers.add(autoReconnectClusterConfigurationConfigurer); applyPeerCacheConfigurers(getCompositePeerCacheConfigurer()); }
/** * Destroys the {@link Cache} bean on Spring container shutdown. * * @throws Exception if an error occurs while closing the cache. * @see org.springframework.beans.factory.DisposableBean#destroy() * @see #destroyBeanFactoryLocator() * @see #close(GemFireCache) * @see #isClose() */ @Override public void destroy() throws Exception { if (isClose()) { close(fetchCache()); destroyBeanFactoryLocator(); } }
@Bean @Autowired public CacheFactoryBean gemfireCache(@Qualifier("gemfireProperties") Properties gemfireProperties) throws Exception { CacheFactoryBean cacheFactory = new CacheFactoryBean(); cacheFactory.setProperties(gemfireProperties); return cacheFactory; }
private void configureGemFireProperties(CacheFactoryBean bean) { bean.getProperties().putAll(this.gemfireProperties); } }
/** * Constructs a new instance of {@link CacheFactoryBean} used to create a peer {@link Cache}. * * @param <T> {@link Class} sub-type of {@link CacheFactoryBean}. * @return a new instance of {@link CacheFactoryBean}. * @see org.springframework.data.gemfire.CacheFactoryBean */ @Override @SuppressWarnings("unchecked") protected <T extends CacheFactoryBean> T newCacheFactoryBean() { return (T) new CacheFactoryBean(); }
/** * Applies the given array of {@link PeerCacheConfigurer PeerCacheConfigurers} to this {@link CacheFactoryBean}. * * @param peerCacheConfigurers array of {@link PeerCacheConfigurer PeerCacheConfigurers} applied to * this {@link CacheFactoryBean}. * @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer * @see #applyPeerCacheConfigurers(Iterable) */ protected void applyPeerCacheConfigurers(PeerCacheConfigurer... peerCacheConfigurers) { applyPeerCacheConfigurers(Arrays.asList(nullSafeArray(peerCacheConfigurers, PeerCacheConfigurer.class))); }
/** * Configures PDX for this peer {@link Cache} instance. * * @param cacheFactory {@link CacheFactory} used to configure the peer {@link Cache} with PDX. * @return the given {@link CacheFactory}. * @see org.apache.geode.cache.CacheFactory */ private CacheFactory configurePdx(CacheFactory cacheFactory) { Optional.ofNullable(getPdxSerializer()).ifPresent(cacheFactory::setPdxSerializer); Optional.ofNullable(getPdxDiskStoreName()).filter(StringUtils::hasText) .ifPresent(cacheFactory::setPdxDiskStore); Optional.ofNullable(getPdxIgnoreUnreadFields()).ifPresent(cacheFactory::setPdxIgnoreUnreadFields); Optional.ofNullable(getPdxPersistent()).ifPresent(cacheFactory::setPdxPersistent); Optional.ofNullable(getPdxReadSerialized()).ifPresent(cacheFactory::setPdxReadSerialized); return cacheFactory; }
protected <T extends GemFireCache> T postProcess(T cache) { loadCacheXml(cache); Optional.ofNullable(getCopyOnRead()).ifPresent(cache::setCopyOnRead); Optional.ofNullable(getGatewayConflictResolver()).ifPresent(((Cache) cache)::setGatewayConflictResolver); Optional.ofNullable(getLockLease()).ifPresent(((Cache) cache)::setLockLease); Optional.ofNullable(getLockTimeout()).ifPresent(((Cache) cache)::setLockTimeout); Optional.ofNullable(getMessageSyncInterval()).ifPresent(((Cache) cache)::setMessageSyncInterval); Optional.ofNullable(getSearchTimeout()).ifPresent(((Cache) cache)::setSearchTimeout); configureHeapPercentages(cache); configureOffHeapPercentages(cache); registerJndiDataSources(cache); registerTransactionListeners(cache); registerTransactionWriter(cache);