Package java.nio.channels

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


            comet = false;
            cometClose = true;
            SelectionKey key = socket.getSocket().getIOChannel().keyFor(socket.getSocket().getPoller().getSelector());
            if ( key != null ) {
                NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment();
                if ( attach!=null && attach.getComet()) {
                    //if this is a comet connection
                    //then execute the connection closure at the next selector loop
                    //request.getAttributes().remove("org.apache.tomcat.comet.timeout");
                    //attach.setTimeout(5000); //force a cleanup in 5 seconds
View Full Code Here


        throws IOException {

        //prevent timeout for async,
        SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
        if (key != null) {
            NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment) key.attachment();
            attach.access();
        }

        //write to the socket, if there is anything to write
        if (socket.getBufHandler().getWriteBuffer().position() > 0) {
View Full Code Here

                SelectionKey sk = it.next();
                it.remove();
                try {
                    int readyOps = sk.readyOps();
                    sk.interestOps(sk.interestOps() & ~readyOps);
                    NioSender sender = (NioSender) sk.attachment();
                    if ( sender.process(sk, (testOptions&Channel.SEND_OPTIONS_USE_ACK)==Channel.SEND_OPTIONS_USE_ACK) ) {
                        System.out.println("Message completed for handler:"+sender);
                        Thread.sleep(2000);
                        sender.reset();
                        sender.setMessage(XByteBuffer.createDataPackage(getMessage(mbr)));
View Full Code Here

        while( it.hasNext() )
        {
            SelectionKey key = ( SelectionKey ) it.next();
            it.remove();

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

            if( key.isReadable() )
            {
                readSession( session );
            }
View Full Code Here

            if( !key.isConnectable() )
                continue;

            SocketChannel ch = ( SocketChannel ) key.channel();
            ConnectionRequest entry = ( ConnectionRequest ) key.attachment();

            try
            {
                ch.finishConnect();
                SocketSession session = newSession( ch, entry.handler );
View Full Code Here

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

            if( !key.isValid() )
                continue;

            ConnectionRequest entry = ( ConnectionRequest ) key.attachment();

            if( currentTime >= entry.deadline )
            {
                entry.exception = new ConnectException();
                entry.done = true;
View Full Code Here

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

        RegistrationRequest req = ( RegistrationRequest ) key.attachment();
        DatagramSession s = new DatagramSession( filters, ch, req.handler );
        s.setRemoteAddress( remoteAddress );
        s.setSelectionKey( key );
       
        try
View Full Code Here

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

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

            RegistrationRequest req = ( RegistrationRequest ) key.attachment();
            DatagramSession session = new DatagramSession(
                    filters, ch, req.handler );
            session.setSelectionKey( key );
           
            try
View Full Code Here

        Iterator it = selectedKeys.iterator();

        while( it.hasNext() )
        {
            SelectionKey key = ( SelectionKey ) it.next();
            SocketSession session = ( SocketSession ) key.attachment();

            if( key.isReadable() )
            {
                read( session );
            }
View Full Code Here

            if( keys != null )
            {
                for( Iterator it = keys.iterator(); it.hasNext(); )
                {
                    SelectionKey key = ( SelectionKey ) it.next();
                    SocketSession session = ( SocketSession ) key.attachment();
                    notifyIdleSession( session, currentTime );
                }
            }
        }
    }
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.