npeltier commented on a change in pull request #4: SLING-7707 Create Executor 
Pipe
URL: 
https://github.com/apache/sling-org-apache-sling-pipes/pull/4#discussion_r195354736
 
 

 ##########
 File path: src/main/java/org/apache/sling/pipes/internal/ThreadedPipe.java
 ##########
 @@ -0,0 +1,184 @@
+/*
+ * 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.pipes.internal;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.NonExistingResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.pipes.OutputWriter;
+import org.apache.sling.pipes.Pipe;
+import org.apache.sling.pipes.PipeBindings;
+import org.apache.sling.pipes.Plumber;
+import org.apache.sling.pipes.SuperPipe;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This pipe executes the pipes it has in its configuration, in sequence or 
parallel;
+ * the output of the children pipes is merged;
+ * if execution is parallel, merge ordering is random;
+ * duplicate resources are kept in the output
+ */
+public class ThreadedPipe extends SuperPipe {
+    private static final Logger log = 
LoggerFactory.getLogger(ThreadedPipe.class);
+
+    public static final String RESOURCE_TYPE = "slingPipes/executor";
+    private static final String PN_QUEUE_SIZE = "queueSize";
+    private static final String PN_NUM_THREADS = "numThreads";
+
+    private int numThreads;
+    private ArrayBlockingQueue<Resource> outputQueue;
+
+    /**
+     * Constructor
+     * @param plumber plumber
+     * @param resource container's configuration resource
+     * @param upperBindings pipe bindings
+     * @throws Exception bad configuration handling
+     */
+    public ThreadedPipe(Plumber plumber, Resource resource, PipeBindings 
upperBindings) throws Exception{
+        super(plumber, resource, upperBindings);
+        int queueSize = properties.get(PN_QUEUE_SIZE, 10000);
+        numThreads = properties.get(PN_NUM_THREADS, 5);
+        outputQueue = new ArrayBlockingQueue<>(queueSize);
+    }
+
+    @Override
+    public void buildChildren() throws Exception {
+        for (Iterator<Resource> childPipeResources = 
getConfiguration().listChildren(); childPipeResources.hasNext();){
+            Resource pipeResource = childPipeResources.next();
+            Pipe pipe = plumber.getPipe(pipeResource, bindings);
+            if (pipe == null) {
+                log.error("configured pipe {} is either not registered, or not 
computable by the plumber", pipeResource.getPath());
+            } else {
+                pipe.setParent(this.getParent());
+                subpipes.add(pipe);
+            }
+        }
+    }
+
+    @Override
+    protected Iterator<Resource> computeSubpipesOutput() throws Exception {
+        return new ConcurrentIterator(numThreads);
+    }
+
+    private class PipeThread implements Runnable {
+
+        Pipe pipe;
+
+        PipeThread(Pipe pipe) {
+            this.pipe = pipe;
+        }
+
+        @Override
+        public void run() {
+            try {
+                
plumber.execute(pipe.getResource().getResourceResolver().clone(null), pipe, 
null, new ThreadOutputWriter(), true);
 
 Review comment:
   As discussed offline, we should support APIs that would work with AEM 6.3+ 
   - either add plumber ```executeFork``` 
   - or ```cloneResolver```  
   api

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to