private WorkQueue buildNDependentTasks(int n) {
   final AtomicInteger sharedLock = new AtomicInteger(0);
   WorkQueue queue = new WorkQueue();
   for (int i = 0; i < n; i++) {
     queue.add(lockNThreadsTask(sharedLock, n));
   }
   return queue;
 }
  /** This method uses JAX-RS 2 {@link AsyncResponse} response capability. */
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public void /* Yes it returns void */ asyncQueue(
      @BeanParam final CommonQueryProvider t, @Suspended final AsyncResponse asyncResponse) {
    if (GET_PROBE.hit()) {
      System.out.println("GET TPS: " + GET_PROBE.getLastInvocationCount());
    }

    Work work =
        new Work(
            UUID.randomUUID().toString(),
            "work-payload",
            new CompletionCallback() {
              @Override
              public void onSuccess(Result result) {
                asyncResponse.resume(result.toString());
              }

              @Override
              public void onFailure(Result result, Exception e, CompletionStatus sttaus) {
                asyncResponse.resume(e);
              }
            });

    QUEUE.add(work);
  }
Пример #3
0
 /** adds a file or many files depending on the value of singleSelection */
 public void showFileChooserAndAddFiles(boolean singleSelection) {
   if (panel.getMainTable().getModel().getRowCount() >= panel.getMaxSelectableFiles()) {
     JOptionPane.showMessageDialog(
         panel,
         GettextResource.gettext(
             Configuration.getInstance().getI18nResourceBundle(),
             "Selection table is full, please remove some pdf document."),
         GettextResource.gettext(
             Configuration.getInstance().getI18nResourceBundle(), "Table full"),
         JOptionPane.INFORMATION_MESSAGE);
   } else {
     if (singleSelection) {
       fileChooser.setMultiSelectionEnabled(false);
     } else {
       fileChooser.setMultiSelectionEnabled(true);
     }
     if (!(workQueue.getRunning() > 0)) {
       if (fileChooser.showOpenDialog(panel) == JFileChooser.APPROVE_OPTION) {
         if (fileChooser.isMultiSelectionEnabled()) {
           addFiles(fileChooser.getSelectedFiles(), true);
         } else {
           addFile(fileChooser.getSelectedFile());
         }
       }
     } else {
       log.info(
           GettextResource.gettext(
               Configuration.getInstance().getI18nResourceBundle(),
               "Please wait while all files are processed.."));
     }
   }
 }
Пример #4
0
 /**
  * reload a file to the selectionTable
  *
  * @param file input file
  * @param password password
  * @param pageSelection page selection
  */
 public synchronized void reloadFile(File file, String password, String pageSelection, int index) {
   if (file != null) {
     workQueue.execute(
         new ReloadThread(file, password, pageSelection, index),
         (file.length() < (LOW_PRIORITY_SIZE)) ? WorkQueue.HIGH : WorkQueue.LOW);
   }
 }
Пример #5
0
 /**
  * adds files to the selectionTable
  *
  * @param files
  * @param ordered files are added keeping order
  */
 public synchronized void addFiles(File[] files, boolean ordered) {
   if (files != null) {
     for (int i = 0; i < files.length; i++) {
       Integer priority =
           (ordered)
               ? WorkQueue.SINGLE
               : (files[i].length() < (LOW_PRIORITY_SIZE)) ? WorkQueue.HIGH : WorkQueue.LOW;
       workQueue.execute(new AddThread(files[i]), priority);
     }
   }
 }
  @PUT
  @Consumes(MediaType.TEXT_PLAIN)
  @Path("/sql")
  public void submit(String sql, @Suspended final AsyncResponse response) {

    if (PUT_PROBE.hit()) {
      System.err.println("PUT TPS: " + PUT_PROBE.getLastInvocationCount());
    }

    final long time = System.currentTimeMillis();
    ApplicationContext applicationContext = SpringContextLoader.getContext();
    WorkQueue jdbcBatchQueue = (WorkQueue) applicationContext.getBean("batchUpdateQueue");

    Work work =
        new Work(
            UUID.randomUUID().toString(),
            new String[] {sql},
            new CompletionCallback() {
              @Override
              public void onSuccess(Result result) {
                response.resume(
                    "Result received in "
                        + (System.currentTimeMillis() - time)
                        + "ms: "
                        + result.toString());
              }

              @Override
              public void onFailure(Result result, Exception e, CompletionStatus status) {
                e.printStackTrace();
                response.resume(e);
              }
            });

    jdbcBatchQueue.add(work);
  }
Пример #7
0
  /**
   * Search the query file to find the query words and add them in to an array list.
   *
   * @param filename : file of queries
   */
  public void search(String filename, InvertedIndex index) {
    Path file = Paths.get(filename);

    try (BufferedReader reader = Files.newBufferedReader(file, Charset.forName("UTF-8"))) {
      String parseWord;
      while ((parseWord = reader.readLine()) != null) {
        lock.acquireWriteLock();
        map.put(parseWord, null);
        lock.releaseWriteLock();
        workers.execute(new Searcher(parseWord, index));
      }
      finish();
    } catch (IOException e) {
      System.out.println("The file " + filename + " could not be read.");
    }
  }
Пример #8
0
 public void run() {
   try {
     while (true) {
       // Retrieve some work; block if the queue is empty
       Object x = q.getWork();
       // Terminate if the end-of-stream marker was retrieved
       if (x == NO_MORE_WORK) {
         break;
       }
       // Compute the square of x
       int y = ((Long) x).intValue() * ((Long) x).intValue();
       System.out.println("Square of [" + x + "] = [" + y + "]");
     }
   } catch (InterruptedException e) {
   }
 }
Пример #9
0
 /** Shuts down */
 public void shutdown() {
   log.debug("Shutting down");
   finish();
   workers.shutdown();
 }
 /** Communicate by executing items on the work queue */
 @Override
 protected void communicate(final Session session) throws Exception {
   queue.performQueuedCommands(WORKER_DELAY);
 }
 /**
  * Add task to the work queue of the JMS communication thread.
  *
  * @param task Task that will be executed by the communication thread.
  * @see Executor
  */
 @Override
 public void execute(final Runnable task) {
   queue.execute(task);
 }
Пример #12
0
 /** @return number of running threads */
 public int getRunningThreadsNumber() {
   return workQueue.getRunning();
 }
Пример #13
0
 /**
  * add a file to the selectionTable
  *
  * @param file input file
  * @param password password
  * @param pageSelection page selection
  */
 public synchronized void addFile(File file, String password, String pageSelection) {
   if (file != null) {
     workQueue.execute(new AddThread(file, password, pageSelection), WorkQueue.SINGLE);
   }
 }