KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > kaha > impl > index > VMIndex


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

14
15 package org.apache.activemq.kaha.impl.index;
16
17 import java.io.IOException JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20 import org.apache.activemq.kaha.Marshaller;
21 import org.apache.activemq.kaha.StoreEntry;
22 import org.apache.activemq.kaha.impl.container.MapContainerImpl;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /**
27  * Index implementation using a HashMap
28  *
29  * @version $Revision: 1.2 $
30  */

31 public class VMIndex implements Index{
32     private static final Log log=LogFactory.getLog(VMIndex.class);
33     private IndexManager indexManager;
34     private Map JavaDoc<Object JavaDoc,StoreEntry> map=new HashMap JavaDoc<Object JavaDoc,StoreEntry>();
35
36     public VMIndex(IndexManager manager) {
37         this.indexManager= manager;
38     }
39     /**
40      *
41      * @see org.apache.activemq.kaha.impl.index.Index#clear()
42      */

43     public void clear(){
44         map.clear();
45     }
46
47     /**
48      * @param key
49      * @return true if the index contains the key
50      * @see org.apache.activemq.kaha.impl.index.Index#containsKey(java.lang.Object)
51      */

52     public boolean containsKey(Object JavaDoc key){
53         return map.containsKey(key);
54     }
55
56     /**
57      * @param key
58      * @return store entry
59      * @see org.apache.activemq.kaha.impl.index.Index#removeKey(java.lang.Object)
60      */

61     public StoreEntry remove(Object JavaDoc key){
62         StoreEntry result = map.remove(key);
63         if (result != null) {
64             try{
65                 result=indexManager.refreshIndex((IndexItem)result);
66             }catch(IOException JavaDoc e){
67                 log.error("Failed to refresh entry",e);
68                throw new RuntimeException JavaDoc("Failed to refresh entry");
69             }
70         }
71         return result;
72     }
73
74     /**
75      * @param key
76      * @param entry
77      * @see org.apache.activemq.kaha.impl.index.Index#store(java.lang.Object,
78      * org.apache.activemq.kaha.impl.index.IndexItem)
79      */

80     public void store(Object JavaDoc key,StoreEntry entry){
81         map.put(key,entry);
82     }
83
84     /**
85      * @param key
86      * @return the entry
87      */

88     public StoreEntry get(Object JavaDoc key){
89         StoreEntry result = map.get(key);
90         if (result != null) {
91             try{
92                 result=indexManager.refreshIndex((IndexItem)result);
93             }catch(IOException JavaDoc e){
94                 log.error("Failed to refresh entry",e);
95                throw new RuntimeException JavaDoc("Failed to refresh entry");
96             }
97         }
98         return result;
99     }
100
101     /**
102      * @return true if the index is transient
103      */

104     public boolean isTransient(){
105         return true;
106     }
107
108     /**
109      * load indexes
110      */

111     public void load(){
112     }
113
114     /**
115      * unload indexes
116      */

117     public void unload(){
118         map.clear();
119     }
120     
121    
122     public void setKeyMarshaller(Marshaller marshaller){
123     }
124 }
125
Popular Tags