Esempio n. 1
0
 private static float getSpeedAdjustmentFactor() {
   final String speedAdjustmentFactorString =
       PropertyUtil.extractAndLogProperty(
           "net.sf.ehcache.speedAdjustmentFactor", System.getProperties());
   if (speedAdjustmentFactorString != null) {
     return Float.parseFloat(speedAdjustmentFactorString);
   } else {
     return 1;
   }
 }
Esempio n. 2
0
 /**
  * Extract a Boolean out of a Property
  *
  * @param properties the properties
  * @param propertyName the name of the property
  * @param defaultValue the deulat value id none is found
  * @return the extracted property
  */
 protected boolean extractBooleanProperty(
     Properties properties, String propertyName, boolean defaultValue) {
   boolean ret;
   String pString = PropertyUtil.extractAndLogProperty(propertyName, properties);
   if (pString != null) {
     ret = PropertyUtil.parseBoolean(pString);
   } else {
     ret = defaultValue;
   }
   return ret;
 }
Esempio n. 3
0
  /**
   * peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446,
   * multicastPacketTimeToLive=255
   */
  protected CacheManagerPeerProvider createAutomaticallyConfiguredCachePeerProvider(
      CacheManager cacheManager, Properties properties) throws IOException {
    String hostName = PropertyUtil.extractAndLogProperty(HOST_NAME, properties);
    InetAddress hostAddress = null;
    if (hostName != null && hostName.length() != 0) {
      hostAddress = InetAddress.getByName(hostName);
      if (hostName.equals("localhost")) {
        LOG.log(
            Level.WARNING,
            "Explicitly setting the multicast hostname to 'localhost' is not recommended. "
                + "It will only work if all CacheManager peers are on the same machine.");
      }
    }

    String groupAddressString =
        PropertyUtil.extractAndLogProperty(MULTICAST_GROUP_ADDRESS, properties);
    InetAddress groupAddress = InetAddress.getByName(groupAddressString);
    String multicastPortString =
        PropertyUtil.extractAndLogProperty(MULTICAST_GROUP_PORT, properties);
    Integer multicastPort = new Integer(multicastPortString);
    String packetTimeToLiveString =
        PropertyUtil.extractAndLogProperty(MULTICAST_PACKET_TTL, properties);
    Integer timeToLive;
    if (packetTimeToLiveString == null) {
      timeToLive = new Integer(1);
      LOG.log(
          Level.FINE,
          "No TTL set. Setting it to the default of 1, which means packets are limited to the same subnet.");
    } else {
      timeToLive = new Integer(packetTimeToLiveString);
      if (timeToLive.intValue() < 0 || timeToLive.intValue() > MAXIMUM_TTL) {
        throw new CacheException("The TTL must be set to a value between 0 and 255");
      }
    }
    return new MulticastRMICacheManagerPeerProvider(
        cacheManager, groupAddress, multicastPort, timeToLive, hostAddress);
  }
Esempio n. 4
0
 /**
  * @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;
   }
 }
Esempio n. 5
0
  /**
   * Extract a long out of a string.
   *
   * @param properties the property
   * @param propertyName the name of the property
   * @param defaultValue the default value if none is found
   * @return the extracted value
   */
  protected long extractAsynchronousReplicationIntervalMillis(
      Properties properties, String propertyName, long defaultValue) {
    String parsedString = PropertyUtil.extractAndLogProperty(propertyName, properties);
    if (parsedString != null) {

      try {
        Long longValue = new Long(parsedString);
        return longValue.longValue();
      } catch (NumberFormatException e) {
        LOG.warn(
            "Number format exception trying to set asynchronousReplicationIntervalMillis. "
                + "Using the default instead. String value was: '"
                + parsedString
                + "'");
      }
    }
    return defaultValue;
  }
Esempio n. 6
0
 /**
  * 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.log(
         Level.INFO,
         "Starting manual peer provider with empty list of peers. "
             + "No replication will occur unless peers are added.");
     rmiUrls = new String();
   }
   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);
     if (LOG.isLoggable(Level.FINE)) {
       LOG.log(Level.FINE, "Registering peer " + rmiUrl);
     }
   }
   return rmiPeerProvider;
 }