KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tomcat > util > buf > TimeStamp


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.tomcat.util.buf;
19
20 import java.io.Serializable JavaDoc;
21
22 // XXX Shouldn't be here - has nothing to do with buffers.
23

24 /**
25  * Main tool for object expiry.
26  * Marks creation and access time of an "expirable" object,
27  * and extra properties like "id", "valid", etc.
28  *
29  * Used for objects that expire - originally Sessions, but
30  * also Contexts, Servlets, cache - or any other object that
31  * expires.
32  *
33  * @author Costin Manolache
34  */

35 public final class TimeStamp implements Serializable JavaDoc {
36     private long creationTime = 0L;
37     private long lastAccessedTime = creationTime;
38     private long thisAccessedTime = creationTime;
39     private boolean isNew = true;
40     private long maxInactiveInterval = -1;
41     private boolean isValid = false;
42     MessageBytes name;
43     int id=-1;
44     
45     Object JavaDoc parent;
46     
47     public TimeStamp() {
48     }
49
50     // -------------------- Active methods --------------------
51

52     /**
53      * Access notification. This method takes a time parameter in order
54      * to allow callers to efficiently manage expensive calls to
55      * System.currentTimeMillis()
56      */

57     public void touch(long time) {
58     this.lastAccessedTime = this.thisAccessedTime;
59     this.thisAccessedTime = time;
60     this.isNew=false;
61     }
62
63     // -------------------- Property access --------------------
64

65     /** Return the "name" of the timestamp. This can be used
66      * to associate unique identifier with each timestamped object.
67      * The name is a MessageBytes - i.e. a modifiable byte[] or char[].
68      */

69     public MessageBytes getName() {
70     if( name==null ) name=MessageBytes.newInstance();//lazy
71
return name;
72     }
73
74     /** Each object can have an unique id, similar with name but
75      * providing faster access ( array vs. hashtable lookup )
76      */

77     public int getId() {
78     return id;
79     }
80
81     public void setId( int id ) {
82     this.id=id;
83     }
84     
85     /** Returns the owner of this stamp ( the object that is
86      * time-stamped ).
87      * For a
88      */

89     public void setParent( Object JavaDoc o ) {
90     parent=o;
91     }
92
93     public Object JavaDoc getParent() {
94     return parent;
95     }
96
97     public void setCreationTime(long time) {
98     this.creationTime = time;
99     this.lastAccessedTime = time;
100     this.thisAccessedTime = time;
101     }
102
103
104     public long getLastAccessedTime() {
105     return lastAccessedTime;
106     }
107
108     public long getThisAccessedTime() {
109         return thisAccessedTime;
110     }
111
112     /** Inactive interval in millis - the time is computed
113      * in millis, convert to secs in the upper layer
114      */

115     public long getMaxInactiveInterval() {
116     return maxInactiveInterval;
117     }
118
119     public void setMaxInactiveInterval(long interval) {
120     maxInactiveInterval = interval;
121     }
122
123     public boolean isValid() {
124     return isValid;
125     }
126
127     public void setValid(boolean isValid) {
128     this.isValid = isValid;
129     }
130
131     public boolean isNew() {
132     return isNew;
133     }
134
135     public void setNew(boolean isNew) {
136     this.isNew = isNew;
137     }
138
139     public long getCreationTime() {
140     return creationTime;
141     }
142
143     // -------------------- Maintainance --------------------
144

145     public void recycle() {
146     creationTime = 0L;
147     lastAccessedTime = 0L;
148     maxInactiveInterval = -1;
149     isNew = true;
150     isValid = false;
151     id=-1;
152     if( name!=null) name.recycle();
153     }
154
155 }
156
157
Popular Tags