awesome assets from gffs code
[feisty_meow.git] / kona / src / org / gffs / cache / TimeoutList.java
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 class TimeoutList<KeyType, DataType> extends CacheList<KeyType, DataType>
17 {
18         public TimeoutList()
19         {
20                 super(RoleBasedCacheNode.ROLE_TIMEOUT);
21         }
22
23         @Override
24         public void insert(RoleBasedCacheNode<KeyType, DataType> node)
25         {
26                 // We'll start at the end because most likely we're adding to the end
27                 if (_tail == null) {
28                         // The list is empty
29                         _head = _tail = node;
30                         return;
31                 }
32
33                 RoleBasedCacheNode<KeyType, DataType> tmp;
34                 for (tmp = _tail; tmp != null; tmp = tmp.getPrevious(_myRole)) {
35                         if (tmp.getInvalidationDate().compareTo(node.getInvalidationDate()) <= 0) {
36                                 // current node invalidates before me, so I should go after him
37                                 node.setPrevious(_myRole, tmp);
38                                 node.setNext(_myRole, tmp.getNext(_myRole));
39                                 tmp.setNext(_myRole, node);
40                                 if (node.getNext(_myRole) == null) {
41                                         // Adding to the tail
42                                         _tail = node;
43                                 } else {
44                                         node.getNext(_myRole).setPrevious(_myRole, node);
45                                 }
46
47                                 return;
48                         }
49                 }
50
51                 // We add to the head of the list
52                 node.setNext(_myRole, _head);
53                 _head.setPrevious(_myRole, node);
54                 _head = node;
55         }
56 }