1 29 30 package com.caucho.server.cluster; 31 32 import com.caucho.vfs.Path; 33 import com.caucho.vfs.ReadStream; 34 import com.caucho.vfs.TempStream; 35 import com.caucho.vfs.Vfs; 36 37 import javax.annotation.PostConstruct; 38 import java.util.logging.Level ; 39 40 43 public class FileStore extends StoreManager { 44 private final FileBacking _backing = new FileBacking(); 45 46 49 public FileStore() 50 { 51 } 52 53 56 public void setPath(Path path) 57 { 58 _backing.setPath(path); 59 } 60 61 public void addText(String value) 62 { 63 _backing.setPath(Vfs.lookup(value.trim())); 64 } 65 66 public Path getPath() 67 { 68 return _backing.getPath(); 69 } 70 71 74 @PostConstruct 75 public boolean init() 76 throws Exception 77 { 78 if (! super.init()) 79 return false; 80 81 String serverId = Cluster.getServerId(); 82 83 String tableName = _backing.serverNameToTableName(serverId); 84 85 _backing.setTableName(tableName); 86 87 _backing.init(1); 88 89 return true; 90 } 91 92 95 public boolean start() 96 throws Exception 97 { 98 if (! super.start()) 99 return false; 100 101 _backing.start(); 102 103 return true; 104 } 105 106 109 public void clearOldObjects() 110 { 111 try { 112 _backing.clearOldObjects(getMaxIdleTime()); 113 } catch (Exception e) { 114 log.log(Level.WARNING, e.toString(), e); 115 } 116 } 117 118 121 @Override 122 protected boolean isPrimary(String id) 123 { 124 return true; 125 } 126 127 130 ClusterObject create(Store store, String id) 131 { 132 return new ClusterObject(this, store, id); 133 } 134 135 140 public boolean load(ClusterObject clusterObj, Object obj) 141 throws Exception 142 { 143 return _backing.loadSelf(clusterObj, obj); 144 } 145 146 154 public void store(ClusterObject obj, 155 TempStream tempStream, 156 long crc) 157 throws Exception 158 { 159 if (crc == 0) 160 return; 161 162 int length = tempStream.getLength(); 163 ReadStream is = tempStream.openRead(true); 164 try { 165 _backing.storeSelf(obj.getUniqueId(), is, length, 166 obj.getExpireInterval(), 0, 0, 0); 167 168 if (log.isLoggable(Level.FINE)) 169 log.fine("file store: " + obj.getUniqueId() + " length=" + 170 length); 171 } finally { 172 is.close(); 173 } 174 } 175 176 181 public void accessImpl(String uniqueId) 182 throws Exception 183 { 184 _backing.updateAccess(uniqueId); 185 } 186 187 193 public void setExpireInterval(String uniqueId, long expires) 194 throws Exception 195 { 196 _backing.setExpireInterval(uniqueId, expires); 197 } 198 199 202 public void remove(ClusterObject obj) 203 throws Exception 204 { 205 removeClusterObject(obj.getStoreId(), obj.getObjectId()); 206 207 _backing.remove(obj.getUniqueId()); 208 } 209 210 public String toString() 211 { 212 return "FileStore[]"; 213 } 214 } 215 | Popular Tags |