incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1429791 - in /incubator/droids/branches/0.2.x-cleanup/droids-walker/src: main/java/org/apache/droids/protocol/file/ main/java/org/apache/droids/walker/ test/java/org/apache/droids/walker/
Date Mon, 07 Jan 2013 13:12:20 GMT
Author: tobr
Date: Mon Jan  7 13:12:20 2013
New Revision: 1429791

URL: http://svn.apache.org/viewvc?rev=1429791&view=rev
Log:
removed Protocol
added Fetcher

Added:
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileFetcher.java
      - copied, changed from r1429330, incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/protocol/file/FileProtocol.java
Removed:
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/protocol/file/
Modified:
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileWorker.java
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/SimpleWalkingDroid.java
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/WalkingDroid.java
    incubator/droids/branches/0.2.x-cleanup/droids-walker/src/test/java/org/apache/droids/walker/WalkingDroidTest.java

Copied: incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileFetcher.java
(from r1429330, incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/protocol/file/FileProtocol.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileFetcher.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileFetcher.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/protocol/file/FileProtocol.java&r1=1429330&r2=1429791&rev=1429791&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/protocol/file/FileProtocol.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileFetcher.java
Mon Jan  7 13:12:20 2013
@@ -16,46 +16,43 @@
 * specific language governing permissions and limitations
 * under the License.
 */
-package org.apache.droids.protocol.file;
+package org.apache.droids.walker;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URI;
 
-import org.apache.droids.core.Protocol;
-import org.apache.droids.core.Task;
+import org.apache.droids.core.ContentEntity;
+import org.apache.droids.core.Fetcher;
 import org.apache.droids.walker.FileTask;
 
 /**
- * Protocol implementation for system-independent
+ * Fetcher implementation for system-independent
  * file and directory pathnames based on java.io.File.
  *
  * @version 1.0
  */
-public class FileProtocol implements Protocol {
+public class FileFetcher implements Fetcher<FileTask> {
 
     @Override
-    public String scheme() {
-        return "file://";
-    }
-
-    @Override
-    public boolean isAllowed(URI uri) {
-        File file = new File(extractLocation(uri));
+    public boolean isAllowed(FileTask task) {
+        File file = new File(extractLocation(task.getURI()));
         return file.canRead();
     }
 
     @Override
-    public Task load(URI uri) throws IOException {
-        File file = new File(extractLocation(uri));
-        return new FileTask(file);
+    public void fetch(FileTask task) throws IOException {
+        File file = new File(extractLocation(task.getURI()));
+        task.getContentEntity().setContent(new FileInputStream(task.getFile()));
+        task.getContentEntity().put(ContentEntity.CONTENT_LENGTH, file.length());
     }
 
     /**
-     * Removes the scheme from the URI to get the pathname of the file.
+     * Removes the scheme from the URI to get the path name of the file.
      *
      * @param uri The URI of the file
-     * @return The pathname of the file
+     * @return The path name of the file
      */
     private String extractLocation(URI uri) {
         String location = uri.toString();

Modified: incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileWorker.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileWorker.java?rev=1429791&r1=1429790&r2=1429791&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileWorker.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/FileWorker.java
Mon Jan  7 13:12:20 2013
@@ -49,6 +49,7 @@ public class FileWorker implements Worke
             if (logger.isDebugEnabled()) {
                 logger.debug("FILE: " + file.getAbsolutePath());
             }
+            droid.load(task);
             droid.parse(task);
             droid.handle(task);
         }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/SimpleWalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/SimpleWalkingDroid.java?rev=1429791&r1=1429790&r2=1429791&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/SimpleWalkingDroid.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/SimpleWalkingDroid.java
Mon Jan  7 13:12:20 2013
@@ -26,24 +26,14 @@ import java.io.File;
 import java.util.Collection;
 import java.util.Queue;
 
-public class SimpleWalkingDroid extends AbstractDroid<FileTask> implements WalkingDroid
{
-    private Collection<File> initialFiles;
+public class SimpleWalkingDroid extends WalkingDroid {
     private static Logger logger = LoggerFactory.getLogger(SimpleWalkingDroid.class);
 
-    public SimpleWalkingDroid() {
-
-    }
-
-    public SimpleWalkingDroid(Queue<FileTask> queue, TaskMaster<FileTask> taskMaster)
{
+    public SimpleWalkingDroid(Queue queue, TaskMaster taskMaster) {
         super(queue, taskMaster);
     }
 
     @Override
-    public void setInitialFiles(Collection<File> initialFiles) {
-        this.initialFiles = initialFiles;
-    }
-
-    @Override
     public void start() {
         Preconditions.checkState(initialFiles != null,
                 "FileSystemWalker requires at least one starting file");
@@ -55,13 +45,4 @@ public class SimpleWalkingDroid extends 
         super.start();
     }
 
-    @Override
-    public void finished() {
-        logger.info("FINISHED!!!");
-    }
-
-    @Override
-    public FileWorker getNewWorker() {
-        return new FileWorker(this);
-    }
 }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/WalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/WalkingDroid.java?rev=1429791&r1=1429790&r2=1429791&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/WalkingDroid.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-walker/src/main/java/org/apache/droids/walker/WalkingDroid.java
Mon Jan  7 13:12:20 2013
@@ -18,12 +18,32 @@ package org.apache.droids.walker;
 
 import java.io.File;
 import java.util.Collection;
+import java.util.Queue;
 
-import org.apache.droids.core.Droid;
+import org.apache.droids.core.AbstractDroid;
+import org.apache.droids.core.TaskMaster;
 
-public interface WalkingDroid extends Droid<FileTask> {
-    public void setInitialFiles(Collection<File> initialFiles);
+public abstract class WalkingDroid extends AbstractDroid<FileTask> {
+    protected Collection<File> initialFiles;
+
+    public WalkingDroid() {
+        super();
+        this.setFetcher(new FileFetcher());
+    }
+
+    public WalkingDroid(Queue queue, TaskMaster<FileTask> taskMaster) {
+        super(queue, taskMaster);
+        this.setFetcher(new FileFetcher());
+    }
+
+    public void setInitialFiles(Collection<File> initialFiles) {
+            this.initialFiles = initialFiles;
+    }
+
+    @Override
+    public FileWorker getNewWorker() {
+        return new FileWorker(this);
+    }
 
-    public FileWorker getNewWorker();
 }
 

Modified: incubator/droids/branches/0.2.x-cleanup/droids-walker/src/test/java/org/apache/droids/walker/WalkingDroidTest.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-walker/src/test/java/org/apache/droids/walker/WalkingDroidTest.java?rev=1429791&r1=1429790&r2=1429791&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-walker/src/test/java/org/apache/droids/walker/WalkingDroidTest.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-walker/src/test/java/org/apache/droids/walker/WalkingDroidTest.java
Mon Jan  7 13:12:20 2013
@@ -10,9 +10,7 @@ import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 
 import java.io.File;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.Queue;
+import java.util.*;
 
 public class WalkingDroidTest {
 
@@ -28,7 +26,11 @@ public class WalkingDroidTest {
         SimpleWalkingDroid droid = new SimpleWalkingDroid(queue, taskMaster);
         droid.setInitialFiles(initialFiles);
         droid.addParsers(new FileNameParser());
-        droid.addHandlers(new SysoutHandler());
+
+        // just output the filename
+        Set<String> validAttributes = new HashSet<String>();
+        validAttributes.add(FileNameParser.FILENAME);
+        droid.addHandlers(new SysoutHandler(validAttributes));
 
         droid.start();
 



Mime
View raw message