KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > eviction > NodeEntry


1 package org.jboss.cache.eviction;
2
3 import org.jboss.cache.Fqn;
4
5 /**
6  * Value object used in queue
7  *
8  * @author Ben Wang 2-2004
9  * @author Daniel Huang - dhuang@jboss.org
10  */

11 public class NodeEntry
12 {
13    private long modifiedTimeStamp;
14    private long creationTimeStamp;
15    private int numberOfNodeVisits;
16    private int numberOfElements;
17    private Fqn fqn;
18
19    private long inUseTimeoutTimestamp;
20    private boolean currentlyInUse = false;
21
22    EvictionQueue queue;
23
24    /**
25     * Private constructor that automatically sets the creation time stamp of the node entry.
26     */

27    private NodeEntry()
28    {
29       this.creationTimeStamp = System.currentTimeMillis();
30    }
31
32    public NodeEntry(Fqn fqn)
33    {
34       this();
35       setFqn(fqn);
36    }
37
38    public NodeEntry(String JavaDoc fqn)
39    {
40       this();
41       setFqn(Fqn.fromString(fqn));
42    }
43
44    /**
45     * Is the node currently in use.
46     *
47     * @return True/false if the node is currently marked as in use.
48     */

49    public boolean isCurrentlyInUse()
50    {
51       return currentlyInUse;
52    }
53
54    public void setCurrentlyInUse(boolean currentlyInUse, long inUseTimeout)
55    {
56       this.currentlyInUse = currentlyInUse;
57       if (inUseTimeout > 0)
58       {
59          this.inUseTimeoutTimestamp = System.currentTimeMillis() + inUseTimeout;
60       }
61    }
62
63    public long getInUseTimeoutTimestamp()
64    {
65       return this.inUseTimeoutTimestamp;
66    }
67
68    /**
69     * Get modified time stamp. This stamp is created during the node is
70     * processed so it has some fuzy tolerance in there.
71     *
72     * @return The last modified time stamp
73     */

74    public long getModifiedTimeStamp()
75    {
76       return modifiedTimeStamp;
77    }
78
79    public void setModifiedTimeStamp(long modifiedTimeStamp)
80    {
81       this.modifiedTimeStamp = modifiedTimeStamp;
82    }
83
84    /**
85     * Get the time stamp for when the node entry was created.
86     *
87     * @return The node entry creation time stamp
88     */

89    public long getCreationTimeStamp()
90    {
91       return creationTimeStamp;
92    }
93
94    public void setCreationTimeStamp(long creationTimeStamp)
95    {
96       this.creationTimeStamp = creationTimeStamp;
97    }
98
99    public int getNumberOfNodeVisits()
100    {
101       return numberOfNodeVisits;
102    }
103
104    public void setNumberOfNodeVisits(int numberOfNodeVisits)
105    {
106       this.numberOfNodeVisits = numberOfNodeVisits;
107    }
108
109    public int getNumberOfElements()
110    {
111       return numberOfElements;
112    }
113
114    public void setNumberOfElements(int numberOfElements)
115    {
116       if (queue != null)
117       {
118          int difference = numberOfElements - this.numberOfElements;
119          queue.modifyElementCount(difference);
120       }
121       this.numberOfElements = numberOfElements;
122    }
123
124    public Fqn getFqn()
125    {
126       return fqn;
127    }
128
129    void setFqn(Fqn fqn)
130    {
131       this.fqn = fqn;
132    }
133
134    public int hashCode()
135    {
136       return fqn.hashCode();
137    }
138
139    public boolean equals(Object JavaDoc o)
140    {
141       if (!(o instanceof NodeEntry))
142          return false;
143       NodeEntry ne = (NodeEntry) o;
144       return fqn.equals(ne.getFqn());
145    }
146
147    public String JavaDoc toString()
148    {
149       StringBuffer JavaDoc output = new StringBuffer JavaDoc();
150       output.append("Fqn: ");
151       if (fqn != null)
152       {
153          output.append(fqn);
154       }
155       else
156       {
157          output.append(" null");
158       }
159
160       output.append(" CreateTime: ").append(this.getCreationTimeStamp());
161       output.append(" NodeVisits: ").append(this.getNumberOfNodeVisits());
162       output.append(" ModifiedTime: ").append(this.getModifiedTimeStamp());
163       output.append(" NumberOfElements: ").append(this.getNumberOfElements());
164       output.append(" CurrentlyInUse: ").append(this.isCurrentlyInUse());
165       return output.toString();
166    }
167
168 }
169
Popular Tags