java selectionkey_Java SelectionKey.interestOps方法代碼示例

本文整理匯總了Java中java.nio.channels.SelectionKey.interestOps方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectionKey.interestOps方法的具體用法?Java SelectionKey.interestOps怎麽用?Java SelectionKey.interestOps使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.channels.SelectionKey的用法示例。

在下文中一共展示了SelectionKey.interestOps方法的20個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。

示例1: finishConnection

​點讚 3

import java.nio.channels.SelectionKey; //導入方法依賴的package包/類

private final void finishConnection(SelectionKey key, MMOConnection con)

{

try

{

((SocketChannel) key.channel()).finishConnect();

}

catch (IOException e)

{

con.getClient().onForcedDisconnection();

closeConnectionImpl(key, con);

}

// key might have been invalidated on finishConnect()

if (key.isValid())

{

key.interestOps(key.interestOps() | SelectionKey.OP_READ);

key.interestOps(key.interestOps() & ~SelectionKey.OP_CONNECT);

}

}

開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:20,

示例2: Client

​點讚 3

import java.nio.channels.SelectionKey; //導入方法依賴的package包/類

public Client() throws IOException {

// 同樣的,注冊鬧鍾.

this.selector = Selector.open();

// 連接遠程server

socketChannel = SocketChannel.open();

// 如果快速的建立了連接,返回true.如果沒有建立,則返回false,並在連接後出發Connect事件.

Boolean isConnected = socketChannel.connect(new InetSocketAddress("localhost", 3562));

socketChannel.configureBlocking(false);

SelectionKey key = socketChannel.register(selector, SelectionKey.OP_READ);

if (isConnected) {

this.sendFirstMsg();

} else {

// 如果連接還在嘗試中,則注冊connect事件的監聽. connect成功以後會出發connect事件.

key.interestOps(SelectionKey.OP_CONNECT);

}

}

開發者ID:minilynn,項目名稱:samplecode,代碼行數:19,

示例3: SSLSocketChannel2

​點讚 3

import java.nio.channels.SelectionKey; //導入方法依賴的package包/類

public SSLSocketChannel2( SocketChannel channel , SSLEngine sslEngine , ExecutorService exec , SelectionKey key ) throws IOException {

if( channel == null || sslEngine == null || exec == null )

throw new IllegalArgumentException( "parameter must not be null" );

this.socketChannel = channel;

this.sslEngine = sslEngine;

this.exec = exec;

readEngineResult = writeEngineResult = new SSLEngineResult( Status.BUFFER_UNDERFLOW, sslEngine.getHandshakeStatus(), 0, 0 ); // init to prevent NPEs

tasks = new ArrayList>( 3 );

if( key != null ) {

key.interestOps( key.interestOps() | SelectionKey.OP_WRITE );

this.selectionKey = key;

}

createBuffers( sslEngine.getSession() );

// kick off handshake

socketChannel.write( wrap( emptybuffer ) );// initializes res

processHandshake();

}

開發者ID:LDLN,項目名稱:Responder-Android,代碼行數:21,

示例4: setInterestedInWrite

​點讚 3

import java.nio.channels.SelectionKey; //導入方法依賴的package包/類

@Override

protected void setInterestedInWrite(NioSession session, boolean isInterested) throws Exception {

SelectionKey key = session.getSelectionKey();

if (key == null) {

return;

}

int newInterestOps = key.interestOps();

if (isInterested) {

newInterestOps |= SelectionKey.OP_WRITE;

//newInterestOps &= ~SelectionKey.OP_READ;

} else {

newInterestOps &= ~SelectionKey.OP_WRITE;

//newInterestOps |= SelectionKey.OP_READ;

}

key.interestOps(newInterestOps);

}

開發者ID:eclipse,項目名稱:neoscada,代碼行數:21,

示例5: NIOServerCnxn

​點讚 3

import java.nio.channels.SelectionKey; //導入方法依賴的package包/類

public NIOServerCnxn(ZooKeeperServer zk, SocketChannel sock,

SelectionKey sk, NIOServerCnxnFactory factory) throws IOException {

this.zkServer = zk;

this.sock = sock;

this.sk = sk;

this.factory = factory;

if (this.factory.login != null) {

你可能感兴趣的:(java,selectionkey)