01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: package org.apache.cocoon.caching.impl;
18:
19: import java.io.IOException;
20:
21: import org.apache.avalon.framework.service.ServiceException;
22: import org.apache.avalon.framework.service.ServiceManager;
23: import org.apache.avalon.framework.service.Serviceable;
24: import org.apache.excalibur.store.Store;
25:
26: /**
27: * This implementation of <code>EventRegistry</code> stores its <code>EventRegistryDataWrapper</code>
28: * in the default <code>Store</code> defined in cocoon.xconf.
29: *
30: * @since 2.1
31: * @author <a href="mailto:ghoward@apache.org">Geoff Howard</a>
32: * @version CVS $Id: StoreEventRegistryImpl.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34: public class StoreEventRegistryImpl extends
35: AbstractDoubleMapEventRegistry implements Serviceable {
36:
37: private static final String EVENTREGISTRYKEY = "EVENTREGWRAPPER";
38: private ServiceManager m_manager;
39: private Store m_store;
40:
41: protected void persist(EventRegistryDataWrapper wrapper) {
42: EventRegistryDataWrapper ecdw = wrapRegistry();
43: try {
44: m_store.store(EVENTREGISTRYKEY, ecdw);
45: } catch (IOException e) {
46: getLogger().warn("Unable to persist Event Registry");
47: }
48: this .m_manager.release(this .m_store);
49: m_manager = null;
50: m_store = null;
51: }
52:
53: /**
54: * Obtain a reference to the Store
55: */
56: public void service(ServiceManager manager) throws ServiceException {
57: this .m_manager = manager;
58: this .m_store = (Store) manager.lookup(Store.ROLE);
59: }
60:
61: /**
62: * Recover the datawrapper from the Store.
63: */
64: protected boolean recover() {
65: Object o = m_store.get(EVENTREGISTRYKEY);
66: m_store.remove(EVENTREGISTRYKEY);
67: if (o != null && o instanceof EventRegistryDataWrapper) {
68: if (getLogger().isInfoEnabled()) {
69: getLogger()
70: .info("Retrieving EventRegistry from Store.");
71: }
72: unwrapRegistry((EventRegistryDataWrapper) o);
73: return true;
74: } else {
75: getLogger().warn("Unable to recover Event Registry.");
76: super .createBlankCache();
77: return false;
78: }
79: }
80:
81: }
|