1 29 30 package com.caucho.server.cluster; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.L10N; 34 35 import java.util.logging.Logger ; 36 37 40 public class Store { 41 static protected final Logger log = Log.open(Store.class); 42 static final L10N L = new L10N(Store.class); 43 44 private StoreManager _storeManager; 45 private ObjectManager _objectManager; 46 private String _storeId; 47 private long _maxIdleTime; 48 49 private boolean _isAlwaysLoad; 50 private boolean _isAlwaysSave; 51 52 59 Store(String storeId, StoreManager storeManager) 60 { 61 _storeId = mangleId(storeId); 62 _storeManager = storeManager; 63 64 _maxIdleTime = storeManager.getMaxIdleTime(); 65 66 _isAlwaysLoad = _storeManager.isAlwaysLoad(); 67 _isAlwaysSave = _storeManager.isAlwaysSave(); 68 } 69 70 73 public String getId() 74 { 75 return _storeId; 76 } 77 78 81 public long getMaxIdleTime() 82 { 83 return _maxIdleTime; 84 } 85 86 89 public void setMaxIdleTime(long maxIdleTime) 90 { 91 _maxIdleTime = maxIdleTime; 92 93 _storeManager.updateIdleCheckInterval(maxIdleTime); 94 } 95 96 100 public long getAccessWindowTime() 101 { 102 long window = _maxIdleTime / 4; 103 104 if (window < 60000L) 105 return 60000L; 106 else 107 return window; 108 } 109 110 113 public boolean isAlwaysLoad() 114 { 115 return _isAlwaysLoad; 116 } 117 118 121 public void setAlwaysLoad(boolean isAlwaysLoad) 122 { 123 _isAlwaysLoad = isAlwaysLoad; 124 } 125 126 129 public void setAlwaysSave(boolean isAlwaysSave) 130 { 131 _isAlwaysSave = isAlwaysSave; 132 } 133 134 137 public boolean isAlwaysSave() 138 { 139 return _isAlwaysSave; 140 } 141 142 145 public ObjectManager getObjectManager() 146 { 147 return _objectManager; 148 } 149 150 153 public void setObjectManager(ObjectManager obj) 154 { 155 _objectManager = obj; 156 } 157 158 161 public StoreManager getStoreManager() 162 { 163 return _storeManager; 164 } 165 166 169 public ClusterObject createClusterObject(String objectId) 170 { 171 return _storeManager.createClusterObject(this, objectId); 172 } 173 174 179 public void access(String objectId) 180 throws Exception 181 { 182 _storeManager.access(this, objectId); 183 } 184 185 190 public void remove(String objectId) 191 throws Exception 192 { 193 _storeManager.remove(this, objectId); 194 } 195 196 201 void notifyRemove(String objectId) 202 throws Exception 203 { 204 if (_objectManager != null) 205 _objectManager.notifyRemove(objectId); 206 } 207 208 211 static private String mangleId(String id) 212 { 213 StringBuilder cb = new StringBuilder (); 214 215 for (int i = 0; i < id.length(); i++) { 216 char ch = id.charAt(i); 217 218 if (ch == '/') 219 cb.append("__"); 220 else if (ch == ':') 221 cb.append("_0"); 222 else if (ch == '_') 223 cb.append("_1"); 224 else 225 cb.append(ch); 226 } 227 228 return cb.toString(); 229 } 230 } 231 | Popular Tags |