sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1755300 - in /sling/trunk/contrib/extensions/distribution/core/src: main/java/org/apache/sling/distribution/packaging/impl/ main/java/org/apache/sling/distribution/queue/ main/java/org/apache/sling/distribution/queue/impl/jobhandling/ main...
Date Fri, 05 Aug 2016 12:01:55 GMT
Author: tommaso
Date: Fri Aug  5 12:01:55 2016
New Revision: 1755300

URL: http://svn.apache.org/viewvc?rev=1755300&view=rev
Log:
SLING-5934 - added size to DistributionQueueItem

Modified:
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
    sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStream.java
    sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/packaging/impl/DistributionPackageUtils.java
Fri Aug  5 12:01:55 2016
@@ -166,7 +166,7 @@ public class DistributionPackageUtils {
      * @return a distribution queue item
      */
     public static DistributionQueueItem toQueueItem(DistributionPackage distributionPackage)
{
-        return new DistributionQueueItem(distributionPackage.getId(), distributionPackage.getInfo());
+        return new DistributionQueueItem(distributionPackage.getId(), distributionPackage.getSize(),
distributionPackage.getInfo());
     }
 
     /**

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItem.java
Fri Aug  5 12:01:55 2016
@@ -34,10 +34,17 @@ import org.apache.sling.distribution.pac
 public class DistributionQueueItem extends ValueMapDecorator implements ValueMap {
 
     private final String packageId;
+    private final long size;
 
     public DistributionQueueItem(@Nonnull String packageId, Map<String, Object> base)
{
+        this(packageId, -1, base);
+    }
+
+    public DistributionQueueItem(String id, long size, Map<String, Object> base) {
         super(base);
-        this.packageId = packageId;
+        this.packageId = id;
+        this.size = size;
+
     }
 
     @Nonnull
@@ -45,6 +52,13 @@ public class DistributionQueueItem exten
         return packageId;
     }
 
+    /**
+     * retrieve the size of the package referenced by this queue item.
+     * @return the size of the underlying package or {@code -1} if not available.
+     */
+    public long getSize() {
+        return size;
+    }
 
     @Override
     public String toString() {

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtils.java
Fri Aug  5 12:01:55 2016
@@ -18,12 +18,11 @@
  */
 package org.apache.sling.distribution.queue.impl.jobhandling;
 
+import javax.annotation.CheckForNull;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-import javax.annotation.CheckForNull;
-
 import org.apache.sling.distribution.queue.DistributionQueueEntry;
 import org.apache.sling.distribution.queue.DistributionQueueItem;
 import org.apache.sling.distribution.queue.DistributionQueueItemState;
@@ -39,12 +38,20 @@ class JobHandlingUtils {
 
     private static final String DISTRIBUTION_PACKAGE_PREFIX = "distribution.";
     private static final String DISTRIBUTION_PACKAGE_ID = DISTRIBUTION_PACKAGE_PREFIX + "item.id";
+    private static final String DISTRIBUTION_PACKAGE_SIZE = DISTRIBUTION_PACKAGE_PREFIX +
"package.size";
 
     public static DistributionQueueItem getItem(final Job job) {
 
         Map<String, Object> properties = new HashMap<String, Object>();
 
         String packageId = (String) job.getProperty(DISTRIBUTION_PACKAGE_ID);
+        Object sizeProperty = job.getProperty(DISTRIBUTION_PACKAGE_SIZE);
+        long size;
+        if (sizeProperty != null) {
+            size = Long.valueOf(sizeProperty.toString());
+        } else {
+            size = -1;
+        }
 
         try {
             Set<String> propertyNames = job.getPropertyNames();
@@ -58,7 +65,7 @@ class JobHandlingUtils {
             log.error("Cannot read job {} properties", job.getId(), t);
         }
 
-        return new DistributionQueueItem(packageId, properties);
+        return new DistributionQueueItem(packageId, size, properties);
     }
 
     public static Map<String, Object> createFullProperties(DistributionQueueItem queueItem)
{
@@ -72,6 +79,7 @@ class JobHandlingUtils {
         }
 
         properties.put(DISTRIBUTION_PACKAGE_ID, queueItem.getPackageId());
+        properties.put(DISTRIBUTION_PACKAGE_SIZE, queueItem.getSize());
 
         return properties;
     }
@@ -129,7 +137,7 @@ class JobHandlingUtils {
             return null;
         }
 
-        return itemId.replace(ID_START, "").replace("--","/");
+        return itemId.replace(ID_START, "").replace("--", "/");
     }
 
 

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/resources/impl/ExtendedDistributionServiceResourceProvider.java
Fri Aug  5 12:01:55 2016
@@ -195,6 +195,7 @@ public class ExtendedDistributionService
             DistributionPackageInfo packageInfo = DistributionPackageUtils.fromQueueItem(item);
 
             result.put("id", entry.getId());
+            result.put("size", item.getSize());
             result.put("paths", packageInfo.getPaths());
             result.put("action", packageInfo.getRequestType());
             result.put("userid", packageInfo.get(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_USER,
String.class));

Modified: sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStream.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStream.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStream.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/main/java/org/apache/sling/distribution/util/impl/FileBackedMemoryOutputStream.java
Fri Aug  5 12:01:55 2016
@@ -36,6 +36,8 @@ import java.nio.ByteBuffer;
  */
 public class FileBackedMemoryOutputStream extends OutputStream {
 
+    private int memorySize = -1;
+
     public enum MemoryUnit {
 
         BYTES(1),
@@ -117,7 +119,7 @@ public class FileBackedMemoryOutputStrea
     }
 
     public long size() {
-        long size = memory.position();
+        long size = memorySize > 0 ? memorySize : memory.position();
         if (file != null) {
             size += file.length();
         }
@@ -133,6 +135,7 @@ public class FileBackedMemoryOutputStrea
     }
 
     public InputStream openWrittenDataInputStream() throws IOException {
+        memorySize = memory.position(); // save the memory position for size calculation
as after flip() position's always 0
         memory.flip();
         return new ByteBufferBackedInputStream(memory, file);
     }

Modified: sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java?rev=1755300&r1=1755299&r2=1755300&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java
(original)
+++ sling/trunk/contrib/extensions/distribution/core/src/test/java/org/apache/sling/distribution/queue/impl/jobhandling/JobHandlingUtilsTest.java
Fri Aug  5 12:01:55 2016
@@ -43,9 +43,10 @@ public class JobHandlingUtilsTest {
 
         Map<String, Object> fullPropertiesFromPackage = JobHandlingUtils.createFullProperties(queueItem);
         assertNotNull(fullPropertiesFromPackage);
-        assertEquals(4, fullPropertiesFromPackage.size());
+        assertEquals(5, fullPropertiesFromPackage.size());
         assertNotNull(fullPropertiesFromPackage.get("distribution.request.paths"));
         assertNotNull(fullPropertiesFromPackage.get("distribution.item.id"));
+        assertNotNull(fullPropertiesFromPackage.get("distribution.package.size"));
         assertNotNull(fullPropertiesFromPackage.get("distribution.package.type"));
         assertNotNull(fullPropertiesFromPackage.get("distribution.request.type"));
     }



Mime
View raw message