Beispiel #1
0
  /**
   * Display pictures from pending list with delay between. If the list is empty it waits on the
   * pending list for new pictures.
   */
  public void run() {
    Picture picture;
    int size;

    while (true) {
      try {
        picture = null;
        synchronized (mPending) {
          if (mActive && !mPending.isEmpty()) picture = (Picture) mPending.remove(0);
          else
            try {
              mPending.wait();
            } catch (InterruptedException ie) {
              ie.printStackTrace();
            }
          size = mPending.size();
          if (mThumbelina.mReadyProgress.getMaximum() < size)
            mThumbelina.mReadyProgress.setMaximum(size);
          mThumbelina.mReadyProgress.setValue(size);
        }
        if (null != picture) {
          place(picture, true);
          if (0 != getDelay())
            try {
              sleep(getDelay());
            } catch (InterruptedException ie) {
              ie.printStackTrace();
            }
        }
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }
 /** Entry point for the control thread. */
 public void run() {
   // Debug.trace();
   while (true) {
     // Debug.trace();
     Action action;
     synchronized (jobQueue) {
       while (jobQueue.isEmpty()) {
         if (finish) {
           break;
         } else {
           try {
             // Debug.trace();
             jobQueue.wait();
             // Debug.trace();
           } catch (InterruptedException e) {
             // Debug.trace(e.toString());
           }
         }
       }
       action = (Action) jobQueue.remove(0);
     }
     try {
       // Debug.trace("Executing "+action.toString());
       action.run();
       // Debug.trace("Done executing "+action.toString());
     } catch (Exception e) {
       // Debug.trace("Exception in action : "+e.toString());
       e.printStackTrace();
     }
   }
 }
  /**
   * Returns a packet from the queue of ready packets
   *
   * @returns a <code>JdwpPacket</code> ready for processing <code>null</code> when shutting down
   */
  public JdwpPacket getPacket() {
    synchronized (_commandQueue) {
      while (_commandQueue.isEmpty()) {
        try {
          _commandQueue.wait();
        } catch (InterruptedException ie) {
          /* PacketProcessor is interrupted
          when shutting down */
          return null;
        }
      }

      return (JdwpPacket) _commandQueue.remove(0);
    }
  }
    public void run() {
      while (true) {
        synchronized (evts) {
          try {
            evts.wait(pubInterval);
          } catch (InterruptedException e) {
          }

          logTextPanel.newEvents(
              (EventBufferElement[]) evts.toArray(new EventBufferElement[evts.size()]));

          evts.clear();
        }
      }
    }
 /**
  * Returns one message from the queue.
  *
  * @return Message extracted from queue.
  */
 protected final Message getMessage() {
   synchronized (messageList) {
     while (messageList.size() == 0) {
       try {
         messageList.wait();
       } catch (Exception e) {
       }
     }
     if (messageList.size() > 0) {
       final Message message = (Message) messageList.get(0);
       messageList.remove(message);
       return message;
     }
   }
   return null;
 }
 /**
  * If this queue is not empty, then remove the next operation from the head of this queue and
  * return it. If this queue is empty (see {@link #setProcessQueries(boolean)}, then the behavior
  * of this method depends on the value of the argument. If the argument is less than or equal to
  * zero (<code>0</code>), then <code>null</code> will be returned immediately. If the argument is
  * greater than zero, then this method will wait until at least one operation has been added to
  * this queue or until the given amount of time has passed. If, at the end of that time, this
  * queue is empty, then <code>null</code> will be returned. If this queue is not empty, then the
  * first operation will be removed and returned.
  *
  * <p>Note that <code>null</code> can be returned, even if a positive timeout is given.
  *
  * <p>Note too that this method's timeout is not treated the same way as the timeout value used
  * for {@link Object#wait(long)}. In particular, it is not possible to cause this method to wait
  * for an indefinite period of time.
  *
  * @param timeout the maximum number of milliseconds to wait for an operation to be available
  *     before giving up and returning <code>null</code>
  * @return the operation that was removed from the queue
  * @throws InterruptedException if the thread on which this method is running was interrupted
  *     while it was waiting for an operation to be added to the queue
  */
 public IndexOperation dequeue(long timeout) throws InterruptedException {
   synchronized (nonQueryOperations) {
     if (nonQueryOperations.isEmpty() && (!processQueries || queryOperations.isEmpty())) {
       if (timeout <= 0L) {
         return null;
       }
       nonQueryOperations.wait(timeout);
     }
     if (!nonQueryOperations.isEmpty()) {
       return nonQueryOperations.remove(0);
     }
     if (processQueries && !queryOperations.isEmpty()) {
       return queryOperations.remove(0);
     }
     return null;
   }
 }
Beispiel #7
0
 /** Called from DD to retrieve messages DO NOT CHANGE THIS! */
 public static Hashtable<String, Object> checkOutgoingMessageHashtable() {
   if (DEBUG) System.out.println("Plugin:ChatApp:checkOutgoingMessageHashtable: start");
   Hashtable<String, Object> pd;
   // pd = plugin.checkOutgoingMessage().getHashtable();
   synchronized (queue) {
     while (queue.size() == 0) {
       try {
         queue.wait();
       } catch (Exception e) {
       }
     }
     pd = queue.remove(0).getHashtable();
   }
   if (DEBUG)
     System.out.println(
         "Plugin:ChatApp:checkOutgoingMessageHashtable: got="
             + pd); // plugin_data.PluginRequest.display(pd));
   return pd;
 }
  /**
   * M: Load the structure and body of messages not yet synced in multithread
   *
   * @param context the context
   * @param account the account we're syncing
   * @param remoteStore the Store we're working on
   * @param unsyncedMessages an array of Message's we've got headers for
   * @param toMailbox the destination mailbox we're syncing
   * @throws MessagingException
   */
  public void loadUnsyncedMessagesInMultiThread(
      Context context,
      final Account account,
      Store remoteStore,
      ArrayList<Message> unsyncedMessages,
      final Mailbox toMailbox)
      throws MessagingException {
    LogUtils.d(
        Logging.LOG_TAG, "loadUnsyncedMessagesInMultiThread message: " + unsyncedMessages.size());
    /** M: Put IMAP synchronize process into Multi-Thread, left POP3 run as used to @{ */
    mUnsyncedMessages = unsyncedMessages;

    /** M: Start {@link MAX_ACCOUNT_SYNC_THREADS} threads to synchronize Messages concurrently */
    synchronized (mUnsyncedMessages) {
      mRunningSyncThreadCount = 0;
      final int unsyncedMessagesCount = unsyncedMessages.size();
      while (unsyncedMessagesCount > mRunningSyncThreadCount
          && mRunningSyncThreadCount < MAX_ACCOUNT_SYNC_THREADS) {
        Logging.v(
            "unsyncedMessages size: "
                + unsyncedMessagesCount
                + " threadIndex: "
                + mRunningSyncThreadCount);
        MESSAGE_SYNC_THREAD_POOL.execute(
            new LoadUnsyncMessageTask(context, account, remoteStore, toMailbox));
        mRunningSyncThreadCount++;
      }
      // wait until all messages has been fetched.
      while (mRunningSyncThreadCount > 0) {
        try {
          mUnsyncedMessages.wait();
        } catch (InterruptedException e) {
          Logging.e("loadUnsyncedMessages " + e.getMessage(), e);
        }
      }
    }
    if (mMessagingException != null) {
      MessagingException me = mMessagingException;
      mMessagingException = null;
      throw me;
    }
  }
Beispiel #9
0
  // Connects to server, starts a NetThread, then waits for messages.
  public static void main(String[] args) {

    int port = -1;
    String host = null;

    if (args.length >= 3) {

      name = args[0];
      host = args[1];
      try {
        port = Integer.parseInt(args[2]);
      } catch (Exception e) {
        port = -1;
      }
    }

    if (port == (-1)) {

      io.p("What server would you like to connect to? ");
      host = io.readLine();

      io.p("What port would you like to connect on? ");
      port = io.readInt();

      if ((port < 1) || (port > 65535)) {
        io.pl("Invalid port number.");
        System.exit(1);
      }
    }

    io.pl("Connecting to " + host + ":" + port + "...");

    Socket s = null;

    try {
      s = new Socket(host, port);
    } catch (Exception e) {
      io.pl("Couldn't connect to that server.");
      UIWindow.alert(null, "Couldn't connect to that server.");
      System.exit(1);
    }

    server = new NetThread(s, al, -1);

    io.pl("Connected to server.");

    Message nameMessage = new Message(Message.SET_NAME, name, null);
    server.sendMessage(nameMessage);

    while (true) {

      synchronized (al) {
        if (haveMessages()) {

          Message m = null;

          m = al.get(0);
          al.remove(0);

          handleMessage(m);

        } else {

          try {
            al.wait();
          } catch (Exception e) {
            io.pl("An exception occurred while trying to wait for messages from the server.");
            UIWindow.alert(null, "AI Client error occurred.");
            System.exit(1);
          }
        }
      }
    }
  }