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

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

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

Selector.wakeup介绍

[英]Forces blocked select operations to return immediately.

If no select operation is blocked when wakeup() is called then the next select operation will return immediately. This can be undone by a call to selectNow(); after calling selectNow(), a subsequent call of select can block again.
[中]强制被阻止的select操作立即返回。
如果在调用wakeup()时未阻止任何选择操作,则下一个选择操作将立即返回。这可以通过调用selectNow()来撤销;调用selectNow()后,接下来的select调用可能会再次被阻止。

代码示例

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

  1. @Override
  2. public Selector wakeup() {
  3. return delegate.wakeup();
  4. }

代码示例来源:origin: apache/kafka

  1. /**
  2. * Interrupt the nioSelector if it is blocked waiting to do I/O.
  3. */
  4. @Override
  5. public void wakeup() {
  6. this.nioSelector.wakeup();
  7. }

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

  1. @Override
  2. public Selector wakeup() {
  3. return delegate.wakeup();
  4. }

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

  1. @Override
  2. protected void wakeup(boolean inEventLoop) {
  3. if (!inEventLoop && wakenUp.compareAndSet(false, true)) {
  4. selector.wakeup();
  5. }
  6. }

代码示例来源:origin: apache/zookeeper

  1. private synchronized void wakeupCnxn() {
  2. selector.wakeup();
  3. }

代码示例来源:origin: apache/zookeeper

  1. public void wakeupSelector() {
  2. selector.wakeup();
  3. }

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

  1. int selectNow() throws IOException {
  2. try {
  3. return selector.selectNow();
  4. } finally {
  5. // restore wakeup state if needed
  6. if (wakenUp.get()) {
  7. selector.wakeup();
  8. }
  9. }
  10. }

代码示例来源:origin: iluwatar/java-design-patterns

  1. /**
  2. * Stops the reactor and related resources such as dispatcher.
  3. *
  4. * @throws InterruptedException
  5. * if interrupted while stopping the reactor.
  6. * @throws IOException
  7. * if any I/O error occurs.
  8. */
  9. public void stop() throws InterruptedException, IOException {
  10. reactorMain.shutdownNow();
  11. selector.wakeup();
  12. reactorMain.awaitTermination(4, TimeUnit.SECONDS);
  13. selector.close();
  14. LOGGER.info("Reactor stopped");
  15. }

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

  1. @Override
  2. protected void wakeup(boolean inEventLoop) {
  3. if (!inEventLoop && wakenUp.compareAndSet(false, true)) {
  4. selector.wakeup();
  5. }
  6. }

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

  1. int selectNow() throws IOException {
  2. try {
  3. return selector.selectNow();
  4. } finally {
  5. // restore wakeup state if needed
  6. if (wakenUp.get()) {
  7. selector.wakeup();
  8. }
  9. }
  10. }

代码示例来源:origin: iluwatar/java-design-patterns

  1. /**
  2. * Queues the change of operations request of a channel, which will change the interested operations of the channel
  3. * sometime in future.
  4. * <p>
  5. * This is a non-blocking method and does not guarantee that the operations have changed when this method returns.
  6. *
  7. * @param key
  8. * the key for which operations have to be changed.
  9. * @param interestedOps
  10. * the new interest operations.
  11. */
  12. public void changeOps(SelectionKey key, int interestedOps) {
  13. pendingCommands.add(new ChangeKeyOpsCommand(key, interestedOps));
  14. selector.wakeup();
  15. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Updating the readSelector while it's being used is not thread-safe,
  3. * so the connection must be queued. The reader will drain the queue
  4. * and update its readSelector before performing the next select
  5. */
  6. public void addConnection(SimpleServerRpcConnection conn) throws IOException {
  7. pendingConnections.add(conn);
  8. readSelector.wakeup();
  9. }
  10. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Add a connection to the list that want to write,
  3. */
  4. public void registerForWrite(SimpleServerRpcConnection c) {
  5. if (writingCons.add(c)) {
  6. writeSelector.wakeup();
  7. }
  8. }

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

  1. int selectNow() throws IOException {
  2. try {
  3. return selector.selectNow();
  4. } finally {
  5. // restore wakeup state if needed
  6. if (wakenUp.get()) {
  7. selector.wakeup();
  8. }
  9. }
  10. }

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

  1. public void accept(SocketChannel socketChannel) {
  2. if(isClosed.get())
  3. throw new IllegalStateException("Cannot accept more channels, selector manager closed");
  4. socketChannelQueue.add(socketChannel);
  5. selector.wakeup();
  6. }

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

  1. protected SelectionKey register(SelectableChannel ch, int interest_ops, NioConnection conn) throws Exception {
  2. reg_lock.lock();
  3. try {
  4. registration=true;
  5. selector.wakeup(); // needed because registration will block until selector.select() returns
  6. return ch.register(selector, interest_ops, conn);
  7. }
  8. finally {
  9. reg_lock.unlock();
  10. }
  11. }

代码示例来源:origin: code4craft/netty-learning

  1. Handler(Selector sel) throws IOException {
  2. //注册handler到Selector
  3. socket.configureBlocking(false);
  4. sk = socket.register(sel, 0);
  5. sk.attach(this);
  6. sk.interestOps(SelectionKey.OP_READ);
  7. sel.wakeup();
  8. }

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. @Override
  2. public final void onWriteDemand( WebSocket w ) {
  3. WebSocketImpl conn = (WebSocketImpl) w;
  4. try {
  5. conn.getSelectionKey().interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
  6. } catch ( CancelledKeyException e ) {
  7. // the thread which cancels key is responsible for possible cleanup
  8. conn.outQueue.clear();
  9. }
  10. selector.wakeup();
  11. }

代码示例来源:origin: TooTallNate/Java-WebSocket

  1. @Override
  2. public final void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
  3. selector.wakeup();
  4. try {
  5. if( removeConnection( conn ) ) {
  6. onClose( conn, code, reason, remote );
  7. }
  8. } finally {
  9. try {
  10. releaseBuffers( conn );
  11. } catch ( InterruptedException e ) {
  12. Thread.currentThread().interrupt();
  13. }
  14. }
  15. }

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

  1. protected void register(int op) {
  2. try {
  3. registerSelectionKey(op);
  4. key.selector().wakeup(); // no-op if the selector is not blocked in select()
  5. }
  6. catch(Throwable t) {
  7. }
  8. }

相关文章