incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r711294 - /incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
Date Tue, 04 Nov 2008 16:20:49 GMT
Author: ryan
Date: Tue Nov  4 08:20:49 2008
New Revision: 711294

URL: http://svn.apache.org/viewvc?rev=711294&view=rev
Log:
adding concrete implementaion for WalkingDroid

Added:
    incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java

Added: incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java?rev=711294&view=auto
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
(added)
+++ incubator/droids/trunk/src/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
Tue Nov  4 08:20:49 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.droids.robot.walker;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.droids.AbstractDroid;
+import org.apache.droids.exception.InvalidTaskException;
+import org.apache.droids.impl.MultiThreadedTaskMaster;
+import org.apache.droids.impl.SimpleTaskQueue;
+import org.apache.droids.api.*;
+
+public class SimpleWalkingDroid extends AbstractDroid<FileTask> implements WalkingDroid
+{
+  private Collection<File> initialFiles;
+  
+  public SimpleWalkingDroid( TaskQueue<FileTask> queue, TaskMaster<FileTask>
taskMaster )
+  {
+    super( queue, taskMaster );
+  }
+
+  public void setInitialFiles(Collection<File> initialFiles) {
+    this.initialFiles = initialFiles;
+  }
+  
+  public void init() {
+    if( initialFiles == null || initialFiles.isEmpty() ) {
+      throw new RuntimeException( "FileSystemWalker requires at least one starting file"
);
+    }
+    try {
+      for( File file : initialFiles ) {
+        queue.merge( new FileTask( file, 0 ) );
+      }
+    } 
+    catch (InvalidTaskException e) {
+      e.printStackTrace();
+    }
+  }
+  
+  public void finished()
+  {
+    System.out.println( "FINISHED!!!" );
+  }
+
+  public FileWorker getNewWorker() {
+    return new FileWorker( queue );
+  }
+
+  //------------------------------------------------------------------
+  //------------------------------------------------------------------
+  
+  public static void main( String[] args )
+  {
+    MultiThreadedTaskMaster<FileTask> taskMaster = new MultiThreadedTaskMaster<FileTask>();
+    taskMaster.setMaxThreads( 3 );
+    
+    TaskQueue<FileTask> queue = new SimpleTaskQueue<FileTask>();
+    
+    Collection<File> files = new ArrayList<File>();
+    files.add( new File( args[0] ) ); //APACHE/droids/src" ) );
+    
+    SimpleWalkingDroid simple = new SimpleWalkingDroid( queue, taskMaster );
+    simple.setInitialFiles( files );
+    simple.init();
+    simple.start();  // TODO? perhaps start internally calls init()?
+  }
+}
+



Mime
View raw message