1 package snaq.util; 2 3 import java.util.*; 4 5 11 public class TimeWrapper implements Cacheable 12 { 13 private Object id, obj; 14 private long death = 0; 15 private long accessed = System.currentTimeMillis(); 16 17 23 public TimeWrapper(Object id, Object obj, long expiryTime) 24 { 25 this.id = id; 26 this.obj = obj; 27 if (expiryTime > 0) 28 this.death = System.currentTimeMillis() + expiryTime; 29 } 30 31 34 public Object getId() 35 { 36 return id; 37 } 38 39 42 public Object getObject() { return obj; } 43 44 48 synchronized void setLiveTime(long expiryTime) 49 { 50 if (expiryTime < 0) 51 throw new IllegalArgumentException ("Invalid expiry time"); 52 else if (expiryTime > 0) 53 this.death = System.currentTimeMillis() + expiryTime; 54 else 55 death = 0; 56 } 57 58 62 public synchronized boolean isExpired() 63 { 64 return death > 0 && System.currentTimeMillis() > death; 65 } 66 67 70 synchronized void updateAccessed() { accessed = System.currentTimeMillis(); } 71 72 75 long getAccessed() { return accessed; } 76 } | Popular Tags |