1 49 package org.exolab.jms.tranlog; 50 51 import java.io.Externalizable ; 52 import java.io.IOException ; 53 import java.io.ObjectInput ; 54 import java.io.ObjectOutput ; 55 56 57 64 public abstract class BaseTransactionLogEntry implements Externalizable { 65 66 70 static final long serialVersionUID = 2; 71 72 75 private ExternalXid _externalXid = null; 76 77 80 private String _resourceId; 81 82 85 private long _created = -1; 86 87 91 private long _expiryTime = 0; 92 93 94 97 BaseTransactionLogEntry() { 98 } 99 100 108 BaseTransactionLogEntry(ExternalXid txid, String rid, long created) { 109 _externalXid = txid; 110 _resourceId = rid; 111 _created = created; 112 } 113 114 120 BaseTransactionLogEntry(BaseTransactionLogEntry copy) { 121 _externalXid = new ExternalXid(copy._externalXid); 122 _resourceId = copy._resourceId; 123 _created = copy._created; 124 _expiryTime = copy._expiryTime; 125 } 126 127 132 public void setExternalXid(ExternalXid txid) { 133 _externalXid = txid; 134 } 135 136 141 public ExternalXid getExternalXid() { 142 return _externalXid; 143 } 144 145 150 public void setResourceId(String rid) { 151 _resourceId = rid; 152 } 153 154 159 public String getResourceId() { 160 return _resourceId; 161 } 162 163 168 public void setCreated(long time) { 169 _created = time; 170 } 171 172 175 public void setCreated() { 176 _created = System.currentTimeMillis(); 177 } 178 179 184 public long getCreated() { 185 return _created; 186 } 187 188 189 195 public void setExpiryTime(long time) { 196 _expiryTime = time; 197 } 198 199 204 public long getExpiryTime() { 205 return _expiryTime; 206 } 207 208 213 public boolean transactionExpired() { 214 return System.currentTimeMillis() > _expiryTime; 215 } 216 217 public void writeExternal(ObjectOutput stream) 219 throws IOException { 220 if (isValid()) { 221 stream.writeLong(serialVersionUID); 222 stream.writeObject(_externalXid); 223 stream.writeUTF(_resourceId); 224 stream.writeLong(_created); 225 } else { 226 throw new IOException ("writeExternal : entry has invalid state"); 227 } 228 } 229 230 public void readExternal(ObjectInput stream) 232 throws IOException , ClassNotFoundException { 233 long version = stream.readLong(); 234 if (version == serialVersionUID) { 235 _externalXid = (ExternalXid) stream.readObject(); 236 _resourceId = stream.readUTF(); 237 _created = stream.readLong(); 238 if (!isValid()) { 239 throw new IOException ("readExternal : entry has invalid state"); 240 } 241 } else { 242 throw new IOException ("No support for BaseTransactionLogEntry " + 243 "with version " + version); 244 } 245 } 246 247 253 boolean isValid() { 254 return ((_externalXid != null) && 255 (_resourceId != null) && 256 (_created != -1)); 257 } 258 259 } 260 261 | Popular Tags |