List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:org.springframework.core.env.AbstractEnvironment.java
@Override public void merge(ConfigurableEnvironment parent) { for (PropertySource<?> ps : parent.getPropertySources()) { if (!this.propertySources.contains(ps.getName())) { this.propertySources.addLast(ps); }//from ww w . j a va 2 s . c om } String[] parentActiveProfiles = parent.getActiveProfiles(); if (!ObjectUtils.isEmpty(parentActiveProfiles)) { synchronized (this.activeProfiles) { for (String profile : parentActiveProfiles) { this.activeProfiles.add(profile); } } } String[] parentDefaultProfiles = parent.getDefaultProfiles(); if (!ObjectUtils.isEmpty(parentDefaultProfiles)) { synchronized (this.defaultProfiles) { this.defaultProfiles.remove(RESERVED_DEFAULT_PROFILE_NAME); for (String profile : parentDefaultProfiles) { this.defaultProfiles.add(profile); } } } }
From source file:org.springframework.data.gemfire.client.ClientRegionFactoryBean.java
@Override protected Region<K, V> lookupFallback(GemFireCache cache, String regionName) throws Exception { Assert.isTrue(cache instanceof ClientCache, "Unable to create regions from " + cache); ClientCache c = (ClientCache) cache; // first look at shortcut ClientRegionShortcut s = null;//from w w w . ja v a 2s . c om if (shortcut == null) { if (dataPolicy != null) { if (DataPolicy.EMPTY.equals(dataPolicy)) { s = ClientRegionShortcut.PROXY; } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy)) { s = ClientRegionShortcut.LOCAL_PERSISTENT; } } s = ClientRegionShortcut.LOCAL; } ClientRegionFactory<K, V> factory = c.createClientRegionFactory(s); // map the attributes onto the client if (attributes != null) { CacheListener<K, V>[] listeners = attributes.getCacheListeners(); if (!ObjectUtils.isEmpty(listeners)) { for (CacheListener<K, V> listener : listeners) { factory.addCacheListener(listener); } } factory.setCloningEnabled(attributes.getCloningEnabled()); factory.setConcurrencyLevel(attributes.getConcurrencyLevel()); factory.setCustomEntryIdleTimeout(attributes.getCustomEntryIdleTimeout()); factory.setCustomEntryTimeToLive(attributes.getCustomEntryTimeToLive()); factory.setDiskStoreName(attributes.getDiskStoreName()); factory.setDiskSynchronous(attributes.isDiskSynchronous()); factory.setEntryIdleTimeout(attributes.getEntryIdleTimeout()); factory.setEntryTimeToLive(attributes.getEntryTimeToLive()); factory.setEvictionAttributes(attributes.getEvictionAttributes()); factory.setInitialCapacity(attributes.getInitialCapacity()); factory.setKeyConstraint(attributes.getKeyConstraint()); factory.setLoadFactor(attributes.getLoadFactor()); factory.setPoolName(attributes.getPoolName()); factory.setRegionIdleTimeout(attributes.getRegionIdleTimeout()); factory.setRegionTimeToLive(attributes.getRegionTimeToLive()); factory.setStatisticsEnabled(attributes.getStatisticsEnabled()); factory.setValueConstraint(attributes.getValueConstraint()); } if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener<K, V> listener : cacheListeners) { factory.addCacheListener(listener); } } if (StringUtils.hasText(poolName)) { // try to eagerly initialize the pool name, if defined as a bean if (beanFactory.isTypeMatch(poolName, Pool.class)) { if (log.isDebugEnabled()) { log.debug("Found bean definition for pool '" + poolName + "'. Eagerly initializing it..."); } beanFactory.getBean(poolName, Pool.class); } factory.setPoolName(poolName); } Region<K, V> reg = factory.create(regionName); log.info("Created new cache region [" + regionName + "]"); if (snapshot != null) { reg.loadSnapshot(snapshot.getInputStream()); } return reg; }
From source file:org.springframework.data.gemfire.client.ClientRegionFactoryBean.java
protected void postProcess(Region<K, V> region) { if (!ObjectUtils.isEmpty(interests)) { for (Interest<K> interest : interests) { if (interest instanceof RegexInterest) { // do the cast since it's safe region.registerInterestRegex((String) interest.getKey(), interest.getPolicy(), interest.isDurable(), interest.isReceiveValues()); } else { region.registerInterest(interest.getKey(), interest.getPolicy(), interest.isDurable(), interest.isReceiveValues()); }//from w w w . j a v a 2 s . co m } } }
From source file:org.springframework.data.gemfire.client.ClientRegionFactoryBean.java
public void destroy() throws Exception { Region<K, V> region = getObject(); // unregister interests try {/* w ww . j av a 2s . co m*/ if (region != null && !ObjectUtils.isEmpty(interests)) { for (Interest<K> interest : interests) { if (interest instanceof RegexInterest) { region.unregisterInterestRegex((String) interest.getKey()); } else { region.unregisterInterest(interest.getKey()); } } } // should not really happen since interests are validated at start/registration } catch (UnsupportedOperationException ex) { log.warn("Cannot unregister cache interests", ex); } if (region != null) { if (close) { if (!region.getCache().isClosed()) { try { region.close(); } catch (CacheClosedException cce) { // nothing to see folks, move on. } } } else if (destroy) { region.destroyRegion(); } } region = null; }
From source file:org.springframework.data.gemfire.RegionFactoryBean.java
@Override protected Region<K, V> lookupFallback(GemFireCache cache, String regionName) throws Exception { Assert.isTrue(cache instanceof Cache, "Unable to create regions from " + cache); Cache c = (Cache) cache;/*from w w w. ja v a2 s. c o m*/ if (attributes != null) AttributesFactory.validateAttributes(attributes); final RegionFactory<K, V> regionFactory = (attributes != null ? c.createRegionFactory(attributes) : c.<K, V>createRegionFactory()); if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener<K, V> listener : cacheListeners) { regionFactory.addCacheListener(listener); } } if (cacheLoader != null) { regionFactory.setCacheLoader(cacheLoader); } if (cacheWriter != null) { regionFactory.setCacheWriter(cacheWriter); } if (dataPolicy != null) { regionFactory.setDataPolicy(dataPolicy); } if (scope != null) { regionFactory.setScope(scope); } // get underlying AttributesFactory postProcess(findAttrFactory(regionFactory)); Region<K, V> reg = regionFactory.create(regionName); log.info("Created new cache region [" + regionName + "]"); if (snapshot != null) { reg.loadSnapshot(snapshot.getInputStream()); } return reg; }
From source file:org.springframework.data.gemfire.snapshot.SnapshotServiceFactoryBean.java
/** * Resolves the SnapshotMetadata used to perform the GemFire Cache or Region data snapshot import/export. * If the event contains specific SnapshotMetadata, then this is preferred over the factory's own * "import" or "export" SnapshotMetadata. * * @param event the SnapshotApplicationEvent from which to resolve the SnapshotMetadata. * @return the resolved SnapshotMetadata, either from the event or this factory's configured imports/exports. * @see SnapshotApplicationEvent#getSnapshotMetadata() * @see #getExports()/* w w w. j a v a 2 s. com*/ * @see #getImports() */ protected SnapshotMetadata<K, V>[] resolveSnapshotMetadata(SnapshotApplicationEvent<K, V> event) { SnapshotMetadata<K, V>[] eventSnapshotMetadata = event.getSnapshotMetadata(); return (!ObjectUtils.isEmpty(eventSnapshotMetadata) ? eventSnapshotMetadata : (event instanceof ExportSnapshotApplicationEvent ? getExports() : getImports())); }
From source file:org.springframework.data.gemfire.SubRegionFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(parentRegion, "The parent Region cannot be null."); this.subRegion = parentRegion.getSubregion(regionName); if (this.subRegion == null) { if (lookupOnly) { throw new BeanInitializationException(String.format("Cannot find Region [%1$s] in Cache %2$s", regionName, parentRegion.getRegionService())); } else {/*from w ww. j ava2 s .co m*/ log.debug(String.format("Creating sub-Region of [%1$s] with name [%2$s]...", (parentRegion.getFullPath() != null ? parentRegion.getFullPath() : parentRegion.getName()), regionName)); if (!ObjectUtils.isEmpty(asyncEventQueues)) { for (Object asyncEventQueue : asyncEventQueues) { addAsyncEventQueueId(((AsyncEventQueue) asyncEventQueue).getId()); } } if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener<K, V> listener : cacheListeners) { addCacheListener(listener); } } if (!ObjectUtils.isEmpty(gatewaySenders)) { for (Object gatewaySender : gatewaySenders) { addGatewaySenderId(((GatewaySender) gatewaySender).getId()); } } this.subRegion = this.parentRegion.createSubregion(regionName, create()); } } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
/** * Creates (constructs and configures) an instance of the ConfigurableApplicationContext based on either the * specified base packages containing @Configuration, @Component or JSR 330 annotated classes to scan, or the * specified locations of context configuration meta-data files. The created ConfigurableApplicationContext * is not automatically "refreshed" and therefore must be "refreshed" by the caller manually. * * When basePackages are specified, an instance of AnnotationConfigApplicationContext is constructed and a scan * is performed; otherwise an instance of the ClassPathXmlApplicationContext is initialized with the * configLocations. This method prefers the ClassPathXmlApplicationContext to the * AnnotationConfigApplicationContext when both basePackages and configLocations are specified. * * @param basePackages the base packages to scan for application @Components and @Configuration classes. * @param configLocations a String array indicating the locations of the context configuration meta-data files * used to configure the ClassPathXmlApplicationContext instance. * @return an instance of ConfigurableApplicationContext configured and initialized with either configLocations * or the basePackages when configLocations is unspecified. Note, the "refresh" method must be called manually * before using the context.//w w w .j a v a 2 s . c o m * @throws IllegalArgumentException if both the basePackages and configLocation parameter arguments * are null or empty. * @see #createApplicationContext(String[]) * @see org.springframework.context.annotation.AnnotationConfigApplicationContext * @see org.springframework.context.annotation.AnnotationConfigApplicationContext#scan(String...) * @see org.springframework.context.support.ClassPathXmlApplicationContext */ protected ConfigurableApplicationContext createApplicationContext(String[] basePackages, String[] configLocations) { if (!ObjectUtils.isEmpty(configLocations)) { return createApplicationContext(configLocations); } else { Assert.isTrue(isConfigurable(basePackages, configLocations, registeredAnnotatedClasses), "'basePackages', 'configLocations' or 'AnnotatedClasses' must be specified in order to" + " construct and configure an instance of the ConfigurableApplicationContext"); return scanBasePackages( registerAnnotatedClasses((AnnotationConfigApplicationContext) createApplicationContext(null), registeredAnnotatedClasses.toArray(new Class<?>[registeredAnnotatedClasses.size()])), basePackages); } }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
ConfigurableApplicationContext createApplicationContext(String[] configLocations) { return (ObjectUtils.isEmpty(configLocations) ? new AnnotationConfigApplicationContext() : new ClassPathXmlApplicationContext(configLocations, false)); }
From source file:org.springframework.data.gemfire.support.SpringContextBootstrappingInitializer.java
private boolean isConfigurable(String[] basePackages, String[] contextConfigLocations, Collection<Class<?>> annotatedClasses) { return !(ObjectUtils.isEmpty(basePackages) && ObjectUtils.isEmpty(contextConfigLocations) && CollectionUtils.isEmpty(annotatedClasses)); }