/**
  * Creates a new queue entry for the given request and value
  *
  * @param request Request to enqueue
  * @param value Value requested
  * @return The given value
  */
 protected V enqueue(T request, V value) {
   synchronized (entries) {
     entries.add(new Entry(request, value));
     entries.notifyAll();
   }
   return value;
 }
Example #2
0
  @Override
  public boolean getRating(
      long userID, long itemID, long command_ID, int resultIndex, String MASTER_RMI_URL)
      throws RemoteException {

    DataModelMasterProxy masterProxy = getMasterProxy(MASTER_RMI_URL);
    if (masterProxy == null) return false;
    logger.info(
        "receive a GetRating command command_ID:"
            + command_ID
            + ",resultIndex:"
            + resultIndex
            + ",userID:"
            + userID
            + ",itemID:"
            + itemID);

    DataChangeRequest aNewDataChangeRequest = new DataChangeRequest();
    aNewDataChangeRequest.commandID = command_ID;
    aNewDataChangeRequest.itemID = itemID;
    aNewDataChangeRequest.operateCode = GET;

    aNewDataChangeRequest.receiver = masterProxy;
    aNewDataChangeRequest.resultIndex = resultIndex;
    aNewDataChangeRequest.userID = userID;
    aNewDataChangeRequest.waitAtTime = System.nanoTime();

    synchronized (waitToOperateQueue) {
      waitToOperateQueue.add(aNewDataChangeRequest);
      waitToOperateQueue.notifyAll();
    }

    return true;
  }
 /**
  * Creates new queue entries for each of the given values for the given request
  *
  * @param request Request to enqueue
  * @param values Values requested
  * @return The given values
  */
 protected Iterable<V> enqueue(T request, Iterable<V> values) {
   synchronized (entries) {
     for (V value : values) {
       entries.add(new Entry(request, value));
     }
     entries.notifyAll();
   }
   return values;
 }
 public void putBuffer(ByteBuffer buf) {
   if (buf.isDirect()) {
     buf.clear(); // 초기화 시켜준다.
     synchronized (queue) {
       queue.add(buf);
       queue.notifyAll();
     }
   }
 }
 /**
  * Enqueue job to run in pool
  *
  * @param run job to run
  * @return true if the job was added, false if it was not added due to pool being in an error
  *     state.
  */
 public boolean execute(final IORunnable run) {
   synchronized (mJobs) {
     if (mProcessJobs) { // QueueThread is still able to despool jobs
       if (!ProgramState.isAbort()) { // And pool not in error state
         mJobs.add(new RunProxy(run)); // OK to add
         mJobs.notifyAll();
         return true;
       }
     }
   }
   return false;
 }
  @Override
  public synchronized void stop(boolean join) throws InterruptedException {
    this.shallRun = false;
    while (running && join) {
      // wake the worker up
      synchronized (entries) {
        entries.notifyAll();
      }

      // wait for response
      this.wait();
    }
  }
Example #7
0
  private void performTask() throws InterruptedException {

    synchronized (queue) {
      while (queue.isEmpty()) {
        System.out.println(
            "Queue is empty. Consumer Thread("
                + Thread.currentThread().getName()
                + ")  is going to wait");
        queue.wait();
      }
      Task t = queue.remove();
      System.out.println(
          "Consumer Thread ("
              + Thread.currentThread().getName()
              + ")  has completed task: "
              + t.getTaskName());
      queue.notifyAll();
    }
  }
 /** Stops the thread pool */
 private void shutdown() {
   synchronized (mJobs) {
     mProcessJobs = false;
     mJobs.notifyAll();
   }
 }
Example #9
0
 public void addCommand(Command command) {
   synchronized (commandQueue) {
     commandQueue.push(command);
     commandQueue.notifyAll();
   }
 }
Example #10
0
 public void rcvmsg(int widget, String msg, Object... args) {
   synchronized (msgs) {
     msgs.add(new Message(widget, msg, args));
     msgs.notifyAll();
   }
 }