Esempio n. 1
0
 /**
  * Add specified socket and associated pool to the poller. The socket will be added to a
  * temporary array, and polled first after a maximum amount of time equal to pollTime (in most
  * cases, latency will be much lower, however).
  *
  * @param socket to add to the poller
  * @param interestOps Operations for which to register this socket with the Poller
  */
 public void add(final NioChannel socket, final int interestOps) {
   PollerEvent r = eventCache.pop();
   if (r == null) r = new PollerEvent(socket, null, interestOps);
   else r.reset(socket, null, interestOps);
   addEvent(r);
   if (close) {
     NioEndpoint.NioSocketWrapper ka = (NioEndpoint.NioSocketWrapper) socket.getAttachment();
     processSocket(ka, SocketEvent.STOP, false);
   }
 }
Esempio n. 2
0
 /**
  * Registers a newly created socket with the poller.
  *
  * @param socket The newly created socket
  */
 public void register(final NioChannel socket) {
   socket.setPoller(this);
   NioSocketWrapper ka = new NioSocketWrapper(socket, NioEndpoint.this);
   socket.setSocketWrapper(ka);
   ka.setPoller(this);
   ka.setReadTimeout(getSocketProperties().getSoTimeout());
   ka.setWriteTimeout(getSocketProperties().getSoTimeout());
   ka.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
   ka.setSecure(isSSLEnabled());
   ka.setReadTimeout(getSoTimeout());
   ka.setWriteTimeout(getSoTimeout());
   PollerEvent r = eventCache.pop();
   ka.interestOps(SelectionKey.OP_READ); // this is what OP_REGISTER turns into.
   if (r == null) r = new PollerEvent(socket, ka, OP_REGISTER);
   else r.reset(socket, ka, OP_REGISTER);
   addEvent(r);
 }
Esempio n. 3
0
    /**
     * Processes events in the event queue of the Poller.
     *
     * @return <code>true</code> if some events were processed, <code>false</code> if queue was
     *     empty
     */
    public boolean events() {
      boolean result = false;

      PollerEvent pe = null;
      while ((pe = events.poll()) != null) {
        result = true;
        try {
          pe.run();
          pe.reset();
          if (running && !paused) {
            eventCache.push(pe);
          }
        } catch (Throwable x) {
          log.error("", x);
        }
      }

      return result;
    }