本文整理汇总了Java中org.jboss.netty.channel.Channel.setInterestOps方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.setInterestOps方法的具体用法?Java Channel.setInterestOps怎么用?Java Channel.setInterestOps使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.setInterestOps方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 尝试连接
*/
public void connect() {
ChannelFuture future = bootstrap.connect(inetAddr);
try{
boolean ret = future.awaitUninterruptibly(Constants.TIMEOUT_CONNECTION_MILLSECOND, TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyRpcConnection.this.channel;
if (oldChannel != null) {
logger.info("Close old netty channel {} on create new netty channel {}", oldChannel, newChannel);
oldChannel.close();
}
} finally {
if (!isConnected()) {
try {
logger.info("Close new netty channel {}, because the client closed.", newChannel);
newChannel.close();
} finally {
NettyRpcConnection.this.channel = null;
}
} else {
NettyRpcConnection.this.channel = newChannel;
}
}
} else if (null != future.getCause()) {
logger.error("connect fail", future.getCause());
throw new RuntimeException("connect error", future.getCause());
} else {
logger.error("connect fail,connstr: "+this.getConnStr());
throw new RuntimeException("connect error");
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}
示例2: doConnect
import org.jboss.netty.channel.Channel; //导入方法依赖的package包/类
protected void doConnect() throws Throwable {
long start = System.currentTimeMillis();
ChannelFuture future = bootstrap.connect(getConnectAddress());
try{
boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
if (ret && future.isSuccess()) {
Channel newChannel = future.getChannel();
newChannel.setInterestOps(Channel.OP_READ_WRITE);
try {
// 关闭旧的连接
Channel oldChannel = NettyClient.this.channel; // copy reference
if (oldChannel != null) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel);
}
oldChannel.close();
} finally {
NettyChannel.removeChannelIfDisconnected(oldChannel);
}
}
} finally {
if (NettyClient.this.isClosed()) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close new netty channel " + newChannel + ", because the client closed.");
}
newChannel.close();
} finally {
NettyClient.this.channel = null;
NettyChannel.removeChannelIfDisconnected(newChannel);
}
} else {
NettyClient.this.channel = newChannel;
}
}
} else if (future.getCause() != null) {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause());
} else {
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server "
+ getRemoteAddress() + " client-side timeout "
+ getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client "
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion());
}
}finally{
if (! isConnected()) {
future.cancel();
}
}
}