incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r803385 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event: EventUtil.java impl/EventHelper.java impl/JobEventHandler.java
Date Wed, 12 Aug 2009 07:03:32 GMT
Author: cziegeler
Date: Wed Aug 12 07:03:31 2009
New Revision: 803385

URL: http://svn.apache.org/viewvc?rev=803385&view=rev
Log:
SLING-1071 - Create hierarchy of child nodes to avoid too many child nodes.

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=803385&r1=803384&r2=803385&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Wed Aug 12 07:03:31 2009
@@ -613,7 +613,7 @@
         if ( e == null ) {
             return "<null>";
         }
-        final StringBuffer buffer =new StringBuffer(e.getClass().getName());
+        final StringBuilder buffer = new StringBuilder(e.getClass().getName());
         buffer.append(" [topic=");
         buffer.append(e.getTopic());
         buffer.append(", properties=");

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java?rev=803385&r1=803384&r2=803385&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
Wed Aug 12 07:03:31 2009
@@ -18,6 +18,10 @@
  */
 package org.apache.sling.event.impl;
 
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
 
 /**
  * Helper class defining some constants and utility methods.
@@ -91,4 +95,47 @@
         return sb.toString();
     }
 
+    /**
+     * used for the md5
+     */
+    public static final char[] hexTable = "0123456789abcdef".toCharArray();
+
+    /**
+     * Calculate an MD5 hash of the string given using 'utf-8' encoding.
+     *
+     * @param data the data to encode
+     * @return a hex encoded string of the md5 digested input
+     */
+    public static String md5(String data) {
+        try {
+            return digest("MD5", data.getBytes("utf-8"));
+        } catch (NoSuchAlgorithmException e) {
+            throw new InternalError("MD5 digest not available???");
+        } catch (UnsupportedEncodingException e) {
+            throw new InternalError("UTF8 digest not available???");
+        }
+    }
+
+    /**
+     * Digest the plain string using the given algorithm.
+     *
+     * @param algorithm The alogrithm for the digest. This algorithm must be
+     *                  supported by the MessageDigest class.
+     * @param data      the data to digest with the given algorithm
+     * @return The digested plain text String represented as Hex digits.
+     * @throws java.security.NoSuchAlgorithmException if the desired algorithm is not supported
by
+     *                                  the MessageDigest class.
+     */
+    private static String digest(String algorithm, byte[] data)
+    throws NoSuchAlgorithmException {
+        MessageDigest md = MessageDigest.getInstance(algorithm);
+        byte[] digest = md.digest(data);
+        StringBuffer res = new StringBuffer(digest.length * 2);
+        for (int i = 0; i < digest.length; i++) {
+            byte b = digest[i];
+            res.append(hexTable[(b >> 4) & 15]);
+            res.append(hexTable[b & 15]);
+        }
+        return res.toString();
+    }
 }

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=803385&r1=803384&r2=803385&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Wed Aug 12 07:03:31 2009
@@ -225,7 +225,7 @@
         deleteBefore.add(Calendar.MINUTE, -this.cleanupPeriod);
         final String dateString = ISO8601.format(deleteBefore);
 
-        final StringBuffer buffer = new StringBuffer("/jcr:root");
+        final StringBuilder buffer = new StringBuilder("/jcr:root");
         buffer.append(this.repositoryPath);
         buffer.append("//element(*, ");
         buffer.append(getEventNodeType());
@@ -861,10 +861,32 @@
      * Create a unique node path (folder and name) for the job.
      */
     private String getNodePath(final String jobTopic, final String jobId) {
+        final StringBuilder sb = new StringBuilder(jobTopic.replace('/', '.'));
+        sb.append('/');
         if ( jobId != null ) {
-            return jobTopic.replace('/', '.') + "/" + EventHelper.filter(jobId);
+            // we create an md from the job id - we use the first 6 bytes to
+            // create sub directories
+            final String md5 = EventHelper.md5(jobId);
+            sb.append(md5.substring(0, 2));
+            sb.append('/');
+            sb.append(md5.substring(2, 4));
+            sb.append('/');
+            sb.append(md5.substring(4, 6));
+            sb.append('/');
+            sb.append(EventHelper.filter(jobId));
+        } else {
+            // create a path from the uuid - we use the first 6 bytes to
+            // create sub directories
+            final String uuid = UUID.randomUUID().toString();
+            sb.append(uuid.substring(0, 2));
+            sb.append('/');
+            sb.append(uuid.substring(2, 4));
+            sb.append('/');
+            sb.append(uuid.substring(5, 7));
+            sb.append("/Job_");
+            sb.append(uuid.substring(8, 17));
         }
-        return jobTopic.replace('/', '.') + "/Job " + UUID.randomUUID().toString();
+        return sb.toString();
     }
 
     /**
@@ -1046,7 +1068,7 @@
     private void loadJobs() {
         try {
             final QueryManager qManager = this.backgroundSession.getWorkspace().getQueryManager();
-            final StringBuffer buffer = new StringBuffer("/jcr:root");
+            final StringBuilder buffer = new StringBuilder("/jcr:root");
             buffer.append(this.repositoryPath);
             buffer.append("//element(*, ");
             buffer.append(this.getEventNodeType());
@@ -1312,7 +1334,7 @@
         try {
             s = this.createSession();
             final QueryManager qManager = s.getWorkspace().getQueryManager();
-            final StringBuffer buffer = new StringBuffer("/jcr:root");
+            final StringBuilder buffer = new StringBuilder("/jcr:root");
             buffer.append(this.repositoryPath);
             if ( topic != null ) {
                 buffer.append('/');



Mime
View raw message