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

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

本文整理了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

@Override
public Selector wakeup() {
  return delegate.wakeup();
}

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

/**
 * Interrupt the nioSelector if it is blocked waiting to do I/O.
 */
@Override
public void wakeup() {
  this.nioSelector.wakeup();
}

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

@Override
public Selector wakeup() {
  return delegate.wakeup();
}

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

@Override
protected void wakeup(boolean inEventLoop) {
  if (!inEventLoop && wakenUp.compareAndSet(false, true)) {
    selector.wakeup();
  }
}

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

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

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

public void wakeupSelector() {
  selector.wakeup();
}

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

int selectNow() throws IOException {
  try {
    return selector.selectNow();
  } finally {
    // restore wakeup state if needed
    if (wakenUp.get()) {
      selector.wakeup();
    }
  }
}

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

/**
 * Stops the reactor and related resources such as dispatcher.
 * 
 * @throws InterruptedException
 *           if interrupted while stopping the reactor.
 * @throws IOException
 *           if any I/O error occurs.
 */
public void stop() throws InterruptedException, IOException {
 reactorMain.shutdownNow();
 selector.wakeup();
 reactorMain.awaitTermination(4, TimeUnit.SECONDS);
 selector.close();
 LOGGER.info("Reactor stopped");
}

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

@Override
protected void wakeup(boolean inEventLoop) {
  if (!inEventLoop && wakenUp.compareAndSet(false, true)) {
    selector.wakeup();
  }
}

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

int selectNow() throws IOException {
  try {
    return selector.selectNow();
  } finally {
    // restore wakeup state if needed
    if (wakenUp.get()) {
      selector.wakeup();
    }
  }
}

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

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

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

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

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

/**
 * Add a connection to the list that want to write,
 */
public void registerForWrite(SimpleServerRpcConnection c) {
 if (writingCons.add(c)) {
  writeSelector.wakeup();
 }
}

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

int selectNow() throws IOException {
  try {
    return selector.selectNow();
  } finally {
    // restore wakeup state if needed
    if (wakenUp.get()) {
      selector.wakeup();
    }
  }
}

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

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

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

protected SelectionKey register(SelectableChannel ch, int interest_ops, NioConnection conn) throws Exception {
  reg_lock.lock();
  try {
    registration=true;
    selector.wakeup(); // needed because registration will block until selector.select() returns
    return ch.register(selector, interest_ops, conn);
  }
  finally {
    reg_lock.unlock();
  }
}

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

Handler(Selector sel) throws IOException {
  //注册handler到Selector
  socket.configureBlocking(false);
  sk = socket.register(sel, 0);
  sk.attach(this);
  sk.interestOps(SelectionKey.OP_READ);
  sel.wakeup();
}

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

@Override
public final void onWriteDemand( WebSocket w ) {
  WebSocketImpl conn = (WebSocketImpl) w;
  try {
    conn.getSelectionKey().interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
  } catch ( CancelledKeyException e ) {
    // the thread which cancels key is responsible for possible cleanup
    conn.outQueue.clear();
  }
  selector.wakeup();
}

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

@Override
public final void onWebsocketClose( WebSocket conn, int code, String reason, boolean remote ) {
  selector.wakeup();
  try {
    if( removeConnection( conn ) ) {
      onClose( conn, code, reason, remote );
    }
  } finally {
    try {
      releaseBuffers( conn );
    } catch ( InterruptedException e ) {
      Thread.currentThread().interrupt();
    }
  }
}

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

protected void register(int op) {
  try {
    registerSelectionKey(op);
    key.selector().wakeup(); // no-op if the selector is not blocked in select()
  }
  catch(Throwable t) {
  }
}

相关文章