java.nio.channels.Selector.provider()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中java.nio.channels.Selector.provider()方法的一些代码示例,展示了Selector.provider()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Selector.provider()方法的具体详情如下:
包路径:java.nio.channels.Selector
类名称:Selector
方法名:provider

Selector.provider介绍

[英]Gets the provider of this selector.
[中]获取此选择器的提供程序。

代码示例

代码示例来源:origin: netty/netty

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: redisson/redisson

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: wildfly/wildfly

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: mpetazzoni/ttorrent

@NotNull
 @Override
 public ServerSocketChannel channelFor(Selector selector) throws IOException {
  ServerSocketChannel myServerSocketChannel = selector.provider().openServerSocketChannel();
  myServerSocketChannel.configureBlocking(false);
  int bindPort = -1;
  for (int port = firstTryPort; port <= lastTryPort; port++) {
   try {
    InetSocketAddress tryAddress = new InetSocketAddress(port);
    myServerSocketChannel.socket().bind(tryAddress);
    bindPort = tryAddress.getPort();
    break;
   } catch (IOException e) {
    //try next port
    logger.debug("Could not bind to port {}, trying next port...", port);
   }
  }
  if (bindPort == -1) {
   logger.error(String.format(
       "No available ports in range [%d, %d] for the BitTorrent client!", firstTryPort, lastTryPort
   ));
   throw new IOException("No available port for the BitTorrent client!");
  }
  return myServerSocketChannel;
 }
}

代码示例来源:origin: EsotericSoftware/kryonet

public void connect (Selector selector, SocketAddress remoteAddress, int timeout) throws IOException {
  close();
  writeBuffer.clear();
  readBuffer.clear();
  readBuffer.flip();
  currentObjectLength = 0;
  try {
    SocketChannel socketChannel = selector.provider().openSocketChannel();
    Socket socket = socketChannel.socket();
    socket.setTcpNoDelay(true);
    // socket.setTrafficClass(IPTOS_LOWDELAY);
    socket.connect(remoteAddress, timeout); // Connect using blocking mode for simplicity.
    socketChannel.configureBlocking(false);
    this.socketChannel = socketChannel;
    selectionKey = socketChannel.register(selector, SelectionKey.OP_READ);
    selectionKey.attach(this);
    if (DEBUG) {
      debug("kryonet", "Port " + socketChannel.socket().getLocalPort() + "/TCP connected to: "
        + socketChannel.socket().getRemoteSocketAddress());
    }
    lastReadTime = lastWriteTime = System.currentTimeMillis();
  } catch (IOException ex) {
    close();
    IOException ioEx = new IOException("Unable to connect to: " + remoteAddress);
    ioEx.initCause(ex);
    throw ioEx;
  }
}

代码示例来源:origin: EsotericSoftware/kryonet

public void bind (Selector selector, InetSocketAddress localPort) throws IOException {
  close();
  readBuffer.clear();
  writeBuffer.clear();
  try {
    datagramChannel = selector.provider().openDatagramChannel();
    datagramChannel.socket().bind(localPort);
    datagramChannel.configureBlocking(false);
    selectionKey = datagramChannel.register(selector, SelectionKey.OP_READ);
    lastCommunicationTime = System.currentTimeMillis();
  } catch (IOException ex) {
    close();
    throw ex;
  }
}

代码示例来源:origin: EsotericSoftware/kryonet

public void connect (Selector selector, InetSocketAddress remoteAddress) throws IOException {
  close();
  readBuffer.clear();
  writeBuffer.clear();
  try {
    datagramChannel = selector.provider().openDatagramChannel();
    datagramChannel.socket().bind(null);
    datagramChannel.socket().connect(remoteAddress);
    datagramChannel.configureBlocking(false);
    selectionKey = datagramChannel.register(selector, SelectionKey.OP_READ);
    lastCommunicationTime = System.currentTimeMillis();
    connectedAddress = remoteAddress;
  } catch (IOException ex) {
    close();
    IOException ioEx = new IOException("Unable to connect to: " + remoteAddress);
    ioEx.initCause(ex);
    throw ioEx;
  }
}

代码示例来源:origin: EsotericSoftware/kryonet

/** @param udpPort May be null. */
public void bind (InetSocketAddress tcpPort, InetSocketAddress udpPort) throws IOException {
  close();
  synchronized (updateLock) {
    selector.wakeup();
    try {
      serverChannel = selector.provider().openServerSocketChannel();
      serverChannel.socket().bind(tcpPort);
      serverChannel.configureBlocking(false);
      serverChannel.register(selector, SelectionKey.OP_ACCEPT);
      if (DEBUG) debug("kryonet", "Accepting connections on port: " + tcpPort + "/TCP");
      if (udpPort != null) {
        udp = new UdpConnection(serialization, objectBufferSize);
        udp.bind(selector, udpPort);
        if (DEBUG) debug("kryonet", "Accepting connections on port: " + udpPort + "/UDP");
      }
    } catch (IOException ex) {
      close();
      throw ex;
    }
  }
  if (INFO) info("kryonet", "Server opened.");
}

代码示例来源:origin: apache/activemq-artemis

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: org.apache.activemq/artemis-jms-client-all

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: org.apache.hbase.thirdparty/hbase-shaded-netty

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: com.couchbase.client/core-io

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: com.datastax.oss/java-driver-core-shaded

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: apache/activemq-artemis

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: org.apache.ratis/ratis-proto-shaded

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: io.bitsensor/proto

@Override
public SelectorProvider provider() {
  return delegate.provider();
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

private void returnToPool(Selector selector) {
    SelectorProvider provider = selector.provider();
    List<Selector> providerPool = pool.get(provider);
    if (providerPool == null) {
      providerPool = new LinkedList<Selector>();
      pool.put(provider, providerPool);
    }
    providerPool.add(selector);
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

private void returnToPool(Selector selector) {
    SelectorProvider provider = selector.provider();
    List<Selector> providerPool = pool.get(provider);
    if (providerPool == null) {
      providerPool = new LinkedList<Selector>();
      pool.put(provider, providerPool);
    }
    providerPool.add(selector);
  }
}

代码示例来源:origin: org.jruby/jruby-core

private synchronized void returnToPool(Selector selector) {
    openSelectors.remove(selector);
    if (selector.isOpen()) {
      SelectorProvider provider = selector.provider();
      List<Selector> providerPool = pool.get(provider);
      if (providerPool == null) {
        providerPool = new LinkedList<Selector>();
        pool.put(provider, providerPool);
      }
      providerPool.add(selector);
    }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

private synchronized void returnToPool(Selector selector) {
    openSelectors.remove(selector);
    if (selector.isOpen()) {
      SelectorProvider provider = selector.provider();
      List<Selector> providerPool = pool.get(provider);
      if (providerPool == null) {
        providerPool = new LinkedList<Selector>();
        pool.put(provider, providerPool);
      }
      providerPool.add(selector);
    }
  }
}

相关文章