1
14
15 package com.liferay.portal.cache.ehcache;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.IPDetector;
20 import com.liferay.portal.kernel.util.OSDetector;
21 import com.liferay.portal.kernel.util.StringBundler;
22 import com.liferay.portal.kernel.util.StringPool;
23 import com.liferay.portal.kernel.util.Validator;
24
25 import java.util.Properties;
26
27 import net.sf.ehcache.CacheManager;
28 import net.sf.ehcache.distribution.CacheManagerPeerProvider;
29 import net.sf.ehcache.distribution.CacheManagerPeerProviderFactory;
30
31
41 public class JGroupsCacheManagerPeerProviderFactory
42 extends CacheManagerPeerProviderFactory {
43
44 public CacheManagerPeerProvider createCachePeerProvider(
45 CacheManager cacheManager, Properties properties) {
46
47 if (_log.isDebugEnabled()) {
48 _log.debug("Creating JGroups peer provider");
49 }
50
51 String clusterName = properties.getProperty("clusterName");
52
53 if (clusterName == null) {
54 clusterName = _DEFAULT_CLUSTER_NAME;
55 }
56
57 if (_log.isDebugEnabled()) {
58 _log.debug("Cluster name " + clusterName);
59 }
60
61 String channelProperties = properties.getProperty("channelProperties");
62
63 if (channelProperties != null) {
64 channelProperties = channelProperties.replaceAll(
65 StringPool.SPACE, StringPool.BLANK);
66
67 if (Validator.isNull(channelProperties)) {
68 channelProperties = null;
69 }
70 }
71
72 if (_log.isDebugEnabled()) {
73 _log.debug("Channel properties " + channelProperties);
74 }
75
76 if (!_initialized) {
77 if (OSDetector.isUnix() && IPDetector.isSupportsV6() &&
78 !IPDetector.isPrefersV4() && _log.isWarnEnabled()) {
79
80 StringBundler sb = new StringBundler(4);
81
82 sb.append(
83 "You are on an Unix server with IPv6 enabled. JGroups ");
84 sb.append("may not work with IPv6. If you see a multicast ");
85 sb.append("error, try adding java.net.preferIPv4Stack=true ");
86 sb.append("as a JVM startup parameter.");
87
88 _log.warn(sb.toString());
89 }
90
91 _initialized = true;
92 }
93
94 return new JGroupsManager(cacheManager, clusterName, channelProperties);
95 }
96
97 private static final String _DEFAULT_CLUSTER_NAME = "Ehcache";
98
99 private static Log _log = LogFactoryUtil.getLog(
100 JGroupsCacheManagerPeerProviderFactory.class);
101
102 private static boolean _initialized;
103
104 }