Package org.apache.tomcat.util.net.NioEndpoint

Examples of org.apache.tomcat.util.net.NioEndpoint.KeyAttachment.interestOps()


                final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                final KeyAttachment att = (KeyAttachment) key.attachment();
                try {
                    if (key != null) {
                        key.interestOps(interestOps);
                        att.interestOps(interestOps);
                    }
                }
                catch (CancelledKeyException ckx) {
                    try {
                        if (key != null && key.attachment() != null) {
View Full Code Here


            socket.setPoller(this);
            KeyAttachment key = keyCache.poll();
            final KeyAttachment ka = key!=null?key:new KeyAttachment();
            ka.reset(this,socket);
            PollerEvent r = eventCache.poll();
            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);
        }
       
View Full Code Here

                    try {
                        if ( sk.isValid() && attachment != null ) {
                            attachment.access();
                            sk.attach(attachment);
                            sk.interestOps(0); //this is a must, so that we don't have multiple threads messing with the socket
                            attachment.interestOps(0);
                            NioChannel channel = attachment.getChannel();
                            if (sk.isReadable() || sk.isWritable() ) {
                                if ( attachment.getComet() ) {
                                    if (!processSocket(channel, SocketStatus.OPEN))
                                        processSocket(channel, SocketStatus.DISCONNECT);
View Full Code Here

                    KeyAttachment ka = (KeyAttachment) key.attachment();
                    if ( ka == null ) {
                        cancelledKey(key, SocketStatus.ERROR); //we don't support any keys without attachments
                    } else if ( ka.getError() ) {
                        cancelledKey(key, SocketStatus.DISCONNECT);
                    }else if ((ka.interestOps()&SelectionKey.OP_READ) == SelectionKey.OP_READ) {
                        //only timeout sockets that we are waiting for a read from
                        long delta = now - ka.getLastAccess();
                        long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout());
                        boolean isTimedout = delta > timeout;
                        if (isTimedout) {
View Full Code Here

                        long delta = now - ka.getLastAccess();
                        long timeout = (ka.getTimeout()==-1)?((long) socketProperties.getSoTimeout()):(ka.getTimeout());
                        boolean isTimedout = delta > timeout;
                        if (isTimedout) {
                            key.interestOps(0);
                            ka.interestOps(0); //avoid duplicate timeout calls
                            cancelledKey(key, SocketStatus.TIMEOUT);
                        } else {
                            long nextTime = now+(timeout-delta);
                            nextExpiration = (nextTime < nextExpiration)?nextTime:nextExpiration;
                        }
View Full Code Here

                if ( key == null ) throw new IOException("Key no longer registered");
                KeyAttachment att = (KeyAttachment) key.attachment();
                try {
                    if ( att.getWriteLatch()==null || att.getWriteLatch().getCount()==0) att.startWriteLatch(1);
                    //only register for write if a write has not yet been issued
                    if ( (att.interestOps() & SelectionKey.OP_WRITE) == 0) socket.getPoller().add(socket,SelectionKey.OP_WRITE);
                    att.awaitWriteLatch(writeTimeout,TimeUnit.MILLISECONDS);
                }catch (InterruptedException ignore) {
                    Thread.interrupted();
                }
                if ( att.getWriteLatch()!=null && att.getWriteLatch().getCount()> 0) {
View Full Code Here

                        break;
                }
                KeyAttachment att = (KeyAttachment) key.attachment();
                try {
                    if ( att.getReadLatch()==null || att.getReadLatch().getCount()==0) att.startReadLatch(1);
                    if ( att.interestOps() == 0) socket.getPoller().add(socket,SelectionKey.OP_READ);
                    att.awaitReadLatch(readTimeout,TimeUnit.MILLISECONDS);
                }catch (InterruptedException ignore) {
                    Thread.interrupted();
                }
                if ( att.getReadLatch()!=null && att.getReadLatch().getCount()> 0) {
View Full Code Here

                        final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                        final KeyAttachment att = (KeyAttachment)key.attachment();
                        //to do, add in a check, we might have just timed out on the wait,
                        //so there is no need to register us again.
                        boolean addToQueue = false;
                        try { addToQueue = ((att.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ckx ){ throw new IOException("Socket key cancelled.");}
                        if ( addToQueue ) {
                            synchronized (att.getMutex()) {
                                addToReadQueue(key, att);
                                att.getMutex().wait(readTimeout);
                            }
View Full Code Here

                        final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                        final KeyAttachment att = (KeyAttachment)key.attachment();
                        //to do, add in a check, we might have just timed out on the wait,
                        //so there is no need to register us again.
                        boolean addToQueue = false;
                        try { addToQueue = ((att.interestOps()&SelectionKey.OP_READ) != SelectionKey.OP_READ); } catch ( CancelledKeyException ckx ){ throw new IOException("Socket key cancelled.");}
                        if ( addToQueue ) {
                            synchronized (att.getMutex()) {
                                addToReadQueue(key, att);
                                att.getMutex().wait(readTimeout);
                            }
View Full Code Here

                if ( key == null ) throw new IOException("Key no longer registered");
                KeyAttachment att = (KeyAttachment) key.attachment();
                try {
                    if ( att.getLatch()==null || att.getLatch().getCount()==0) att.startLatch(1,SelectionKey.OP_WRITE);
                    //only register for write if a write has not yet been issued
                    if ( (att.interestOps() & SelectionKey.OP_WRITE) == 0) socket.getPoller().add(socket,SelectionKey.OP_WRITE);
                    att.awaitLatch(writeTimeout,TimeUnit.MILLISECONDS,SelectionKey.OP_WRITE);
                }catch (InterruptedException ignore) {
                    Thread.interrupted();
                }
                if ( att.getLatch()!=null && att.getLatch().getCount()> 0) {
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.