1 /**
2 * Copyright 2003-2006 Greg Luck
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.distribution;
18
19 import net.sf.ehcache.CacheException;
20 import net.sf.ehcache.CacheManager;
21 import net.sf.ehcache.util.PropertyUtil;
22
23 import java.net.UnknownHostException;
24 import java.util.Properties;
25
26 /**
27 * Builds a listener based on RMI.
28 * <p/>
29 * Expected configuration line:
30 * <p/>
31 * <code>
32 * <cachePeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
33 * properties="hostName=localhost, port=5000" />
34 * </code>
35 * @author Greg Luck
36 * @version $Id: RMICacheManagerPeerListenerFactory.java 52 2006-04-24 14:50:03Z gregluck $
37 */
38 public final class RMICacheManagerPeerListenerFactory extends CacheManagerPeerListenerFactory {
39
40 /**
41 * The default timeout for cache replication for a single replication action.
42 * This may need to be increased for large data transfers.
43 */
44 public static final Integer DEFAULT_SOCKET_TIMEOUT_MILLIS = new Integer(120000);
45
46 private static final String HOSTNAME = "hostName";
47 private static final String PORT = "port";
48 private static final String SOCKET_TIMEOUT_MILLIS = "socketTimeoutMillis";
49
50 /**
51 * @param properties implementation specific properties. These are configured as comma
52 * separated name value pairs in ehcache.xml
53 */
54 public final CacheManagerPeerListener createCachePeerListener(CacheManager cacheManager, Properties properties)
55 throws CacheException {
56 String hostName = PropertyUtil.extractAndLogProperty(HOSTNAME, properties);
57 String portString = PropertyUtil.extractAndLogProperty(PORT, properties);
58 Integer port = new Integer(portString);
59 String socketTimeoutMillisString = PropertyUtil.extractAndLogProperty(SOCKET_TIMEOUT_MILLIS, properties);
60 Integer socketTimeoutMillis;
61 if (socketTimeoutMillisString == null || socketTimeoutMillisString.length() == 0) {
62 socketTimeoutMillis = DEFAULT_SOCKET_TIMEOUT_MILLIS;
63 } else {
64 socketTimeoutMillis = new Integer(socketTimeoutMillisString);
65 }
66 try {
67 return new RMICacheManagerPeerListener(hostName, port, cacheManager, socketTimeoutMillis);
68 } catch (UnknownHostException e) {
69 throw new CacheException("Unable to create CacheManagerPeerListener. Initial cause was " + e.getMessage(), e);
70 }
71 }
72 }