1 28 29 package com.caucho.server.cluster; 30 31 import com.caucho.log.Log; 32 import com.caucho.vfs.Path; 33 import com.caucho.vfs.ReadStream; 34 import com.caucho.vfs.WriteStream; 35 36 import java.io.IOException ; 37 import java.util.logging.Level ; 38 import java.util.logging.Logger ; 39 40 44 public class ObjectBacking { 45 static protected final Logger log = Log.open(ObjectBacking.class); 46 47 private Path _objectPath; 49 50 private Store _store; 52 53 private String _id; 55 56 private DistributedObject _object; 58 59 66 public ObjectBacking(String id, Path objectPath, Store store) 67 { 68 _id = id; 69 _store = store; 70 _objectPath = objectPath; 71 } 72 73 76 public String getId() 77 { 78 return _id; 79 } 80 81 84 public Path getPath() 85 { 86 return _objectPath; 87 } 88 89 92 public DistributedObject getObject() 93 { 94 return _object; 95 } 96 97 100 public void setObject(DistributedObject object) 101 { 102 _object = object; 103 } 104 105 108 public ReadStream openRead() 109 throws IOException 110 { 111 return _objectPath.openRead(); 112 } 113 114 117 public WriteStream openWrite() 118 throws IOException 119 { 120 return _objectPath.openWrite(); 121 } 122 123 126 synchronized void save(DistributedObject object) 127 { 128 WriteStream os = null; 129 try { 130 os = _objectPath.openWrite(); 131 132 134 _object = object; 135 } catch (Exception e) { 136 log.log(Level.FINE, e.toString(), e); 137 } finally { 138 try { 139 if (os != null) 140 os.close(); 141 } catch (IOException e1) { 142 } 143 } 144 } 145 146 149 synchronized public void remove() 150 { 151 try { 152 _objectPath.remove(); 153 } catch (IOException e) { 154 log.log(Level.FINE, e.toString(), e); 155 } 156 } 157 158 161 public boolean canLog() 162 { 163 return log.isLoggable(Level.FINE); 164 } 165 166 169 public void log(String value) 170 { 171 log.fine(value); 172 } 173 174 public String toString() 175 { 176 return "DistBacking[" + _objectPath + "]"; 177 } 178 } 179 | Popular Tags |