Ejemplo n.º 1
0
 public String dumpTimerTasks() {
   StringBuilder sb = new StringBuilder();
   for (Entry entry : tasks.values()) {
     sb.append(entry.dump()).append("\n");
   }
   return sb.toString();
 }
Ejemplo n.º 2
0
  public void run() {
    while (true) {

      try {
        // System.out.println(r+": Take(wait)");
        // String[] info = q.take();
        String blogID = q.poll(60, TimeUnit.SECONDS);
        if (blogID == null) {
          System.out.println("Poll.Timeout");
          continue;
        }

        // System.out.println(r+": Take(get) : "+blogID);

        if (blogID == NO_MORE_WORK) {
          break;
        }

        URL feedUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/comments/default");
        Query myQuery = new Query(feedUrl);
        myQuery.setMaxResults(25);

        System.out.print(r + "+,");
        Feed resultFeed = myService.query(myQuery, Feed.class);

        for (Entry entry : resultFeed.getEntries()) {
          if (entry.getAuthors().get(0).getUri() != null) {
            String profileID = entry.getAuthors().get(0).getUri().replaceAll("[^\\d]", "");
            if (profileID.length() == 20) {
              try {
                myStm.executeUpdate(
                    "INSERT IGNORE INTO author SET profileID = '" + profileID + "'");
                // System.out.print(r+"+,");
              } catch (Exception e) {
              }
            }
          }
        }

      } catch (Exception e) {
        System.out.print(r + "ERR,");
      }
    }

    System.out.println("Bye(" + r + ")");
    try {
      myStm.close();
    } catch (Exception e) {
    }
  }
Ejemplo n.º 3
0
  /**
   * Stops the timer, cancelling all tasks
   *
   * @throws InterruptedException if interrupted while waiting for thread to return
   */
  public void stop() {
    stopRunner();

    java.util.List<Runnable> remaining_tasks = pool.shutdownNow();
    for (Runnable task : remaining_tasks) {
      if (task instanceof Future) {
        Future future = (Future) task;
        future.cancel(true);
      }
    }
    pool.getQueue().clear();
    try {
      pool.awaitTermination(Global.THREADPOOL_SHUTDOWN_WAIT_TIME, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    }

    for (Entry entry : tasks.values()) entry.cancel();
    tasks.clear();
  }
Ejemplo n.º 4
0
  public Future<?> schedule(Runnable work, long delay, TimeUnit unit) {
    if (work == null) return null;

    Future<?> retval = null;

    long key =
        System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, unit); // execution time
    Entry task = new Entry(work);
    while (!isShutdown()) {
      Entry existing = tasks.putIfAbsent(key, task);
      if (existing == null) {
        retval = task.getFuture();
        break; // break out of the while loop
      }
      if ((retval = existing.add(work)) != null) break;
    }

    if (key < next_execution_time || no_tasks.compareAndSet(true, false)) {
      if (key >= next_execution_time) key = 0L;
      taskReady(key);
    }

    return retval;
  }
Ejemplo n.º 5
0
 /**
  * Returns the number of tasks currently in the timer
  *
  * @return The number of tasks currently in the timer
  */
 public int size() {
   int retval = 0;
   Collection<Entry> values = tasks.values();
   for (Entry entry : values) retval += entry.size();
   return retval;
 }