You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by ry...@apache.org on 2008/09/16 15:03:21 UTC

svn commit: r695859 - in /labs/droids/trunk/src: core/java/org/apache/droids/AbstractDroid.java core/java/org/apache/droids/HelloCrawler.java examples/java/org/apache/droids/examples/FileRenamerRacer.java

Author: ryan
Date: Tue Sep 16 06:03:20 2008
New Revision: 695859

URL: http://svn.apache.org/viewvc?rev=695859&view=rev
Log:
removing unused variables from AbstractDroid

Modified:
    labs/droids/trunk/src/core/java/org/apache/droids/AbstractDroid.java
    labs/droids/trunk/src/core/java/org/apache/droids/HelloCrawler.java
    labs/droids/trunk/src/examples/java/org/apache/droids/examples/FileRenamerRacer.java

Modified: labs/droids/trunk/src/core/java/org/apache/droids/AbstractDroid.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/AbstractDroid.java?rev=695859&r1=695858&r2=695859&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/AbstractDroid.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/AbstractDroid.java Tue Sep 16 06:03:20 2008
@@ -37,6 +37,13 @@
 public abstract class AbstractDroid implements Droid{
   
   protected final Log log = LogFactory.getLog(this.getClass().getCanonicalName());
+  
+  private Core core = null;
+  private ThreadPoolExecutor pool = null;
+  private ConcurrentHashMap<Long, Worker> runningWorker = null;
+  private int maxThreads = 0;
+  private Queue queue = null;
+  
   /* 
    * @see org.apache.droids.api.Droid#finishedWorker(long)
    */
@@ -53,6 +60,7 @@
           shutdownAndAwaitTermination();
           Core.threadMessage("All threads has finished.");
         } else if (getQueue().hasNext()) {
+          Core.threadMessage("filling queue... "+getPool().getActiveCount());
           for (int i = 0; i < (getMaxThreads() - getPool().getActiveCount()); i++) {
             if (!getQueue().hasNext()) {
               break;
@@ -60,6 +68,9 @@
             startWorkers();
           }
         }
+        else {
+          Core.threadMessage("queue is empty...");
+        }
       }
     }
   }
@@ -71,13 +82,10 @@
    * in the Droid and their workers)
    */
   public void run() {
-    setRunningThreads (0);
-    setTaskDate( new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System
-        .currentTimeMillis())));
-    setFreeSlots (getMaxThreads() - getRunningThreads());
-    setPool( new ThreadPoolExecutor(getFreeSlots(), getFreeSlots(), KEEP_ALIVE,
-        TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()));
-    setRunningWorker(new ConcurrentHashMap<Long, Worker>());
+    // TODO?  take a timestamp
+    this.pool = new ThreadPoolExecutor(getMaxThreads(), getMaxThreads(), KEEP_ALIVE,
+        TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
+    this.runningWorker = new ConcurrentHashMap<Long, Worker>();
     try {
       initQueue();
     } catch (DroidsException e) {
@@ -115,7 +123,6 @@
    */
   public abstract Worker getWorker() throws DroidsException;
 
-  private Core core = null;
   /* 
    * @see org.apache.droids.api.Droid#getCore()
    */
@@ -131,7 +138,6 @@
     this.core = core;
   }
 
-  private ThreadPoolExecutor pool = null;
 
   /**
    * Get our pool.
@@ -144,17 +150,6 @@
   }
 
   /**
-   * Set our pool.
-   * @param pool the new pool.
-   */
-  public void setPool(ThreadPoolExecutor pool) {
-    synchronized (this) {
-      this.pool = pool;
-    }
-  }
-
-  private ConcurrentHashMap<Long, Worker> runningWorker = null;
-  /**
    * Return the map of running workers
    * @return map of running workers
    */
@@ -164,78 +159,6 @@
     }
   }
 
-  /**
-   * Set the map of running workers
-   * @param runningWorker new map of running workers
-   */
-  public void setRunningWorker(ConcurrentHashMap<Long, Worker> runningWorker) {
-    this.runningWorker = runningWorker;
-  }
-
-  private int runningThreads = 0;
-  /**
-   * To set the number of running threads.
-   * @param runningThreads
-   */
-  public void setRunningThreads(int runningThreads) {
-    this.runningThreads = runningThreads;
-  }
-
-  /**
-   * Get number of currently running threads
-   * @return number of currently running threads
-   */
-  public int getRunningThreads() {
-    return runningThreads;
-  }
-
-  private String taskDate = "";
-
-  /**
-   * When did the task showed up the first time in the queue
-   * 
-   * @return the date when the task registered with the queue
-   */
-  public String getTaskDate() {
-    return taskDate;
-  }
-
-  /**
-   * When did the task showed up the first time in the queue
-   * 
-   * @param taskDate the date when the task registered with the queue
-   */
-  public void setTaskDate(String taskDate) {
-    synchronized (this) {
-      this.taskDate = taskDate;
-    }
-  }
-  
-  private int freeSlots=0;
-
-  /**
-   * Get number of slots that we have currently
-   * open to accept new workers.
-   * @return number of slots that are waiting to serve
-   */
-  public int getFreeSlots() {
-    synchronized (this) {
-      return freeSlots;
-    }
-  }
-
-  /**
-   * Set number of slots that we have currently
-   * open to accept new workers 
-   * @param freeSlots number of slots that are waiting to serve
-   */
-  public void setFreeSlots(int freeSlots) {
-    synchronized (this) {
-      this.freeSlots = freeSlots;
-    }
-  }
-
-  private int maxThreads = 0;
 
   /**
    * Adjust number of allowed threads
@@ -255,7 +178,6 @@
     return maxThreads;
   }
 
-  private Queue queue = null;
   /* 
    * @see org.apache.droids.api.Droid#setQueue(Queue)
    */
@@ -274,6 +196,15 @@
       return queue;
     }
   }
+  
+  /**
+   * Utility function to get a new task date... this should go somewhere else
+   */
+  public static String getNewTaskDate()
+  {
+    return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date(System
+        .currentTimeMillis()));
+  }
 
   /**
    * Shutdown all threads, close the pools and leave.

Modified: labs/droids/trunk/src/core/java/org/apache/droids/HelloCrawler.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/core/java/org/apache/droids/HelloCrawler.java?rev=695859&r1=695858&r2=695859&view=diff
==============================================================================
--- labs/droids/trunk/src/core/java/org/apache/droids/HelloCrawler.java (original)
+++ labs/droids/trunk/src/core/java/org/apache/droids/HelloCrawler.java Tue Sep 16 06:03:20 2008
@@ -41,7 +41,7 @@
    */
   public void initQueue() throws DroidsException{
     synchronized (this) {
-      QueueLink initialLink = new QueueLink(url, getTaskDate(), 0);
+      QueueLink initialLink = new QueueLink(url, AbstractDroid.getNewTaskDate(), 0);
       getQueue().init(new Task[] { initialLink });
     }
   }

Modified: labs/droids/trunk/src/examples/java/org/apache/droids/examples/FileRenamerRacer.java
URL: http://svn.apache.org/viewvc/labs/droids/trunk/src/examples/java/org/apache/droids/examples/FileRenamerRacer.java?rev=695859&r1=695858&r2=695859&view=diff
==============================================================================
--- labs/droids/trunk/src/examples/java/org/apache/droids/examples/FileRenamerRacer.java (original)
+++ labs/droids/trunk/src/examples/java/org/apache/droids/examples/FileRenamerRacer.java Tue Sep 16 06:03:20 2008
@@ -37,7 +37,7 @@
       File[] list = target.listFiles();
       LinkedHashSet<QueueLink> set = new LinkedHashSet<QueueLink>();
       for (File file : list) {
-        QueueLink link = new QueueLink(file.getAbsolutePath(), getTaskDate(), 0);
+        QueueLink link = new QueueLink(file.getAbsolutePath(), AbstractDroid.getNewTaskDate(), 0);
         set.add(link);
       }
       QueueLink[] outlinks = new QueueLink[0];



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org