feisty meow concerns codebase  2.140
RoleBasedCacheNode.java
Go to the documentation of this file.
1 package org.gffs.cache;
2 
3 /*
4  * Copyright 2006 University of Virginia
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
7  * 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 distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
13  * and limitations under the License.
14  */
15 
16 import java.util.Date;
17 
18 class RoleBasedCacheNode<KeyType, DataType>
19 {
20  static public final int ROLE_LRU = 0;
21  static public final int ROLE_TIMEOUT = 1;
22  static private final int _NUM_ROLES = 2;
23 
24  private Object[] _next;
25  private Object[] _previous;
26 
27  private KeyType _key;
28  private DataType _data;
29 
30  private Date _invalidationDate;
31 
32  public RoleBasedCacheNode(KeyType key, DataType data, Date invalidationDate)
33  {
34  _next = new Object[_NUM_ROLES];
35  _previous = new Object[_NUM_ROLES];
36 
37  for (int lcv = 0; lcv < _NUM_ROLES; lcv++) {
38  _next[lcv] = null;
39  _previous[lcv] = null;
40  }
41 
42  _key = key;
43  _data = data;
44  _invalidationDate = invalidationDate;
45  }
46 
47  public KeyType getKey()
48  {
49  return _key;
50  }
51 
52  public DataType getData()
53  {
54  return _data;
55  }
56 
57  public Date getInvalidationDate()
58  {
59  return _invalidationDate;
60  }
61 
62  public void setInvalidationDate(long millisecondsFromNow)
63  {
64  _invalidationDate = new Date(System.currentTimeMillis() + millisecondsFromNow);
65  }
66 
67  @SuppressWarnings("unchecked")
68  public RoleBasedCacheNode<KeyType, DataType> getPrevious(int role)
69  {
70  return RoleBasedCacheNode.class.cast(_previous[role]);
71  }
72 
73  @SuppressWarnings("unchecked")
74  public RoleBasedCacheNode<KeyType, DataType> getNext(int role)
75  {
76  return RoleBasedCacheNode.class.cast(_next[role]);
77  }
78 
79  public void setPrevious(int role, RoleBasedCacheNode<KeyType, DataType> previous)
80  {
81  _previous[role] = previous;
82  }
83 
84  public void setNext(int role, RoleBasedCacheNode<KeyType, DataType> next)
85  {
86  _next[role] = next;
87  }
88 
89  public void clearLinks(int role)
90  {
91  _previous[role] = null;
92  _next[role] = null;
93  }
94 
95  public void clearLinks()
96  {
97  for (int lcv = 0; lcv < _NUM_ROLES; lcv++)
98  clearLinks(lcv);
99  }
100 }