/** * 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; } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * * @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 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; }
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) {
/** * 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 boolean extractBoolean(final Properties properties, final String prop, final boolean defaultValue) { boolean value; String propString = PropertyUtil.extractAndLogProperty(prop, properties); if (propString != null) { value = PropertyUtil.parseBoolean(propString); } else { value = defaultValue; } return value; }
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) {
/** * 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; }
/** * @param properties implementation specific properties. These are configured as comma * separated name value pairs in ehcache.xml */ public CacheManagerPeerProvider createCachePeerProvider(CacheManager cacheManager, Properties properties) throws CacheException { String peerDiscovery = PropertyUtil.extractAndLogProperty(PEER_DISCOVERY, properties); if (peerDiscovery == null || peerDiscovery.equalsIgnoreCase(AUTOMATIC_PEER_DISCOVERY)) { try { return createAutomaticallyConfiguredCachePeerProvider(cacheManager, properties); } catch (IOException e) { throw new CacheException("Could not create CacheManagerPeerProvider. Initial cause was " + e.getMessage(), e); } } else if (peerDiscovery.equalsIgnoreCase(MANUALLY_CONFIGURED_PEER_DISCOVERY)) { return createManuallyConfiguredCachePeerProvider(properties); } else { return null; } }
@Override public TerracottaBootstrapCacheLoader createBootstrapCacheLoader(final Properties properties) { final boolean asynchronous = extractBootstrapAsynchronously(properties); TerracottaBootstrapCacheLoader cacheLoader; final String directory = PropertyUtil.extractAndLogProperty("directory", properties); if (extractBoolean(properties, "doKeySnapshot", true)) { cacheLoader = new TerracottaBootstrapCacheLoader(asynchronous, directory, extractLong(properties, "interval", TerracottaBootstrapCacheLoader.DEFAULT_INTERVAL), extractBoolean(properties, "useDedicatedThread", TerracottaBootstrapCacheLoader.DEFAULT_DEDICATED_THREAD) ); } else { cacheLoader = new TerracottaBootstrapCacheLoader(asynchronous, directory, false); } cacheLoader.setImmediateShutdown(extractBoolean(properties, "immediateShutdown", true)); cacheLoader.setSnapshotOnDispose(extractBoolean(properties, "doKeySnapshotOnDispose", false)); return cacheLoader; }
/** * Extracts the value of bootstrapAsynchronously from the properties */ protected boolean extractAndValidateBootstrapAsynchronously(Properties properties) { String bootstrapAsynchronouslyString = PropertyUtil.extractAndLogProperty(BOOTSTRAP_ASYNCHRONOUSLY, properties); if (bootstrapAsynchronouslyString != null) { return Boolean.parseBoolean(bootstrapAsynchronouslyString); } return true; } }
private String getProperty(final String name, Properties properties) { String property = PropertyUtil.extractAndLogProperty(name, properties); if (property != null) { property = property.trim(); property = property.replaceAll(" ", ""); if (property.equals("")) { property = null; } } return property; }
private static boolean extractBoolean(final String key, final Properties properties) { String booleanString = PropertyUtil.extractAndLogProperty(key, properties); return booleanString == null || PropertyUtil.parseBoolean(booleanString); // defaults to true }
@Override public CacheManagerPeerProvider createCachePeerProvider(CacheManager cacheManager, Properties properties) throws CacheException { final String peerDiscovery = PropertyUtil.extractAndLogProperty(PEER_DISCOVERY, properties); LOG.info(" Starting Jira instance with {} cache replication strategy", (peerDiscovery == null ? "default" : peerDiscovery)); if (peerDiscovery == null || StringUtils.equalsIgnoreCase(peerDiscovery, "default")) { return new JiraCacheManagerPeerProvider(cacheManager); } return super.createCachePeerProvider(cacheManager, properties); }