Beispiel #1
0
  /** Selects on sockets and informs their Communicator when there is something to do. */
  public void communicate(int timeout) {

    try {
      selector.select(timeout);
    } catch (IOException e) {
      // Not really sure why/when this happens yet
      return;
    }

    Iterator<SelectionKey> keys = selector.selectedKeys().iterator();

    while (keys.hasNext()) {
      SelectionKey key = keys.next();
      keys.remove();
      if (!key.isValid()) continue; // WHY
      Communicator communicator = (Communicator) key.attachment();

      if (key.isReadable()) communicator.onReadable();
      if (key.isWritable()) communicator.onWritable();
      if (key.isAcceptable()) communicator.onAcceptable();
    }

    // Go through the queue and handle each communicator
    while (!queue.isEmpty()) {
      Communicator c = queue.poll();
      c.onMemo();
    }
  }
  private void runPlugin(String pluginName) {
    ConnectInfo[] friends = null;
    Plugin plugin = PluginManager.getInstance().getPlugin(pluginName);

    // get users
    if (plugin.isStandalone()) friends = new ConnectInfo[0];
    else {
      ListBox userList =
          new ListBox(
              null, plugin.getTitle(), tr("msg.selectUsers"), Client.getInstance().getUserList());
      Object[] users = userList.selectItems();
      if (users != null) {
        friends = new ConnectInfo[users.length];
        for (int i = 0; i < friends.length; i++)
          friends[i] = Communicator.getInstance().getConnectInfo((String) users[i]);
      }
    }

    // run the plugin if the user didn't click on cancel
    if (friends != null) PluginManager.getInstance().run(pluginName, friends);
  }