示例#1
0
  /**
   * This is the only method exposed as the API call loads multiple configuration files from
   * specified URI an invokes a background {@link SearchAgent} callable task which in turn does the
   * action property collection from various streams. This is the method that is exposed as API
   * call.
   *
   * @params resourses String containg space separated uri where data will be extracted from.
   * @params attribute String containg space separated keywords to look for.
   * @return List class containing the loaded SearchObjectCache.
   */
  public static List<SearchObjectCache> search(String resources, String attributes, int agent)
      throws InterruptedException {
    // "crawling data sources";
    ExecutorService service = Executors.newFixedThreadPool(10);
    List<SearchObjectCache> records = new ArrayList<SearchObjectCache>();
    java.util.List<String> sources = Arrays.asList(resources.split(" "));
    List<Future<SearchObjectCache>> tasks = new ArrayList<Future<SearchObjectCache>>();
    try {

      // for(String source:sources){
      sources.stream().forEach(source -> add(service, tasks, agent, source, attributes));
      for (Future<SearchObjectCache> task : tasks) {
        records.addAll((List<SearchObjectCache>) task.get());
      }

      service.shutdown();
      service.awaitTermination(5, TimeUnit.SECONDS);

    } catch (Exception ex) {

      logger.info("error loading resources ");
      ex.printStackTrace();
      logger.log(Level.SEVERE, null, ex);

    } finally {
      if (!service.isTerminated()) {
        logger.info("Cancel non-finish tasks");
      }
      service.shutdownNow();
    }

    logger.info("Task is completed, let's check result");
    logger.info("Document search completed\n");
    return records;
  }
示例#2
0
  public static void main(String[] args) {

    SearchBroker broker = SearchBroker.newInstance();
    try {

      broker.scheduleJobs();

    } catch (Exception e) {

      System.out.println("error starting jobs..");
      e.printStackTrace();
    }
  }