Package java.nio.channels

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


        clientKey = client.registerSelector(selector, SelectionKey.OP_READ);

        // add this key to the map
        FrameBuffer frameBuffer = new FrameBuffer(client, clientKey,
          SelectAcceptThread.this);
        clientKey.attach(frameBuffer);
      } catch (TTransportException tte) {
        // something went wrong accepting.
        LOGGER.warn("Exception trying to accept!", tte);
        tte.printStackTrace();
        if (clientKey != null) cleanupSelectionKey(clientKey);
View Full Code Here


    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

                    return;
                }
            }
            try {
                final SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
                key.attach(request);
                request.setKey(key);
            } catch (final IOException ex) {
                closeChannel(serverChannel);
                throw new IOReactorException("Failure registering channel " +
                        "with the selector", ex);
View Full Code Here

      SocketChannel channel = server.accept();
      channel.configureBlocking(false);
      channel.socket().setTcpNoDelay(tcpNoDelay);
      SelectionKey readKey = channel.register(selector, SelectionKey.OP_READ);
      c = new Connection(readKey, channel, System.currentTimeMillis());
      readKey.attach(c);
      synchronized (connectionList) {
        connectionList.add(numConnections, c);
        numConnections++;
      }
      if (LOG.isDebugEnabled())
View Full Code Here

                this.sessions.add(session);
                final SessionRequestImpl sessionRequest = entry.getSessionRequest();
                if (sessionRequest != null) {
                    sessionRequest.completed(session);
                }
                key.attach(session);
                sessionCreated(key, session);
            } catch (final CancelledKeyException ex) {
                queueClosedSession(session);
                key.attach(null);
            }
View Full Code Here

                }
                key.attach(session);
                sessionCreated(key, session);
            } catch (final CancelledKeyException ex) {
                queueClosedSession(session);
                key.attach(null);
            }
        }
    }

    private void processClosedSessions() {
View Full Code Here

                        if ((channel instanceof SocketChannel) && ((SocketChannel)channel).isConnected())
                        {
                          key = channel.register(selector,SelectionKey.OP_READ,att);
                          SelectChannelEndPoint endpoint = newEndPoint((SocketChannel)channel,this,key);
                          key.attach(endpoint);
                          endpoint.dispatch();
                        }
                        else if (channel.isOpen())
                        {
                          channel.register(selector,SelectionKey.OP_CONNECT,att);
View Full Code Here

                        if (channel.isConnected())
                        {
                          key = channel.register(selector,SelectionKey.OP_READ,null);
                          SelectChannelEndPoint endpoint = newEndPoint(channel,this,key);
                          key.attach(endpoint);
                          endpoint.dispatch();
                        }
                        else if (channel.isOpen())
                        {
                          channel.register(selector,SelectionKey.OP_CONNECT,null);
View Full Code Here

                            if (_nextSet==_setID)
                            {
                                // bind connections to this select set.
                                SelectionKey cKey = channel.register(_selectSet[_nextSet].getSelector(), SelectionKey.OP_READ);
                                SelectChannelEndPoint endpoint=newEndPoint(channel,_selectSet[_nextSet],cKey);
                                cKey.attach(endpoint);
                                if (endpoint != null)
                                    endpoint.dispatch();
                            }
                            else
                            {
View Full Code Here

        SelectionKey selectionKey = socketChannel.keyFor(selector);

        if(selectionKey != null) {
            try {
                selectionKey.attach(null);
                selectionKey.cancel();
            } catch(Exception e) {
                if(logger.isEnabledFor(Level.WARN))
                    logger.warn(e.getMessage(), e);
            }
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.