/** * Extracts the value of replicateRemovals from the properties * @param properties */ protected boolean extractReplicateRemovals(Properties properties) { boolean replicateRemovals; String replicateRemovalsString = PropertyUtil.extractAndLogProperty(REPLICATE_REMOVALS, properties); if (replicateRemovalsString != null) { replicateRemovals = PropertyUtil.parseBoolean(replicateRemovalsString); } else { replicateRemovals = true; } return replicateRemovals; }
/** * Tries to load the class specified. * * @return If there is none returns null. * @param cacheManager */ public final CacheManagerEventListener createCacheManagerEventListener(CacheManager cacheManager) throws CacheException { String className = null; FactoryConfiguration cacheManagerEventListenerFactoryConfiguration = configuration.getCacheManagerEventListenerFactoryConfiguration(); if (cacheManagerEventListenerFactoryConfiguration != null) { className = cacheManagerEventListenerFactoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No CacheManagerEventListenerFactory class specified. Skipping..."); return null; } else { CacheManagerEventListenerFactory factory = (CacheManagerEventListenerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(cacheManagerEventListenerFactoryConfiguration.properties, cacheManagerEventListenerFactoryConfiguration.getPropertySeparator()); return factory.createCacheManagerEventListener(cacheManager, properties); } }
/** * Will retrieve the boolean value from the properties, defaulting if property isn't present * @param properties the properties to use * @param prop the property name to look for * @param defaultValue the default value if property is missing * @return the value, or it's default, for the property */ protected long extractLong(final Properties properties, final String prop, final long defaultValue) { long value; String propString = PropertyUtil.extractAndLogProperty(prop, properties); if (propString != null) { value = Long.parseLong(propString); } else { value = defaultValue; } return value; } }
/** * Some caches might be persistent, so we want to add a shutdown hook if that is the * case, so that the data and index can be written to disk. */ private void addShutdownHookIfRequired() { String shutdownHookProperty = System.getProperty(ENABLE_SHUTDOWN_HOOK_PROPERTY); boolean enabled = PropertyUtil.parseBoolean(shutdownHookProperty); if (!enabled) { return; } else { LOG.info("The CacheManager shutdown hook is enabled because {} is set to true.", ENABLE_SHUTDOWN_HOOK_PROPERTY); Thread localShutdownHook = new Thread() { @Override public void run() { synchronized (this) { if (status.equals(Status.STATUS_ALIVE)) { // clear shutdown hook reference to prevent // removeShutdownHook to remove it during shutdown shutdownHook = null; LOG.info("VM shutting down with the CacheManager still active. Calling shutdown."); shutdown(); } } } }; Runtime.getRuntime().addShutdownHook(localShutdownHook); shutdownHook = localShutdownHook; } }
/** * Extracts the value of maximumBatchSize. Sets it to 1024 if * either not set or there is a problem parsing the number * @param properties */ protected int extractMaximumBatchSize(Properties properties) { String maximumBatchSizeString = PropertyUtil.extractAndLogProperty(ASYNCHRONOUS_REPLICATION_MAXIMUM_BATCH_SIZE, properties); if (maximumBatchSizeString == null) { return DEFAULT_ASYNCHRONOUS_REPLICATION_MAXIMUM_BATCH_SIZE; } else { try { return Integer.parseInt(maximumBatchSizeString); } catch (NumberFormatException e) { LOG.warn("Number format exception trying to set maximumBatchSize. " + "Using the default instead. String value was: '" + maximumBatchSizeString + "'"); return DEFAULT_ASYNCHRONOUS_REPLICATION_MAXIMUM_BATCH_SIZE; } } }
/** * Extracts the value of replicatePutsViaCopy from the properties * @param properties */ protected boolean extractReplicatePutsViaCopy(Properties properties) { boolean replicatePutsViaCopy; String replicatePutsViaCopyString = PropertyUtil.extractAndLogProperty(REPLICATE_PUTS_VIA_COPY, properties); if (replicatePutsViaCopyString != null) { replicatePutsViaCopy = PropertyUtil.parseBoolean(replicatePutsViaCopyString); } else { replicatePutsViaCopy = true; } return replicatePutsViaCopy; }
/** * Tries to create a CacheLoader from the configuration using the factory * specified. * * @return The CacheExceptionHandler, or null if it could not be found. */ public static CacheExceptionHandler createCacheExceptionHandler( CacheConfiguration.CacheExceptionHandlerFactoryConfiguration factoryConfiguration, ClassLoader loader) throws CacheException { String className = null; CacheExceptionHandler cacheExceptionHandler = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No CacheExceptionHandlerFactory class specified. Skipping..."); } else { CacheExceptionHandlerFactory factory = (CacheExceptionHandlerFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); return factory.createExceptionHandler(properties); } return cacheExceptionHandler; }
/** * * @param properties the properties passed by the CacheManager, read from the configuration file * @return the max chunk size in bytes */ protected int extractMaximumChunkSizeBytes(Properties properties) { int maximumChunkSizeBytes; String maximumChunkSizeBytesString = PropertyUtil.extractAndLogProperty(MAXIMUM_CHUNK_SIZE_BYTES, properties); if (maximumChunkSizeBytesString != null) { try { int maximumChunkSizeBytesCandidate = Integer.parseInt(maximumChunkSizeBytesString); if ((maximumChunkSizeBytesCandidate < FIVE_KB) || (maximumChunkSizeBytesCandidate > ONE_HUNDRED_MB)) { LOG.warn("Trying to set the chunk size to an unreasonable number. Using the default instead."); maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES; } else { maximumChunkSizeBytes = maximumChunkSizeBytesCandidate; } } catch (NumberFormatException e) { LOG.warn("Number format exception trying to set chunk size. Using the default instead."); maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES; } } else { maximumChunkSizeBytes = DEFAULT_MAXIMUM_CHUNK_SIZE_BYTES; } return maximumChunkSizeBytes; }
/** * Extracts the value of replicateUpdatesViaCopy from the properties * @param properties */ protected boolean extractReplicateUpdatesViaCopy(Properties properties) { boolean replicateUpdatesViaCopy; String replicateUpdatesViaCopyString = PropertyUtil.extractAndLogProperty(REPLICATE_UPDATES_VIA_COPY, properties); if (replicateUpdatesViaCopyString != null) { replicateUpdatesViaCopy = PropertyUtil.parseBoolean(replicateUpdatesViaCopyString); } else { replicateUpdatesViaCopy = true; } return replicateUpdatesViaCopy; }
/** * Tries to load a BootstrapCacheLoader from the class specified. * @param loader * * @return If there is none returns null. */ private static final BootstrapCacheLoader createBootstrapCacheLoader( CacheConfiguration.BootstrapCacheLoaderFactoryConfiguration factoryConfiguration, ClassLoader loader) throws CacheException { String className = null; BootstrapCacheLoader bootstrapCacheLoader = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null || className.length() == 0) { LOG.debug("No BootstrapCacheLoaderFactory class specified. Skipping..."); } else { BootstrapCacheLoaderFactory factory = (BootstrapCacheLoaderFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); return factory.createBootstrapCacheLoader(properties); } return bootstrapCacheLoader; }
/** * Extracts the value of asynchronousReplicationIntervalMillis. Sets it to 1000ms if * either not set or there is a problem parsing the number * @param properties */ protected int extractReplicationIntervalMilis(Properties properties) { int asynchronousReplicationIntervalMillis; String asynchronousReplicationIntervalMillisString = PropertyUtil.extractAndLogProperty(ASYNCHRONOUS_REPLICATION_INTERVAL_MILLIS, properties); if (asynchronousReplicationIntervalMillisString != null) { try { int asynchronousReplicationIntervalMillisCandidate = Integer.parseInt(asynchronousReplicationIntervalMillisString); if (asynchronousReplicationIntervalMillisCandidate < MINIMUM_REASONABLE_INTERVAL) { LOG.debug("Trying to set the asynchronousReplicationIntervalMillis to an unreasonable number." + " Using the default instead."); asynchronousReplicationIntervalMillis = DEFAULT_ASYNCHRONOUS_REPLICATION_INTERVAL_MILLIS; } else { asynchronousReplicationIntervalMillis = asynchronousReplicationIntervalMillisCandidate; } } catch (NumberFormatException e) { LOG.warn("Number format exception trying to set asynchronousReplicationIntervalMillis. " + "Using the default instead. String value was: '" + asynchronousReplicationIntervalMillisString + "'"); asynchronousReplicationIntervalMillis = DEFAULT_ASYNCHRONOUS_REPLICATION_INTERVAL_MILLIS; } } else { asynchronousReplicationIntervalMillis = DEFAULT_ASYNCHRONOUS_REPLICATION_INTERVAL_MILLIS; } return asynchronousReplicationIntervalMillis; }
/** * Extracts the value of replicatePuts from the properties * @param properties */ protected boolean extractReplicatePuts(Properties properties) { boolean replicatePuts; String replicatePutsString = PropertyUtil.extractAndLogProperty(REPLICATE_PUTS, properties); if (replicatePutsString != null) { replicatePuts = PropertyUtil.parseBoolean(replicatePutsString); } else { replicatePuts = true; } return replicatePuts; }
/** * Tries to load the class specified otherwise defaults to null. * * @param factoryConfiguration * @param loader */ private static CacheExtension createCacheExtension( CacheConfiguration.CacheExtensionFactoryConfiguration factoryConfiguration, Ehcache cache, ClassLoader loader) { String className = null; CacheExtension cacheExtension = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("CacheExtension factory not configured. Skipping..."); } else { CacheExtensionFactory factory = (CacheExtensionFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); cacheExtension = factory.createCacheExtension(cache, properties); } return cacheExtension; }
String hostName = PropertyUtil.extractAndLogProperty(HOSTNAME, properties); String portString = PropertyUtil.extractAndLogProperty(PORT, properties); Integer port = null; if (portString != null && portString.length() != 0) { String remoteObjectPortString = PropertyUtil.extractAndLogProperty(REMOTE_OBJECT_PORT, properties); Integer remoteObjectPort = null; if (remoteObjectPortString != null && remoteObjectPortString.length() != 0) { String socketTimeoutMillisString = PropertyUtil.extractAndLogProperty(SOCKET_TIMEOUT_MILLIS, properties); Integer socketTimeoutMillis; if (socketTimeoutMillisString == null || socketTimeoutMillisString.length() == 0) {
/** * Extracts the value of replicateAsynchronously from the properties * @param properties */ protected boolean extractReplicateAsynchronously(Properties properties) { boolean replicateAsynchronously; String replicateAsynchronouslyString = PropertyUtil.extractAndLogProperty(REPLICATE_ASYNCHRONOUSLY, properties); if (replicateAsynchronouslyString != null) { replicateAsynchronously = PropertyUtil.parseBoolean(replicateAsynchronouslyString); } else { replicateAsynchronously = true; } return replicateAsynchronously; }
/** * Tries to load the class specified otherwise defaults to null. * * @param factoryConfiguration * @param loader */ private static CacheLoader createCacheLoader( CacheConfiguration.CacheLoaderFactoryConfiguration factoryConfiguration, Ehcache cache, ClassLoader loader) { String className = null; CacheLoader cacheLoader = null; if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (className == null) { LOG.debug("CacheLoader factory not configured. Skipping..."); } else { CacheLoaderFactory factory = (CacheLoaderFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); cacheLoader = factory.createCacheLoader(cache, properties); } return cacheLoader; }
String hostName = PropertyUtil.extractAndLogProperty(HOST_NAME, properties); InetAddress hostAddress = null; if (hostName != null && hostName.length() != 0) { String groupAddressString = PropertyUtil.extractAndLogProperty(MULTICAST_GROUP_ADDRESS, properties); InetAddress groupAddress = InetAddress.getByName(groupAddressString); String multicastPortString = PropertyUtil.extractAndLogProperty(MULTICAST_GROUP_PORT, properties); Integer multicastPort = Integer.valueOf(multicastPortString); String packetTimeToLiveString = PropertyUtil.extractAndLogProperty(MULTICAST_PACKET_TTL, properties); Integer timeToLive; if (packetTimeToLiveString == null) {
/** * Extracts the value of replicateUpdates from the properties * @param properties */ protected boolean extractReplicateUpdates(Properties properties) { boolean replicateUpdates; String replicateUpdatesString = PropertyUtil.extractAndLogProperty(REPLICATE_UPDATES, properties); if (replicateUpdatesString != null) { replicateUpdates = PropertyUtil.parseBoolean(replicateUpdatesString); } else { replicateUpdates = true; } return replicateUpdates; }
/** * Tries to load the class specified otherwise defaults to null. * * @param config * @param loader */ private static CacheWriter createCacheWriter(CacheWriterConfiguration config, Ehcache cache, ClassLoader loader) { String className = null; CacheWriter cacheWriter = null; CacheWriterConfiguration.CacheWriterFactoryConfiguration factoryConfiguration = config.getCacheWriterFactoryConfiguration(); if (factoryConfiguration != null) { className = factoryConfiguration.getFullyQualifiedClassPath(); } if (null == className) { LOG.debug("CacheWriter factory not configured. Skipping..."); } else { CacheWriterFactory factory = (CacheWriterFactory) ClassLoaderUtil.createNewInstance(loader, className); Properties properties = PropertyUtil.parseProperties(factoryConfiguration.getProperties(), factoryConfiguration.getPropertySeparator()); if (null == properties) { properties = new Properties(); } cacheWriter = factory.createCacheWriter(cache, properties); } return cacheWriter; }
/** * peerDiscovery=manual, rmiUrls=//hostname:port/cacheName //hostname:port/cacheName //hostname:port/cacheName */ protected CacheManagerPeerProvider createManuallyConfiguredCachePeerProvider(Properties properties) { String rmiUrls = PropertyUtil.extractAndLogProperty(RMI_URLS, properties); if (rmiUrls == null || rmiUrls.length() == 0) { LOG.info("Starting manual peer provider with empty list of peers. " + "No replication will occur unless peers are added."); rmiUrls = ""; } rmiUrls = rmiUrls.trim(); StringTokenizer stringTokenizer = new StringTokenizer(rmiUrls, PayloadUtil.URL_DELIMITER); RMICacheManagerPeerProvider rmiPeerProvider = new ManualRMICacheManagerPeerProvider(); while (stringTokenizer.hasMoreTokens()) { String rmiUrl = stringTokenizer.nextToken(); rmiUrl = rmiUrl.trim(); rmiPeerProvider.registerPeer(rmiUrl); LOG.debug("Registering peer {}", rmiUrl); } return rmiPeerProvider; }