KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > jdo > cache > Carrier


1 /*
2  * Created on Jul 24, 2005
3  */

4 package com.nightlabs.ipanema.jdo.cache;
5
6 import java.lang.ref.SoftReference JavaDoc;
7
8 /**
9  * @author Marco Schulze - marco at nightlabs dot de
10  */

11 public class Carrier
12 {
13     private Key key;
14     private SoftReference JavaDoc ref;
15
16     /**
17      * When has this <tt>Carrier</tt> been created.
18      */

19     private long createDT = System.currentTimeMillis();
20
21     /**
22      * When has this Carrier been accessed (and therefore used) the last time.
23      */

24     private long accessDT = System.currentTimeMillis();
25
26     private CarrierContainer carrierContainer;
27
28     public Carrier(Key key, Object JavaDoc pcObject, CarrierContainer carrierContainer)
29     {
30         if (key == null)
31             throw new NullPointerException JavaDoc("Parameter key must not be null!");
32
33         if (pcObject == null)
34             throw new NullPointerException JavaDoc("Parameter pcObject must not be null!");
35
36         if (carrierContainer == null)
37             throw new NullPointerException JavaDoc("Parameter carrierContainer must not be null!");
38
39         this.key = key;
40         this.ref = new SoftReference JavaDoc(pcObject);
41         this.carrierContainer = carrierContainer;
42         carrierContainer.addCarrier(this);
43     }
44
45     /**
46      * @return Returns the key.
47      */

48     public Key getKey()
49     {
50         return key;
51     }
52
53     /**
54      * @return Returns the object or <tt>null</tt> if the garbage collector has
55      * removed it.
56      */

57     public Object JavaDoc getObject()
58     {
59         return ref.get();
60     }
61
62     /**
63      * @return Returns the carrierContainer.
64      */

65     public CarrierContainer getCarrierContainer()
66     {
67         return carrierContainer;
68     }
69
70     /**
71      * @param carrierContainer The carrierContainer to set. Currently, only <tt>null</tt>
72      * is valid!
73      */

74     public void setCarrierContainer(CarrierContainer carrierContainer)
75     {
76         if (carrierContainer != null)
77             throw new IllegalArgumentException JavaDoc("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     /**
87      * @return Returns the createDT.
88      */

89     public long getCreateDT()
90     {
91         return createDT;
92     }
93
94     /**
95      * @return Returns the access time stamp, which is the time that this
96      * <tt>Carrier</tt> has been used the last time - updated via
97      * {@link #setAccessDT()}.
98      */

99     public long getAccessDT()
100     {
101         return accessDT;
102     }
103
104     /**
105      * Sets the access timestamp to <tt>System.currentTimeMillis()</tt>.
106      * @see #getAccessDT()
107      */

108     public void setAccessDT()
109     {
110         this.accessDT = System.currentTimeMillis();
111     }
112 }
113
Popular Tags