| 1 4 package com.nightlabs.ipanema.jdo.cache; 5 6 import java.lang.ref.SoftReference ; 7 8 11 public class Carrier 12 { 13 private Key key; 14 private SoftReference ref; 15 16 19 private long createDT = System.currentTimeMillis(); 20 21 24 private long accessDT = System.currentTimeMillis(); 25 26 private CarrierContainer carrierContainer; 27 28 public Carrier(Key key, Object pcObject, CarrierContainer carrierContainer) 29 { 30 if (key == null) 31 throw new NullPointerException ("Parameter key must not be null!"); 32 33 if (pcObject == null) 34 throw new NullPointerException ("Parameter pcObject must not be null!"); 35 36 if (carrierContainer == null) 37 throw new NullPointerException ("Parameter carrierContainer must not be null!"); 38 39 this.key = key; 40 this.ref = new SoftReference (pcObject); 41 this.carrierContainer = carrierContainer; 42 carrierContainer.addCarrier(this); 43 } 44 45 48 public Key getKey() 49 { 50 return key; 51 } 52 53 57 public Object getObject() 58 { 59 return ref.get(); 60 } 61 62 65 public CarrierContainer getCarrierContainer() 66 { 67 return carrierContainer; 68 } 69 70 74 public void setCarrierContainer(CarrierContainer carrierContainer) 75 { 76 if (carrierContainer != null) 77 throw new IllegalArgumentException ("Currently, carrierContainer must be null!"); 78 79 if (this.carrierContainer != null) { 80 this.carrierContainer.removeCarrier(this.getKey()); 81 } 82 83 this.carrierContainer = carrierContainer; 84 } 85 86 89 public long getCreateDT() 90 { 91 return createDT; 92 } 93 94 99 public long getAccessDT() 100 { 101 return accessDT; 102 } 103 104 108 public void setAccessDT() 109 { 110 this.accessDT = System.currentTimeMillis(); 111 } 112 } 113 | Popular Tags |