SLING-4153: adding distributor type and making DistributionRequest and interface

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1645598 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java b/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java
index 8b62cf3..3a7a575 100644
--- a/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java
+++ b/src/main/java/org/apache/sling/distribution/agent/DistributionAgent.java
@@ -62,12 +62,12 @@
      * The content to be sent will be assembled according to the information contained in the request.
      * A {@link org.apache.sling.distribution.communication.DistributionResponse} holding the {@link org.apache.sling.distribution.communication.DistributionRequestState}
      * of the provided request will be returned.
-     * Synchronous {@link org.apache.sling.distribution.agent.DistributionAgent}s will usally block until the execution has finished
+     * Synchronous {@link org.apache.sling.distribution.agent.DistributionAgent}s will usually block until the execution has finished
      * while asynchronous agents will usually return the response as soon as the content to be distributed has been assembled
      * and scheduled for distribution.
      *
      * @param distributionRequest the distribution request
-     * @param resourceResolver    the resource resolver used for authenticating the request,
+     * @param resourceResolver    the resource resolver used for authorizing the request,
      * @return a {@link org.apache.sling.distribution.communication.DistributionResponse}
      * @throws DistributionAgentException if any error happens during the execution of the request or if the authentication fails
      */
diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java b/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java
deleted file mode 100644
index 38bf2e5..0000000
--- a/src/main/java/org/apache/sling/distribution/communication/DistributionParameter.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.sling.distribution.communication;
-
-/**
- * HTTP Parameters for distribution
- */
-public enum DistributionParameter {
-
-    QUEUE("queue"),
-    TYPE("type"),
-    ACTION("action"),
-    PATH("path"),
-    DEEP("deep");
-
-    private final String name;
-
-    DistributionParameter(String name) {
-        this.name = name;
-    }
-
-    @Override
-    public String toString() {
-        return name;
-    }
-}
diff --git a/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java b/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java
index 107139a..331803c 100644
--- a/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java
+++ b/src/main/java/org/apache/sling/distribution/communication/DistributionRequest.java
@@ -25,69 +25,31 @@
  * A {@link org.apache.sling.distribution.communication.DistributionRequest} represents the need from the caller to have
  * some content being distributed from a source instance to a target instance.
  */
-public final class DistributionRequest {
+public interface DistributionRequest {
 
 
-    private final DistributionRequestType requestType;
-
-    private final boolean deep;
-    private final String[] paths;
-
-    /**
-     * Creates distribution request with "deep" or "shallow" paths.
-     * @param requestType the request type
-     * @param isDeep is <code>true</code> if all paths are "deep" and is <code>false</code> if all paths are "shallow"
-     * @param paths the array of paths to be distributed
-     */
-    public DistributionRequest(@Nonnull DistributionRequestType requestType, boolean isDeep, @Nonnull String... paths) {
-        this.requestType = requestType;
-        deep = isDeep;
-        this.paths = paths;
-    }
-
-    /**
-     * Creates a distribution request with "shallow" paths.
-     * @param requestType the request type
-     * @param paths the array of paths to be distributed
-     */
-    public DistributionRequest(@Nonnull DistributionRequestType requestType, @Nonnull String... paths) {
-        this(requestType, false, paths);
-    }
-
     /**
      * get the {@link DistributionRequestType} associated with this request
      *
      * @return the type of the request as a {@link DistributionRequestType}
      */
-    public DistributionRequestType getRequestType() {
-        return requestType;
-    }
+    public DistributionRequestType getRequestType();
 
     /**
      * get the paths for this distribution request
      *
      * @return an array of paths
      */
-    public String[] getPaths() {
-        return paths;
-    }
+    public String[] getPaths();
 
 
     /**
      * Returns whether the paths are covering the entire subtree (deep) or just the specified nodes (shallow)
+     *
+     * @param path the path to be checked
      * @return <code>true</code> if the paths are deep
      */
-    public boolean isDeep() {
-        return deep;
-    }
-
-    @Override
-    public String toString() {
-        return "DistributionRequest{" +
-                ", requestType=" + requestType +
-                ", paths=" + Arrays.toString(paths) +
-                '}';
-    }
+    public boolean isDeep(String path);
 
 
 }
diff --git a/src/main/java/org/apache/sling/distribution/communication/Distributor.java b/src/main/java/org/apache/sling/distribution/communication/Distributor.java
new file mode 100644
index 0000000..376b22c
--- /dev/null
+++ b/src/main/java/org/apache/sling/distribution/communication/Distributor.java
@@ -0,0 +1,29 @@
+package org.apache.sling.distribution.communication;
+
+import aQute.bnd.annotation.ProviderType;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.distribution.agent.DistributionAgentException;
+
+import javax.annotation.Nonnull;
+
+@ProviderType
+public interface Distributor {
+    /**
+     * Perform a {@link org.apache.sling.distribution.communication.DistributionRequest} to distribute content from a source
+     * instance to a target instance.
+     * The content to be sent will be assembled according to the information contained in the request.
+     * A {@link org.apache.sling.distribution.communication.DistributionResponse} holding the {@link org.apache.sling.distribution.communication.DistributionRequestState}
+     * of the provided request will be returned.
+     * Synchronous {@link org.apache.sling.distribution.agent.DistributionAgent}s will usually block until the execution has finished
+     * while asynchronous agents will usually return the response as soon as the content to be distributed has been assembled
+     * and scheduled for distribution.
+     *
+     * @param agentName the name of the agent used to distribute the request
+     * @param distributionRequest the distribution request
+     * @param resourceResolver    the resource resolver used for authorizing the request,
+     * @return a {@link org.apache.sling.distribution.communication.DistributionResponse}
+     */
+    DistributionResponse distribute(@Nonnull String agentName, @Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest);
+
+
+}
diff --git a/src/main/java/org/apache/sling/distribution/communication/SimpleDistributionRequest.java b/src/main/java/org/apache/sling/distribution/communication/SimpleDistributionRequest.java
new file mode 100644
index 0000000..98e092e
--- /dev/null
+++ b/src/main/java/org/apache/sling/distribution/communication/SimpleDistributionRequest.java
@@ -0,0 +1,92 @@
+/*
+ * 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.sling.distribution.communication;
+
+import javax.annotation.Nonnull;
+import java.util.Arrays;
+
+/**
+ * A {@link SimpleDistributionRequest} is a {@link DistributionRequest} where all paths are either "deep" or "shallow".
+ */
+public final class SimpleDistributionRequest implements DistributionRequest {
+
+
+    private final DistributionRequestType requestType;
+
+    private final boolean deep;
+    private final String[] paths;
+
+    /**
+     * Creates distribution request with "deep" or "shallow" paths.
+     * @param requestType the request type
+     * @param isDeep is <code>true</code> if all paths are "deep" and is <code>false</code> if all paths are "shallow"
+     * @param paths the array of paths to be distributed
+     */
+    public SimpleDistributionRequest(@Nonnull DistributionRequestType requestType, boolean isDeep, @Nonnull String... paths) {
+        this.requestType = requestType;
+        deep = isDeep;
+        this.paths = paths;
+    }
+
+    /**
+     * Creates a distribution request with "shallow" paths.
+     * @param requestType the request type
+     * @param paths the array of paths to be distributed
+     */
+    public SimpleDistributionRequest(@Nonnull DistributionRequestType requestType, @Nonnull String... paths) {
+        this(requestType, false, paths);
+    }
+
+    /**
+     * get the {@link DistributionRequestType} associated with this request
+     *
+     * @return the type of the request as a {@link DistributionRequestType}
+     */
+    public DistributionRequestType getRequestType() {
+        return requestType;
+    }
+
+    /**
+     * get the paths for this distribution request
+     *
+     * @return an array of paths
+     */
+    public String[] getPaths() {
+        return paths;
+    }
+
+
+    /**
+     * Returns whether the a path is covering the entire subtree (deep) or just the specified nodes (shallow)
+     * @return <code>true</code> if the path is deep
+     */
+    public boolean isDeep(String path) {
+        return deep;
+    }
+
+    @Override
+    public String toString() {
+        return "DistributionRequest{" +
+                ", requestType=" + requestType +
+                ", paths=" + Arrays.toString(paths) +
+                '}';
+    }
+
+
+}
diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java
index a77b140..7db554f 100644
--- a/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java
+++ b/src/main/java/org/apache/sling/distribution/queue/DistributionQueue.java
@@ -84,19 +84,19 @@
     /**
      * get all the items in the queue
      *
-     * @param queueItemSelector represents the criteria to filter queue items.
-     *                          if null is passed then all items are returned.
+     * @param skip the number of items to skip
+     * @param limit the maximum number of items to return. use -1 to return all items.
      * @return a {@link java.lang.Iterable} of {@link DistributionQueueItem}s
      */
     @Nonnull
-    Iterable<DistributionQueueItem> getItems(@Nullable DistributionQueueItemSelector queueItemSelector);
+    Iterable<DistributionQueueItem> getItems(int skip, int limit);
 
     /**
      * remove an item from the queue by specifying its id
      *
-     * @param id an item's identifier
+     * @param packageId the id of the package represented by the item
      * @return the removed item, or {@code null} if the item with the given id
      * doesn't exist
      */
-    DistributionQueueItem remove(@Nonnull String id);
+    DistributionQueueItem remove(@Nonnull String packageId);
 }
diff --git a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java b/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java
deleted file mode 100644
index e52c863..0000000
--- a/src/main/java/org/apache/sling/distribution/queue/DistributionQueueItemSelector.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.sling.distribution.queue;
-
-/**
- * Class representing criteria for queue items selection.
- */
-public class DistributionQueueItemSelector {
-    private final int skip;
-    private final int limit;
-
-    /**
-     *
-     * @param skip the number of items to skip
-     * @param limit the maximum number of items to return. use -1 to return all items.
-     */
-    public DistributionQueueItemSelector(int skip, int limit) {
-        this.skip = skip;
-        this.limit = limit;
-    }
-
-    /**
-     * @return the number of items to skip from the queue.
-     */
-    public int getSkip() {
-        return skip;
-    }
-
-    /**
-     *
-     * @return return the maximum number of items to be selected.
-     */
-    public int getLimit() {
-        return limit;
-    }
-}