Package java.nio.channels

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


            while(keyItor.hasNext()) {
                SelectionKey key = keyItor.next();
                keyItor.remove();
                // The key indexes into the selector so you
                // can retrieve the socket that's ready for I/O
                Handler handler = (Handler) key.attachment();
                try {
                    handler.handle(key);
                } catch (CancelledKeyException cke) {
                    ;
                } catch (IOException ioe) {
View Full Code Here


        SelectionKey selectionKey = iter.next();
        iter.remove();
        try {
          int ops = selectionKey.readyOps();
          if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
            if (selectionKey.attachment() == tcp) {
              while (true) {
                Object object = tcp.readObject(this);
                if (object == null) break;
                if (!tcpRegistered) {
                  if (object instanceof RegisterTCP) {
View Full Code Here

      for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
        SelectionKey selectionKey = iter.next();
        iter.remove();
        try {
          int ops = selectionKey.readyOps();
          Connection fromConnection = (Connection)selectionKey.attachment();

          if (fromConnection != null) {
            // Must be a TCP read or write operation.
            if (udp != null && fromConnection.udpRemoteAddress == null) continue;
            if ((ops & SelectionKey.OP_READ) == SelectionKey.OP_READ) {
View Full Code Here

                    it.remove();

                    if (key.isAcceptable()) {
                        srv_sock=(ServerSocketChannel) key.channel();
                        // get server socket and attachment
                        src=(InetSocketAddress) key.attachment();
                        in_sock=srv_sock.accept(); // accept request
                        if (verbose)
                            log("Proxy.loop()", "accepted connection from " + toString(in_sock));
                        dest=(InetSocketAddress) mappings.get(src);
                        // find corresponding dest
View Full Code Here

                        // validate the key
                        if ( !selKey.isValid() ) continue;

                        // at least our ConnectionAcceptor has created a client
                        // ConnectionHeader
                        clientInfo = (ConnectionHeader) selKey.attachment();

                        // first check read-availbility
                        if ( selKey.isReadable() )
                        {
                            // get the underlying socket channel
View Full Code Here

      for(Iterator<SelectionKey> i = selector.selectedKeys().iterator(); i.hasNext();) {
        SelectionKey sk = i.next();
        i.remove();

       
        IoSessionImpl session = (IoSessionImpl) sk.attachment();
       
        if(sk.isValid() == false) {
          try {
            session.closeNow0();
          } catch (IOException e) {}
View Full Code Here

                // What kind of activity is it?
                if ((key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ)
                {
                    SocketChannel ch = (SocketChannel)key.channel();
                    java.net.Socket ss = (java.net.Socket)ch.socket();
                    Socket s = (Socket)key.attachment();
                    if (s != null)
                    {
//                        System.out.println(s + ": OnRead");
                        s.OnRead();
                        if (s.LineProtocol())
View Full Code Here

                }
                if ((key.readyOps() & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT)
                {
                    ServerSocketChannel ch = (ServerSocketChannel)key.channel();
                    java.net.ServerSocket ss = (java.net.ServerSocket)ch.socket();
                    Socket s = (Socket)key.attachment();
                    if (s != null)
                    {
//                        System.out.println(s + ": OnRead(ACCEPT)");
                        s.OnRead(); // ListenSocket.OnRead will call OnAccept on new Socket
                    }
View Full Code Here

                }
                if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT)
                {
                    SocketChannel ch = (SocketChannel)key.channel();
                    java.net.Socket ss = (java.net.Socket)ch.socket();
                    Socket s = (Socket)key.attachment();
                    if (s != null)
                    {
//                        System.out.println(s + ": OnConnect");
                        ch.finishConnect();
                        s.SetConnecting(false);
View Full Code Here

            while (it.hasNext())
            {
                // Get a key representing one of bits of I/O
                // activity
                SelectionKey key = (SelectionKey)it.next();
                Socket p = (Socket)key.attachment();
                if (p.CloseAndDelete())
                {
                    p.OnDelete(); // OnDelete closes Channel
                    key.cancel();
                    m_sockets.remove(p); // no longer Valid
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.