Package java.nio.channels

Examples of java.nio.channels.SelectionKey


  }

  @Override
  public ServerContext createContext(TProtocol input, TProtocol output, Object selectionKeyObject) {
    LOG.debug("Client connected");
    SelectionKey selectionKey = (SelectionKey) selectionKeyObject;
    SocketChannel channel = (SocketChannel) selectionKey.channel();
    Socket socket = channel.socket();
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    _connectionMeter.mark();
    _connections.incrementAndGet();
View Full Code Here


  }

  @Override
  public ServerContext createContext(TProtocol input, TProtocol output, Object selectionKeyObject) {
    LOG.debug("Client connected");
    SelectionKey selectionKey = (SelectionKey) selectionKeyObject;
    SocketChannel channel = (SocketChannel) selectionKey.channel();
    Socket socket = channel.socket();
    SocketAddress remoteSocketAddress = socket.getRemoteSocketAddress();
    SocketAddress localSocketAddress = socket.getLocalSocketAddress();
    _connectionMeter.mark();
    _connections.incrementAndGet();
View Full Code Here

    public void run() {
      LOG.info(getName() + ": starting");
      SERVER.set(HBaseServer.this);

      while (running) {
        SelectionKey key = null;
        try {
          selector.select(); // FindBugs IS2_INCONSISTENT_SYNC
          Iterator<SelectionKey> iter = selector.selectedKeys().iterator();
          while (iter.hasNext()) {
            key = iter.next();
            iter.remove();
            try {
              if (key.isValid()) {
                if (key.isAcceptable())
                  doAccept(key);
              }
            } catch (IOException ignored) {
            }
            key = null;
View Full Code Here

        channel.socket().setKeepAlive(tcpKeepAlive);

        Reader reader = getReader();
        try {
          reader.startAdd();
          SelectionKey readKey = reader.registerChannel(channel);
          c = getConnection(channel, System.currentTimeMillis());
          readKey.attach(c);
          synchronized (connectionList) {
            connectionList.add(numConnections, c);
            numConnections++;
          }
          if (LOG.isDebugEnabled())
View Full Code Here

        }
      }

      private synchronized void doRunLoop() {
        while (running) {
          SelectionKey key = null;
          try {
            readSelector.select();
            while (adding) {
              this.wait(1000);
            }

            Iterator<SelectionKey> iter = readSelector.selectedKeys().iterator();
            while (iter.hasNext()) {
              key = iter.next();
              iter.remove();
              if (key.isValid()) {
                if (key.isReadable()) {
                  doRead(key);
                }
              }
              key = null;
            }
View Full Code Here

        try {
          waitPending();     // If a channel is being registered, wait.
          writeSelector.select(purgeTimeout);
          Iterator<SelectionKey> iter = writeSelector.selectedKeys().iterator();
          while (iter.hasNext()) {
            SelectionKey key = iter.next();
            iter.remove();
            try {
              if (key.isValid() && key.isWritable()) {
                  doAsyncWrite(key);
              }
            } catch (IOException e) {
              LOG.info(getName() + ": doAsyncWrite threw exception " + e);
            }
          }
          long now = System.currentTimeMillis();
          if (now < lastPurgeTime + purgeTimeout) {
            continue;
          }
          lastPurgeTime = now;
          //
          // If there were some calls that have not been sent out for a
          // long time, discard them.
          //
          LOG.debug("Checking for old call responses.");
          ArrayList<Call> calls;

          // get the list of channels from list of keys.
          synchronized (writeSelector.keys()) {
            calls = new ArrayList<Call>(writeSelector.keys().size());
            iter = writeSelector.keys().iterator();
            while (iter.hasNext()) {
              SelectionKey key = iter.next();
              Call call = (Call)key.attachment();
              if (call != null && key.channel() == call.connection.channel) {
                calls.add(call);
              }
            }
          }
View Full Code Here

    {
        Iterator<SelectionKey> selectedIter = _selectedKeys.iterator();

        while(selectedIter.hasNext())
        {
            SelectionKey key = selectedIter.next();
            selectedIter.remove();
            if(key.isAcceptable())
            {
                return (Listener) key.attachment();
            }
        }
        return null;
    }
View Full Code Here

    {
        Iterator<SelectionKey> selectedIter = _selectedKeys.iterator();

        while(selectedIter.hasNext())
        {
            SelectionKey key = selectedIter.next();
            selectedIter.remove();
            if(key.isReadable() || key.isWritable())
            {
                return (Connector) key.attachment();

            }
        }
        return null;
    }
View Full Code Here

    }

    public <C> Listener<C> createListener(ServerSocketChannel c, C context)
    {
        Listener<C> l = new ListenerImpl<C>(this, c, context);
        SelectionKey key = registerInterest(c,SelectionKey.OP_ACCEPT);
        key.attach(l);
        return l;
    }
View Full Code Here

        }
    }

    public <C> Connector<C> createConnector(SelectableChannel c, C context)
    {
        SelectionKey key = registerInterest(c,SelectionKey.OP_READ);
        Connector<C> co = new ConnectorImpl<C>(this, null, new SaslClientImpl(),(SocketChannel)c, context, key);
        key.attach(co);
        return co;
    }
View Full Code Here

TOP

Related Classes of java.nio.channels.SelectionKey

Copyright © 2018 www.massapicom. 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.