001
014
015 package com.liferay.portal.cache.bootstrap;
016
017 import com.liferay.portal.kernel.cache.BootstrapLoader;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021
022 import java.util.Properties;
023
024
027 public class ClusterLinkBootstrapLoader implements BootstrapLoader {
028
029 public ClusterLinkBootstrapLoader(Properties properties) {
030 if (properties != null) {
031 _bootstrapAsynchronously = GetterUtil.getBoolean(
032 properties.getProperty("bootstrapAsynchronously"));
033 }
034 else {
035 _bootstrapAsynchronously = true;
036 }
037 }
038
039 @Override
040 public boolean isAsynchronous() {
041 return _bootstrapAsynchronously;
042 }
043
044 @Override
045 public void load(String portalCacheManagerName, String portalCacheName) {
046 if (ClusterLinkBootstrapLoaderHelperUtil.isSkipped()) {
047 return;
048 }
049
050 if (_bootstrapAsynchronously) {
051 BootstrapLoaderClientThread bootstrapLoaderClientThread =
052 new BootstrapLoaderClientThread(
053 portalCacheManagerName, portalCacheName);
054
055 bootstrapLoaderClientThread.start();
056 }
057 else {
058 doLoad(portalCacheManagerName, portalCacheName);
059 }
060 }
061
062 protected void doLoad(
063 String portalCacheManagerName, String portalCacheName) {
064
065 if (_log.isDebugEnabled()) {
066 _log.debug("Bootstraping " + portalCacheName);
067 }
068
069 try {
070 ClusterLinkBootstrapLoaderHelperUtil.loadCachesFromCluster(
071 portalCacheManagerName, portalCacheName);
072 }
073 catch (Exception e) {
074 if (_log.isWarnEnabled()) {
075 _log.warn("Unable to load cache data from the cluster", e);
076 }
077 }
078 }
079
080 private static final Log _log = LogFactoryUtil.getLog(
081 ClusterLinkBootstrapLoader.class);
082
083 private final boolean _bootstrapAsynchronously;
084
085 private class BootstrapLoaderClientThread extends Thread {
086
087 public BootstrapLoaderClientThread(
088 String portalCacheManagerName, String portalCacheName) {
089
090 if (_log.isDebugEnabled()) {
091 _log.debug(
092 "Bootstrap loader client thread for cache " +
093 portalCacheName + " from cache manager " +
094 portalCacheManagerName);
095 }
096
097 _portalCacheManagerName = portalCacheManagerName;
098 _portalCacheName = portalCacheName;
099
100 setDaemon(true);
101 setName(
102 BootstrapLoaderClientThread.class.getName() + " - " +
103 portalCacheManagerName + " - " + portalCacheName);
104 setPriority(Thread.NORM_PRIORITY);
105 }
106
107 @Override
108 public void run() {
109 try {
110 doLoad(_portalCacheManagerName, _portalCacheName);
111 }
112 catch (Exception e) {
113 if (_log.isWarnEnabled()) {
114 _log.warn("Unable to asynchronously stream bootstrap", e);
115 }
116 }
117 }
118
119 private final String _portalCacheManagerName;
120 private final String _portalCacheName;
121
122 }
123
124 }