incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1479608 - in /sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl: dea/DistributedEventSender.java jobs/JobImpl.java jobs/JobManagerImpl.java jobs/timed/TimedEventSender.java support/ResourceHelper.java
Date Mon, 06 May 2013 15:43:58 GMT
Author: cziegeler
Date: Mon May  6 15:43:55 2013
New Revision: 1479608

URL: http://svn.apache.org/r1479608
Log:
SLING-2829 : Provide better error message if a job/event/timed job can't be read from the
repository

Modified:
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java?rev=1479608&r1=1479607&r2=1479608&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/dea/DistributedEventSender.java
Mon May  6 15:43:55 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.event.impl.dea;
 
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -118,7 +119,9 @@ public class DistributedEventSender
             final String topic = vm.get(EventConstants.EVENT_TOPIC, String.class);
             final Map<String, Object> properties = ResourceHelper.cloneValueMap(vm);
             // only send event if there are no read errors, otherwise discard it
-            if ( properties.get(ResourceHelper.PROPERTY_MARKER_READ_ERROR) == null ) {
+            @SuppressWarnings("unchecked")
+            final List<Exception> readErrorList = (List<Exception>) properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR_LIST);
+            if ( readErrorList == null ) {
                 properties.remove(EventConstants.EVENT_TOPIC);
 
                 try {
@@ -137,6 +140,10 @@ public class DistributedEventSender
                     // but you never know)
                     logger.error("Unable to read event: " + iae.getMessage(), iae);
                 }
+            } else {
+                for(final Exception e : readErrorList) {
+                    logger.warn("Unable to read distributed event from " + eventResource.getPath(),
e);
+                }
             }
         } catch (final InstantiationException ie) {
             // something happened with the resource in the meanitime

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java?rev=1479608&r1=1479607&r2=1479608&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobImpl.java
Mon May  6 15:43:55 2013
@@ -19,6 +19,7 @@
 package org.apache.sling.event.impl.jobs;
 
 import java.util.Calendar;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -52,7 +53,7 @@ public class JobImpl implements Job {
 
     private final boolean isBridgedEvent;
 
-    private final boolean hasReadError;
+    private final List<Exception> readErrorList;
 
     /**
      * Create a new job instance
@@ -62,6 +63,7 @@ public class JobImpl implements Job {
      * @param jobId The unique (internal) job id
      * @param properties Non-null map of properties, at least containing {@link #PROPERTY_RESOURCE_PATH}
      */
+    @SuppressWarnings("unchecked")
     public JobImpl(final String topic,
                    final String name,
                    final String jobId,
@@ -71,7 +73,7 @@ public class JobImpl implements Job {
         this.jobId = jobId;
         this.path = (String)properties.remove(PROPERTY_RESOURCE_PATH);
         this.isBridgedEvent = properties.remove(PROPERTY_BRIDGED_EVENT) != null;
-        this.hasReadError = properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR)
!= null;
+        this.readErrorList = (List<Exception>) properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR_LIST);
 
         this.properties = new ValueMapDecorator(properties);
     }
@@ -94,7 +96,7 @@ public class JobImpl implements Job {
      * Did we have read errors?
      */
     public boolean hasReadErrors() {
-        return this.hasReadError;
+        return this.readErrorList != null;
     }
 
     /**

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java?rev=1479608&r1=1479607&r2=1479608&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/JobManagerImpl.java
Mon May  6 15:43:55 2013
@@ -497,6 +497,13 @@ public class JobManagerImpl
                     jobProperties.put(Job.PROPERTY_JOB_RETRY_COUNT, vm.get(Job.PROPERTY_JOB_RETRY_COUNT,
Integer.class));
                     jobProperties.put(Job.PROPERTY_JOB_PRIORITY, JobPriority.valueOf(vm.get(Job.PROPERTY_JOB_PRIORITY,
JobPriority.NORM.name())));
 
+                    @SuppressWarnings("unchecked")
+                    final List<Exception> readErrorList = (List<Exception>) jobProperties.get(ResourceHelper.PROPERTY_MARKER_READ_ERROR_LIST);
+                    if ( readErrorList != null ) {
+                        for(final Exception e : readErrorList) {
+                            logger.warn("Unable to read job from " + resource.getPath(),
e);
+                        }
+                    }
                     job = new JobImpl(topic,
                             (String)jobProperties.get(JobUtil.PROPERTY_JOB_NAME),
                             (String)jobProperties.get(JobUtil.JOB_ID),

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java?rev=1479608&r1=1479607&r2=1479608&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/timed/TimedEventSender.java
Mon May  6 15:43:55 2013
@@ -542,7 +542,14 @@ public class TimedEventSender
                     result.hasReadErrors = true;
                     return result;
                 }
-                result.hasReadErrors = properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR)
!= null;
+                @SuppressWarnings("unchecked")
+                final List<Exception> readErrorList = (List<Exception>) properties.remove(ResourceHelper.PROPERTY_MARKER_READ_ERROR_LIST);
+                result.hasReadErrors = readErrorList != null;
+                if ( readErrorList != null ) {
+                    for(final Exception e : readErrorList) {
+                        logger.warn("Unable to read timed event job from " + eventResource.getPath(),
e);
+                    }
+                }
                 properties.remove(EventConstants.EVENT_TOPIC);
                 properties.put(TimedEventStatusProvider.PROPERTY_EVENT_ID, topic.replace('/',
'.') + '/' + eventResource.getName());
 

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java?rev=1479608&r1=1479607&r2=1479608&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
(original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/support/ResourceHelper.java
Mon May  6 15:43:55 2013
@@ -18,10 +18,14 @@
  */
 package org.apache.sling.event.impl.support;
 
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.api.resource.PersistenceException;
@@ -125,10 +129,10 @@ public abstract class ResourceHelper {
         return sb.toString();
     }
 
-    public static final String PROPERTY_MARKER_READ_ERROR = ResourceHelper.class.getName()
+ "/ReadError";
+    public static final String PROPERTY_MARKER_READ_ERROR_LIST = ResourceHelper.class.getName()
+ "/ReadErrorList";
 
     public static Map<String, Object> cloneValueMap(final ValueMap vm) throws InstantiationException
{
-        boolean hasReadError = false;
+        List<Exception> hasReadError = null;
         try {
             final Map<String, Object> result = new HashMap<String, Object>(vm);
             for(final Map.Entry<String, Object> entry : result.entrySet()) {
@@ -137,12 +141,36 @@ public abstract class ResourceHelper {
                     if ( value != null ) {
                         entry.setValue(value);
                     } else {
-                        hasReadError = true;
+                        if ( hasReadError == null ) {
+                            hasReadError = new ArrayList<Exception>();
+                        }
+                        final int count = hasReadError.size();
+                        // let's find out which class might be missing
+                        ObjectInputStream ois = null;
+                        try {
+                            ois = new ObjectInputStream((InputStream)entry.getValue());
+                            ois.readObject();
+                        } catch (final ClassNotFoundException cnfe) {
+                             hasReadError.add(new Exception("Unable to deserialize property
'" + entry.getKey() + "'", cnfe));
+                        } catch (final IOException ioe) {
+                            hasReadError.add(new Exception("Unable to deserialize property
'" + entry.getKey() + "'", ioe));
+                        } finally {
+                            if ( ois != null ) {
+                                try {
+                                    ois.close();
+                                } catch (IOException ignore) {
+                                    // ignore
+                                }
+                            }
+                        }
+                        if ( hasReadError.size() == count ) {
+                            hasReadError.add(new Exception("Unable to deserialize property
'" + entry.getKey() + "'"));
+                        }
                     }
                 }
             }
-            if ( hasReadError ) {
-                result.put(PROPERTY_MARKER_READ_ERROR, Boolean.TRUE);
+            if ( hasReadError != null ) {
+                result.put(PROPERTY_MARKER_READ_ERROR_LIST, hasReadError);
             }
             return result;
         } catch ( final IllegalArgumentException iae) {



Mime
View raw message