Package rabbit.io

Examples of rabbit.io.HandlerRegistration


  unregister ();
  listener.finishedRead ();
    }

    public void register () {
  HandlerRegistration hr = new HandlerRegistration (this);
  SocketChannel c = wc.getChannel ();
  try {
      sk = c.register (selector, SelectionKey.OP_READ, hr);
  } catch (IOException e) {
      listener.failed (e);
View Full Code Here


    ssc.socket ().bind (new InetSocketAddress (port));
    accepting = true;
    selector = Selector.open ();
    Acceptor acceptor =
        new Acceptor (acceptorId++, this, selector);
    HandlerRegistration hr =
        new HandlerRegistration (acceptor, Long.MAX_VALUE);
    ssc.register (selector, SelectionKey.OP_ACCEPT, hr);
      } catch (IOException e) {
    logger.logFatal ("Failed to open serversocket on port " +
         port);
    stop ();
View Full Code Here

  for (SelectionKey sk : selector.keys ()) {
      Object a = sk.attachment ();
      if (a instanceof String) {
    // ignore, this is used for status.
      } else {
    HandlerRegistration hr = (HandlerRegistration)a;
    if (hr != null && now - hr.when > 60 * 1000) {
        cancelKeyAndCloseChannel (sk);
        hr.handler.timeout ();
    }
      }
View Full Code Here

  Set<SelectionKey> selected = selector.selectedKeys ();
  for (Iterator<SelectionKey> i = selected.iterator (); i.hasNext (); ) {
      SelectionKey sk = i.next ();
      Object a = sk.attachment ();
      if (a != null && a instanceof HandlerRegistration) {
    HandlerRegistration hr = (HandlerRegistration)a;
    if (hr != null && hr.handler != null)
        handle (sk, hr.handler);
      } else if (a == null) {
    logger.logWarn ("No handler for:" + sk);
      } else {
View Full Code Here

    protected void waitForRead () {
  if (buffer.remaining () > 0)
      readStartPos = buffer.position ();
  SocketHandler sh = new Reader ();
  HandlerRegistration hr = new HandlerRegistration (sh)
  SocketChannel c = con.getChannel ();
  try {
      sk = c.register (con.getSelector (), SelectionKey.OP_READ, hr);
  } catch (IOException e) {
      listener.failed (e);
View Full Code Here

    }

    protected void register () throws ClosedChannelException {
  int ops = getSocketOperations ();
  if (ops != 0) {
      HandlerRegistration hr = new HandlerRegistration (this);
      sk = channel.register (selector, ops, hr);
  }
    }
View Full Code Here

    }
   
    private void registerRead () throws IOException {
  fromBuffer.clear ();
  toBuffer.clear ();
  HandlerRegistration hr = new HandlerRegistration (this, Long.MAX_VALUE);
  fromSk = from.register (selector, SelectionKey.OP_READ, hr);
  hr = new HandlerRegistration (this, Long.MAX_VALUE);
  toSk = to.register (selector, SelectionKey.OP_READ, hr);
    }
View Full Code Here

    }

    private void sendBuffers () throws IOException
  boolean needMore1 = sendBuffer (fromBuffer, to, toLogger);
  if (needMore1) {
      HandlerRegistration hr =
    new HandlerRegistration (this, Long.MAX_VALUE);
      toSk = to.register (selector, SelectionKey.OP_WRITE, hr);
  }
 
  boolean needMore2 = sendBuffer (toBuffer, from, fromLogger);
  if (needMore2) {
      HandlerRegistration hr =
    new HandlerRegistration (this, Long.MAX_VALUE);
      fromSk = from.register (selector, SelectionKey.OP_WRITE, hr);
  }
 
  if (!(needMore1 || needMore2))
      registerRead ();
View Full Code Here

TOP

Related Classes of rabbit.io.HandlerRegistration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.