You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/09/28 21:24:44 UTC

svn commit: r292271 - /cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java

Author: vgritsenko
Date: Wed Sep 28 12:24:38 2005
New Revision: 292271

URL: http://svn.apache.org/viewcvs?rev=292271&view=rev
Log:
if (m_persistentFile == null) was always false

Modified:
    cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java

Modified: cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java?rev=292271&r1=292270&r2=292271&view=diff
==============================================================================
--- cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java (original)
+++ cocoon/blocks/eventcache/trunk/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java Wed Sep 28 12:24:38 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,21 +30,20 @@
 import org.apache.cocoon.caching.EventRegistry;
 
 /**
- * This implementation of <code>EventRegistry</code> handles 
- * persistence by serializing an <code>EventRegistryDataWrapper</code> to 
+ * This implementation of <code>EventRegistry</code> handles
+ * persistence by serializing an <code>EventRegistryDataWrapper</code> to
  * disk.
- * 
+ *
  * @since 2.1
  * @author <a href="mailto:ghoward@apache.org">Geoff Howard</a>
- * @version CVS $Id: DefaultEventRegistryImpl.java,v 1.12 2004/03/05 13:01:56 bdelacretaz Exp $
+ * @version $Id$
  */
-public class DefaultEventRegistryImpl 
-        extends AbstractDoubleMapEventRegistry
-        implements EventRegistry, 
-                   Contextualizable {
+public class DefaultEventRegistryImpl extends AbstractDoubleMapEventRegistry
+                                      implements EventRegistry, Contextualizable {
+
+    private static final String PERSISTENT_FILE = "/WEB-INF/ev_cache.ser";
 
     private File m_persistentFile;
-    private static final String PERSISTENT_FILE = "ev_cache.ser";    
 
     /**
      * Set up the persistence file.
@@ -53,27 +52,25 @@
         org.apache.cocoon.environment.Context ctx =
                 (org.apache.cocoon.environment.Context) context.get(
                                     Constants.CONTEXT_ENVIRONMENT_CONTEXT);
-        // set up file 
-        m_persistentFile = new File(
-                    ctx.getRealPath("/WEB-INF"), 
-                        DefaultEventRegistryImpl.PERSISTENT_FILE);
-        if (m_persistentFile == null) {
-            throw new ContextException("Could not obtain persistent file. " +
-                "The cache event registry cannot be " +
-                "used inside an unexpanded WAR file.");
+        // set up file
+        String path = ctx.getRealPath(PERSISTENT_FILE);
+        if (path == null) {
+            throw new ContextException("The cache event registry cannot be used inside an unexpanded WAR file. " +
+                                       "Real path for <" + PERSISTENT_FILE + "> is null.");
         }
+
+        m_persistentFile = new File(path);
     }
-    
-    /** 
-     * Persist by simple object serialization.  If the serialization fails, an 
-     * error is logged but not thrown because missing/invalid state is handled 
+
+    /**
+     * Persist by simple object serialization.  If the serialization fails, an
+     * error is logged but not thrown because missing/invalid state is handled
      * at startup.
      */
     protected void persist(EventRegistryDataWrapper registryWrapper) {
         ObjectOutputStream oos = null;
         try {
-            oos = new ObjectOutputStream(
-                                        new FileOutputStream(this.m_persistentFile));       
+            oos = new ObjectOutputStream(new FileOutputStream(this.m_persistentFile));
             oos.writeObject(registryWrapper);
             oos.flush();
         } catch (FileNotFoundException e) {
@@ -83,13 +80,13 @@
         } finally {
             try {
                 if (oos != null) oos.close();
-            } catch (IOException e) {}
+            } catch (IOException e) { /* ignored */ }
         }
     }
 
-    /* 
-     * I don't think this needs to get synchronized because it should 
-     * only be called during initialize, which should only be called 
+    /*
+     * I don't think this needs to get synchronized because it should
+     * only be called during initialize, which should only be called
      * once by the container.
      */
     protected boolean recover() {
@@ -97,8 +94,7 @@
             ObjectInputStream ois = null;
             EventRegistryDataWrapper ecdw = null;
             try {
-                ois = new ObjectInputStream(
-                    new FileInputStream(this.m_persistentFile));
+                ois = new ObjectInputStream(new FileInputStream(this.m_persistentFile));
                 ecdw = (EventRegistryDataWrapper)ois.readObject();
             } catch (FileNotFoundException e) {
                 getLogger().error("Unable to retrieve EventRegistry", e);
@@ -122,7 +118,7 @@
             unwrapRegistry(ecdw);
         } else {
             getLogger().warn(this.m_persistentFile + " does not exist - Unable to " +
-                "retrieve EventRegistry.");
+                             "retrieve EventRegistry.");
             createBlankCache();
             return false;
         }