Examples of attachment()


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

            } else {
                final SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
                try {
                    boolean cancel = false;
                    if (key != null) {
                        final KeyAttachment att = (KeyAttachment) key.attachment();
                        if ( att!=null ) {
                            //handle callback flag
                            if (att.getComet() && (interestOps & OP_CALLBACK) == OP_CALLBACK ) {
                                att.setCometNotify(true);
                            } else {
View Full Code Here

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

                    Iterator iterator = keyCount > 0 ? selector.selectedKeys().iterator() : null;
                    // Walk through the collection of ready keys and dispatch
                    // any active event.
                    while (iterator != null && iterator.hasNext()) {
                        SelectionKey sk = (SelectionKey) iterator.next();
                        KeyAttachment attachment = (KeyAttachment)sk.attachment();
                        attachment.access();
                        iterator.remove();
                        processKey(sk, attachment);
                    }//while
View Full Code Here

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

            int keycount = 0;
            for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext(); ) {
                SelectionKey key = iter.next();
                keycount++;
                try {
                    KeyAttachment ka = (KeyAttachment) key.attachment();
                    if ( ka == null ) {
                        cancelledKey(key, SocketStatus.ERROR,false); //we don't support any keys without attachments
                    } else if ( ka.getError() ) {
                        cancelledKey(key, SocketStatus.ERROR,true);
                    } else if (ka.getComet() && ka.getCometNotify() ) {
View Full Code Here

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

     * @throws IOException if an IO Exception occurs in the underlying socket logic
     */
    public int write(ByteBuffer buf, NioChannel socket, long writeTimeout,MutableInteger lastWrite) throws IOException {
        SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
        if ( key == null ) throw new IOException("Key no longer registered");
        KeyAttachment att = (KeyAttachment) key.attachment();
        int written = 0;
        boolean timedout = false;
        int keycount = 1; //assume we can write
        long time = System.currentTimeMillis(); //start the timeout timer
        try {
View Full Code Here

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

     * @throws IOException if an IO Exception occurs in the underlying socket logic
     */
    public int read(ByteBuffer buf, NioChannel socket, long readTimeout) throws IOException {
        SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector());
        if ( key == null ) throw new IOException("Key no longer registered");
        KeyAttachment att = (KeyAttachment) key.attachment();
        int read = 0;
        boolean timedout = false;
        int keycount = 1; //assume we can write
        long time = System.currentTimeMillis(); //start the timeout timer
        try {
View Full Code Here

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

                    // Walk through the collection of ready keys and dispatch
                    // any active event.
                    while (run && iterator != null && iterator.hasNext()) {
                        SelectionKey sk = (SelectionKey) iterator.next();
                        KeyAttachment attachment = (KeyAttachment)sk.attachment();
                        try {
                            attachment.access();
                            iterator.remove(); ;
                            sk.interestOps(sk.interestOps() & (~sk.readyOps()));
                            if ( sk.isReadable() ) {
View Full Code Here

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

                    if (closed) {
                        // Close socket and pool
                        try {
                            KeyAttachment ka = null;
                            if (key!=null) {
                                ka = (KeyAttachment) key.attachment();
                                if (ka!=null) ka.setComet(false);
                                socket.getPoller().cancelledKey(key, SocketStatus.ERROR, false);
                            }
                            if (socket!=null) nioChannels.offer(socket);
                            socket = null;
View Full Code Here

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

                        }
                    }
                } else if (handshake == -1 ) {
                    KeyAttachment ka = null;
                    if (key!=null) {
                        ka = (KeyAttachment) key.attachment();
                        socket.getPoller().cancelledKey(key, SocketStatus.DISCONNECT, false);
                    }
                    if (socket!=null) nioChannels.offer(socket);
                    socket = null;
                    if ( ka!=null ) keyCache.offer(ka);
View Full Code Here

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

                    if ( ka!=null ) keyCache.offer(ka);
                    ka = null;
                } else {
                    final SelectionKey fk = key;
                    final int intops = handshake;
                    final KeyAttachment ka = (KeyAttachment)fk.attachment();
                    ka.getPoller().add(socket,intops);
                }
            }catch(CancelledKeyException cx) {
                socket.getPoller().cancelledKey(key,null,false);
            } catch (OutOfMemoryError oom) {
View Full Code Here

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

    public Object getAttachment(boolean remove) {
        Poller pol = getPoller();
        Selector sel = pol!=null?pol.getSelector():null;
        SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null;
        Object att = key!=null?key.attachment():null;
        if (key != null && att != null && remove ) key.attach(null);
        return att;
    }
    /**
     * getBufHandler
 
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.