KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > caching > impl > StoreEventRegistryImpl


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.caching.impl;
17
18 import java.io.IOException JavaDoc;
19
20 import org.apache.avalon.framework.service.ServiceException;
21 import org.apache.avalon.framework.service.ServiceManager;
22 import org.apache.avalon.framework.service.Serviceable;
23 import org.apache.excalibur.store.Store;
24
25 /**
26  * This implementation of <code>EventRegistry</code> stores its <code>EventRegistryDataWrapper</code>
27  * in the default <code>Store</code> defined in cocoon.xconf.
28  *
29  * @since 2.1
30  * @author <a HREF="mailto:ghoward@apache.org">Geoff Howard</a>
31  * @version CVS $Id: StoreEventRegistryImpl.java 37202 2004-08-30 14:04:43Z cziegeler $
32  */

33 public class StoreEventRegistryImpl extends AbstractDoubleMapEventRegistry
34     implements Serviceable {
35
36     private static final String JavaDoc EVENTREGISTRYKEY = "EVENTREGWRAPPER";
37     private ServiceManager m_manager;
38     private Store m_store;
39
40     protected void persist(EventRegistryDataWrapper wrapper) {
41         EventRegistryDataWrapper ecdw = wrapRegistry();
42         try {
43             m_store.store(EVENTREGISTRYKEY, ecdw);
44         } catch (IOException JavaDoc e) {
45             getLogger().warn("Unable to persist Event Registry");
46         }
47         this.m_manager.release(this.m_store);
48         m_manager = null;
49         m_store = null;
50     }
51
52     /**
53      * Obtain a reference to the Store
54      */

55     public void service(ServiceManager manager) throws ServiceException {
56         this.m_manager = manager;
57         this.m_store = (Store) manager.lookup(Store.ROLE);
58     }
59
60     /**
61      * Recover the datawrapper from the Store.
62      */

63     protected boolean recover() {
64         Object JavaDoc o = m_store.get(EVENTREGISTRYKEY);
65         m_store.remove(EVENTREGISTRYKEY);
66         if (o != null && o instanceof EventRegistryDataWrapper) {
67             if (getLogger().isInfoEnabled()) {
68                 getLogger().info("Retrieving EventRegistry from Store.");
69             }
70             unwrapRegistry((EventRegistryDataWrapper) o);
71             return true;
72         } else {
73             getLogger().warn("Unable to recover Event Registry.");
74             super.createBlankCache();
75             return false;
76         }
77     }
78
79 }
80
Popular Tags