Examples of attachment()


Examples of java.nio.channels.SelectionKey.attachment()

                attachment.handleWrite();
            }

            // clean up broken connections
            if(!key.isValid()) {
                NIOAttachment attachment = (NIOAttachment)key.attachment();
                attachment.close(new IOException("Connection closed"));
            }
        }
    }
}
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

        for(Iterator k = nioDaemon.getSelector().keys().iterator(); k.hasNext(); ) {
            SelectionKey key = (SelectionKey)k.next();

            // close an invalid connection
            if(!key.isValid()) {
                NIOAttachment attachment = (NIOAttachment)key.attachment();
                attachment.close(new IOException("Connection closed"));

            // close the server socket
            } else if((key.interestOps() & SelectionKey.OP_ACCEPT) != 0) {
                try {
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

                    logger.warning("Error closing server socket, " + e.getMessage());
                }
               
            // close a connection socket
            } else {
                NIOAttachment attachment = (NIOAttachment)key.attachment();
                attachment.close(new ServerShutdownException());
            }
        }
    }
}
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

          synchronized (writeSelector.keys()) {
            calls = new ArrayList<Call>(writeSelector.keys().size());
            iter = writeSelector.keys().iterator();
            while (iter.hasNext()) {
              SelectionKey key = iter.next();
              Call call = (Call)key.attachment();
              if (call != null && key.channel() == call.connection.channel) {
                calls.add(call);
              }
            }
          }
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

        {
            SelectionKey key = selectedIter.next();
            selectedIter.remove();
            if(key.isAcceptable())
            {
                return (Listener) key.attachment();
            }
        }
        return null;
    }
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

        {
            SelectionKey key = selectedIter.next();
            selectedIter.remove();
            if(key.isReadable() || key.isWritable())
            {
                return (Connector) key.attachment();

            }
        }
        return null;
    }
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

        Iterator<SelectionKey> it = keys.iterator();
        while (it.hasNext()) {
            SelectionKey key = it.next();
            it.remove();

            DatagramSessionImpl session = (DatagramSessionImpl) key
                    .attachment();

            // Let the recycler know that the session is still active.
            getSessionRecycler(session).recycle(session.getLocalAddress(),
                    session.getRemoteAddress());
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

        if (key == null) {
            throw new IllegalArgumentException("Unknown localAddress: "
                    + localAddress);
        }

        RegistrationRequest req = (RegistrationRequest) key.attachment();
        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler(req);
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(localAddress, remoteAddress);
            if (session != null) {
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

            SelectionKey key = it.next();
            it.remove();

            DatagramChannel ch = (DatagramChannel) key.channel();

            RegistrationRequest req = (RegistrationRequest) key.attachment();
            try {
                if (key.isReadable()) {
                    readSession(ch, req);
                }
View Full Code Here

Examples of java.nio.channels.SelectionKey.attachment()

                if (ch == null) {
                    request.exception = new IllegalArgumentException(
                            "Address not bound: " + request.address);
                } else {
                    SelectionKey key = ch.keyFor(selector);
                    request.registrationRequest = (RegistrationRequest) key
                            .attachment();
                    key.cancel();
                    selector.wakeup(); // wake up again to trigger thread death
                    ch.disconnect();
                    ch.close();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.