Пример #1
0
  public List search(Hashtable h, MetaSearchRequest r) {
    // create tasks
    List taskList = null;
    String dateString = (String) h.get("DATETIME");
    Date date = null;
    long waitTime = MSR_DEFAULT_DURATION_;
    try {
      waitTime = Long.valueOf((String) h.get("WAIT_TIME")).longValue() * 1000;
    } catch (Exception e) {
    }
    if (dateString != null)
      try {
        Messages.debug(-1, "MetaSearch::search before parse");
        date = RandomDate.parse(dateString);
        Messages.debug(-1, "MetaSearch::search after parse date=%1", date);
      } catch (Exception e) {
        Messages.error(TFA01_, dateString);
      }
    else Messages.error(TFA01_, dateString);

    if (date != null) {
      Thread t = Thread.currentThread();
      taskList = taskFac_.makeTasks(h, date, r);
      // take precaution that the issueing Thread is interrupted when all tasks are done
      r.registerInterrupt(t, taskList.size());
      try {
        for (Iterator e = taskList.iterator(); e.hasNext(); ) executor_.execute((Task) e.next());
        // sleep
        t.sleep(waitTime);
      } catch (InterruptedException e) {
        // if all tasks have been done, before waitTime was over
      }

      // invalidate all tasks and interrupt the corresponding threads
      for (Iterator e = taskList.iterator(); e.hasNext(); ) ((Task) e.next()).cancel();
    }
    return taskList;
  }