cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r894241 - in /cocoon/cocoon3/trunk: cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/ cocoon-pipeline/ cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/ cocoon-pipeline/src/main/java/org/ap...
Date Mon, 28 Dec 2009 20:27:29 GMT
Author: reinhard
Date: Mon Dec 28 20:27:28 2009
New Revision: 894241

URL: http://svn.apache.org/viewvc?rev=894241&view=rev
Log:
use MurmurHash 2.0, a strong hashing algorithm, to implement the hashCode() method of cache
keys
[Using the Java MurmurHash 2.0 implementation by Andrzej Bialecki which is based on the original
C version by Austin Appleby (http://murmurhash.googlepages.com/).]

Added:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
  (with props)
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/EncodingHTMLSerializer.java
    cocoon/cocoon3/trunk/cocoon-pipeline/NOTICE.txt
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
    cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/CachingTimestampGenerator.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/EncodingHTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/EncodingHTMLSerializer.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/EncodingHTMLSerializer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/servlet/components/sax/serializers/EncodingHTMLSerializer.java
Mon Dec 28 20:27:28 2009
@@ -37,18 +37,18 @@
  * <p>
  * A serializer converting XHTML into plain old HTML.
  * </p>
- * 
+ *
  * <p>
  * For configuration options of this serializer, please look at the {@link EncodingXHTMLSerializer}
and
  * {@link EncodingSerializer}.
  * </p>
- * 
+ *
  * <p>
  * Any of the XHTML document type declared or used will be converted into its HTML 4.01 counterpart,
  * and in addition to those a "compatible" doctype can be supported to exploit a couple of
shortcuts
  * into MSIE's rendering engine. The values for the <code>doctype-default</code>
can then be:
  * </p>
- * 
+ *
  * <dl>
  * <dt>"<code>none</code>"</dt>
  * <dd>Not to emit any dococument type declaration.</dd>

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/NOTICE.txt
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/NOTICE.txt?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/NOTICE.txt (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/NOTICE.txt Mon Dec 28 20:27:28 2009
@@ -3,3 +3,7 @@
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
+
+This software contains a Java MurmurHash 2.0 implementation by 
+Andrzej Bialecki which is based on the original C version by Austin Appleby 
+(http://murmurhash.googlepages.com/).
\ No newline at end of file

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/CachingPipeline.java
Mon Dec 28 20:27:28 2009
@@ -44,23 +44,23 @@
  */
 public class CachingPipeline<T extends PipelineComponent> extends AbstractPipeline<T>
{
 
+    protected Cache cache;
+
     protected CacheKey cacheKey;
 
     protected CachingOutputStream cachingOutputStream;
 
-    protected Cache cache;
-
     /** Expires time in seconds */
     private String expires;
 
-    private String jmxGroupName;
-
     /**
      * Expires pipelines that have non-cacheable pipeline components require an
      * explicit cache key
      */
     private Serializable expiresCacheKey;
 
+    private String jmxGroupName;
+
     private final Log logger = LogFactory.getLog(this.getClass());
 
     public CacheKey constructCacheKey() {
@@ -147,6 +147,10 @@
         this.setCachedValue(this.cacheKey, cacheValue);
     }
 
+    public CacheKey getCacheKey() {
+        return this.cacheKey;
+    }
+
     public String getExpires() {
         return this.expires;
     }
@@ -160,6 +164,10 @@
         return this.cacheKey.getLastModified();
     }
 
+    public void setCache(Cache cache) {
+        this.cache = cache;
+    }
+
     /**
      * {@inheritDoc}
      *
@@ -174,16 +182,12 @@
         super.setConfiguration(parameters);
     }
 
-    public void setExpiresCacheKey(Serializable expiresCacheKey) {
-        this.expiresCacheKey = expiresCacheKey;
-    }
-
     public void setExpires(String expires) {
         this.expires = expires;
     }
 
-    public void setCache(Cache cache) {
-        this.cache = cache;
+    public void setExpiresCacheKey(Serializable expiresCacheKey) {
+        this.expiresCacheKey = expiresCacheKey;
     }
 
     @Override

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompoundCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -22,6 +22,7 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -77,18 +78,18 @@
 
     @Override
     public int hashCode() {
-        int result = 1;
+        MurmurHashCodeBuilder murmurHashCodeBuilder = new MurmurHashCodeBuilder();
 
         for (CacheKey cacheKey : this.cacheKeys) {
-            result = 31 * result + cacheKey.hashCode();
+            murmurHashCodeBuilder.append(cacheKey.hashCode());
         }
 
-        return result;
+        return murmurHashCodeBuilder.toHashCode();
     }
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.caching.CacheKey#isValid(org.apache.cocoon.pipeline.caching.CacheKey)
      */
     public boolean isValid(CacheKey cacheKey) {

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ExpiresCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -19,6 +19,8 @@
  */
 package org.apache.cocoon.pipeline.caching;
 
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
+
 /**
  * A cache key implementation that expires after a defined number of seconds.
  */
@@ -37,7 +39,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.caching.CacheKey#isValid(org.apache.cocoon.pipeline.caching.CacheKey)
      */
     public boolean isValid(CacheKey cacheKey) {
@@ -84,16 +86,12 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
     public int hashCode() {
-        int result = 1;
-
-        result = 31 * result + this.getClass().hashCode();
-        result = 31 * result + this.cacheKey.hashCode();
-
-        return result;
+        return new MurmurHashCodeBuilder().append(this.getClass().getName()).append(this.cacheKey.hashCode())
+                .toHashCode();
     }
 }
\ No newline at end of file

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/InvalidCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -18,6 +18,8 @@
 
 import java.io.Serializable;
 
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
+
 public class InvalidCacheKey extends AbstractCacheKey {
 
     private static final long serialVersionUID = 1L;
@@ -47,12 +49,8 @@
 
     @Override
     public int hashCode() {
-        int result = 1;
-
-        result = 31 * result + this.getClass().hashCode();
-        result = 31 * result + this.expiresCacheKey.hashCode();
-
-        return result;
+        return new MurmurHashCodeBuilder().append(this.getClass().getName()).append(this.expiresCacheKey.hashCode())
+                .toHashCode();
     }
 
     public boolean isValid(CacheKey cacheKey) {

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -18,6 +18,9 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
 
 /**
  * A {@link CacheKey} that contains a {@link Map} of parameters.
@@ -25,28 +28,51 @@
 public class ParameterCacheKey extends AbstractCacheKey {
 
     private static final long serialVersionUID = 1L;
-    private final Map<String, Object> parameters;
+    private final Map<String, String> parameters;
 
     public ParameterCacheKey() {
-        this(new HashMap<String, Object>());
+        this(new HashMap<String, String>());
     }
 
-    public ParameterCacheKey(Map<String, Object> parameters) {
+    public ParameterCacheKey(Map<String, String> parameters) {
+        if (parameters == null) {
+            throw new IllegalArgumentException("A map of parameters has to be passed.");
+        }
+
         this.parameters = parameters;
     }
 
-    public ParameterCacheKey(String name, Object value) {
+    public ParameterCacheKey(String name, Map<?, ?> value) {
+        this();
+        this.addParameter(name, value);
+    }
+
+    public ParameterCacheKey(String name, String value) {
         this();
         this.addParameter(name, value);
     }
 
-    public void addParameter(String name, Object value) {
+    public void addParameter(String name, boolean value) {
+        this.parameters.put(name, Boolean.toString(value));
+    }
+
+    public void addParameter(String name, int value) {
+        this.parameters.put(name, Integer.toString(value));
+    }
+
+    public void addParameter(String name, Map<?, ?> value) {
+        for (Entry<?, ?> object : value.entrySet()) {
+            this.parameters.put(name + "_" + object.getKey().toString(), object.getValue().toString());
+        }
+    }
+
+    public void addParameter(String name, String value) {
         this.parameters.put(name, value);
     }
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see java.lang.Object#equals(java.lang.Object)
      */
     @Override
@@ -59,29 +85,32 @@
         return this.parameters != null && this.parameters.equals(other.parameters);
     }
 
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.apache.cocoon.pipeline.caching.CacheKey#getLastModified()
+     */
     public long getLastModified() {
         return -1;
     }
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see java.lang.Object#hashCode()
      */
     @Override
     public int hashCode() {
-        int hashCode = ParameterCacheKey.class.hashCode();
-
-        if (this.parameters != null) {
-            hashCode = 31 * hashCode + this.parameters.hashCode();
+        MurmurHashCodeBuilder hashCodeBuilder = new MurmurHashCodeBuilder();
+        for (Entry<String, String> parameterEntry : this.parameters.entrySet()) {
+            hashCodeBuilder.append(parameterEntry.getKey()).append(parameterEntry.getValue());
         }
-
-        return hashCode;
+        return hashCodeBuilder.toHashCode();
     }
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.caching.CacheKey#isValid(org.apache.cocoon.pipeline.caching.CacheKey)
      */
     public boolean isValid(CacheKey cacheKey) {

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cocoon.pipeline.caching;
 
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 
 public class SimpleCacheKey extends AbstractCacheKey {
@@ -31,7 +32,7 @@
 
     @Override
     public int hashCode() {
-        return this.getClass().hashCode();
+        return new MurmurHashCodeBuilder().append(this.getClass().getName()).toHashCode();
     }
 
     public boolean isValid(CacheKey cacheKey) {

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
Mon Dec 28 20:27:28 2009
@@ -22,6 +22,7 @@
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 
 public class TimestampCacheKey extends AbstractCacheKey {
@@ -57,7 +58,7 @@
 
     @Override
     public int hashCode() {
-        return this.url.hashCode();
+        return new MurmurHashCodeBuilder().append(this.url.toExternalForm()).toHashCode();
     }
 
     public boolean isValid(CacheKey cacheKey) {

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java?rev=894241&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
Mon Dec 28 20:27:28 2009
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.pipeline.util;
+
+/**
+ * This is a very fast, non-cryptographic hash suitable for general hash-based lookup. See
+ * http://murmurhash.googlepages.com/ for more details.
+ *
+ * <p>
+ * The C version of MurmurHash 2.0 found at that site was ported to Java by Andrzej Bialecki
(ab at
+ * getopt org): http://www.getopt.org/murmur/MurmurHash.java
+ * </p>
+ */
+public class MurmurHash {
+
+    public static int hash(byte[] data, int seed) {
+        int m = 0x5bd1e995;
+        int r = 24;
+
+        int h = seed ^ data.length;
+
+        int len = data.length;
+        int len_4 = len >> 2;
+
+        for (int i = 0; i < len_4; i++) {
+            int i_4 = i << 2;
+            int k = data[i_4 + 3];
+            k = k << 8;
+            k = k | data[i_4 + 2] & 0xff;
+            k = k << 8;
+            k = k | data[i_4 + 1] & 0xff;
+            k = k << 8;
+            k = k | data[i_4 + 0] & 0xff;
+            k *= m;
+            k ^= k >>> r;
+            k *= m;
+            h *= m;
+            h ^= k;
+        }
+
+        int len_m = len_4 << 2;
+        int left = len - len_m;
+
+        if (left != 0) {
+            if (left >= 3) {
+                h ^= data[len - 3] << 16;
+            }
+            if (left >= 2) {
+                h ^= data[len - 2] << 8;
+            }
+            if (left >= 1) {
+                h ^= data[len - 1];
+            }
+
+            h *= m;
+        }
+
+        h ^= h >>> 13;
+        h *= m;
+        h ^= h >>> 15;
+
+        return h;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHash.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java?rev=894241&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
Mon Dec 28 20:27:28 2009
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.pipeline.util;
+
+/**
+ * A hash code builder based on MurmurHash.
+ */
+public class MurmurHashCodeBuilder {
+
+    private byte[] bytes;
+
+    public MurmurHashCodeBuilder() {
+        this.bytes = new byte[0];
+    }
+
+    public MurmurHashCodeBuilder append(byte[] byteArray) {
+        if (byteArray == null) {
+            return this;
+        }
+
+        byte[] joinedArray = new byte[this.bytes.length + byteArray.length];
+        System.arraycopy(this.bytes, 0, joinedArray, 0, this.bytes.length);
+        System.arraycopy(byteArray, 0, joinedArray, this.bytes.length, byteArray.length);
+        this.bytes = joinedArray;
+        return this;
+    }
+
+    public MurmurHashCodeBuilder append(int value) {
+        return this.append(new byte[] { (byte) (value >>> 24), (byte) (value >>>
16), (byte) (value >>> 8), (byte) value });
+    }
+
+    public MurmurHashCodeBuilder append(String value) {
+        if (value == null) {
+            return this;
+        }
+
+        return this.append(value.getBytes());
+    }
+
+    public int toHashCode() {
+        return MurmurHash.hash(this.bytes, 1);
+    }
+
+    protected byte[] getBytes() {
+        return this.bytes;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java
Mon Dec 28 20:27:28 2009
@@ -24,7 +24,7 @@
     public static String buildString(Object instance, String... additionalOutputStrings)
{
         StringBuilder sb = new StringBuilder();
         sb.append(instance.getClass().getSimpleName());
-        sb.append("(hashCode=").append(instance.hashCode());
+        sb.append("(hashCode=").append(System.identityHashCode(instance));
 
         if (additionalOutputStrings != null) {
             for (String outputString : additionalOutputStrings) {

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java?rev=894241&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
Mon Dec 28 20:27:28 2009
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.pipeline.util;
+
+import static junit.framework.Assert.*;
+
+import org.junit.Test;
+
+public class MurmurHashCodeBuilderTest {
+
+    @Test
+    public void addInteger() {
+        byte[] bytes = new MurmurHashCodeBuilder().append(2).getBytes();
+        assertEquals(2, byteArrayToInt(bytes));
+    }
+
+    @Test
+    public void addMaxInteger() {
+        byte[] bytes = new MurmurHashCodeBuilder().append(Integer.MAX_VALUE).getBytes();
+        assertEquals(Integer.MAX_VALUE, byteArrayToInt(bytes));
+    }
+
+    @Test
+    public void addMinInteger() {
+        byte[] bytes = new MurmurHashCodeBuilder().append(Integer.MIN_VALUE).getBytes();
+        assertEquals(Integer.MIN_VALUE, byteArrayToInt(bytes));
+    }
+
+    @Test
+    public void addNullString() {
+        byte[] bytes = new MurmurHashCodeBuilder().append("a").append("b").append((String)
null).getBytes();
+        assertEquals("ab", new String(bytes));
+    }
+
+    @Test
+    public void addBytes() {
+        byte[] bytes = new MurmurHashCodeBuilder().append("a".getBytes()).append("b".getBytes()).getBytes();
+        assertEquals("ab", new String(bytes));
+    }
+
+    @Test
+    public void addString() {
+        byte[] bytes = new MurmurHashCodeBuilder().append("a").append("b").getBytes();
+        assertEquals("ab", new String(bytes));
+    }
+
+    @Test
+    public void toHashCode() {
+        int hashCode = new MurmurHashCodeBuilder().append("a").append("b").toHashCode();
+        assertEquals(-419373624, hashCode);
+    }
+
+    @Test
+    public void nullInputToHashCode() {
+        int hashCode = new MurmurHashCodeBuilder().toHashCode();
+        assertEquals(1540447798, hashCode);
+    }
+
+    private static final int byteArrayToInt(byte[] b) {
+        return (b[0] << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF)
<< 8) + (b[3] & 0xFF);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/util/MurmurHashCodeBuilderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/MethodDelegator.java
Mon Dec 28 20:27:28 2009
@@ -54,9 +54,7 @@
 
     public RestResponse delegate(HttpServletRequest request, Object controller) throws Exception
{
         if (request != null && request.getMethod() != null) {
-            String method = this.getMethod(request);
-
-            MethodDelegate methodDelegate = delegates.get(method);
+            MethodDelegate methodDelegate = delegates.get(this.getMethod(request));
             if (methodDelegate != null) {
                 return methodDelegate.execute(controller);
             }

Modified: cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/CachingTimestampGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/CachingTimestampGenerator.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/CachingTimestampGenerator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/generation/CachingTimestampGenerator.java
Mon Dec 28 20:27:28 2009
@@ -19,6 +19,7 @@
 import org.apache.cocoon.pipeline.caching.AbstractCacheKey;
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.util.MurmurHashCodeBuilder;
 
 public class CachingTimestampGenerator extends TimestampGenerator implements CachingPipelineComponent
{
 
@@ -48,7 +49,7 @@
 
         @Override
         public int hashCode() {
-            return this.getClass().hashCode();
+            return new MurmurHashCodeBuilder().append(this.getClass().getName()).toHashCode();
         }
 
         public boolean isValid(CacheKey other) {

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
Mon Dec 28 20:27:28 2009
@@ -21,6 +21,7 @@
 import java.io.OutputStream;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Map.Entry;
 
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.TransformerConfigurationException;
@@ -59,7 +60,11 @@
     }
 
     public CacheKey constructCacheKey() {
-        return new ParameterCacheKey("format", this.format);
+        ParameterCacheKey parameterCacheKey = new ParameterCacheKey();
+        for (Entry<Object, Object> property : this.format.entrySet()) {
+            parameterCacheKey.addParameter(property.getKey().toString(), property.getValue().toString());
+        }
+        return parameterCacheKey;
     }
 
     public XMLSerializer setCDataSectionElements(String cdataSectionElements) {

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
Mon Dec 28 20:27:28 2009
@@ -69,7 +69,7 @@
 
         try {
             cacheKey.addCacheKey(new TimestampCacheKey(this.source, this.source.openConnection().getLastModified()));
-            cacheKey.addCacheKey(new ParameterCacheKey(this.parameters));
+            cacheKey.addCacheKey(new ParameterCacheKey("contextParameters", this.parameters));
         } catch (IOException e) {
             throw new SetupException(e);
         }

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java?rev=894241&r1=894240&r2=894241&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java
Mon Dec 28 20:27:28 2009
@@ -61,7 +61,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.CachingPipelineComponent#constructCacheKey()
      */
     public CacheKey constructCacheKey() {
@@ -73,7 +73,7 @@
 
         try {
             cacheKey.addCacheKey(new TimestampCacheKey(this.source, this.source.openConnection().getLastModified()));
-            cacheKey.addCacheKey(new ParameterCacheKey(this.parameters));
+            cacheKey.addCacheKey(new ParameterCacheKey("contextParameters", this.parameters));
         } catch (IOException e) {
             throw new SetupException("Could not create cache key.", e);
         }
@@ -83,7 +83,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.Starter#execute()
      */
     public void execute() {
@@ -121,7 +121,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.Finisher#getContentType()
      */
     public String getContentType() {
@@ -130,7 +130,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
      */
     @Override
@@ -141,7 +141,7 @@
 
     /**
      * Set the mime-type directly which is useful when this component is used directly.
-     * 
+     *
      * @param mimeType
      *            The mime-type that belongs to the content that is produced by this component.
      */
@@ -151,7 +151,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
      */
     public void setOutputStream(OutputStream outputStream) {
@@ -160,7 +160,7 @@
 
     /**
      * Set the source {@link URL} directly when this component is used directly.
-     * 
+     *
      * @param source
      *            A {@link URL} that will be used by this component.
      */
@@ -170,7 +170,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * @see org.apache.cocoon.pipeline.component.AbstractPipelineComponent#setup(java.util.Map)
      */
     @Override



Mime
View raw message