本文整理汇总了Java中org.jboss.netty.channel.ChannelFuture.await方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelFuture.await方法的具体用法?Java ChannelFuture.await怎么用?Java ChannelFuture.await使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.channel.ChannelFuture
的用法示例。
在下文中一共展示了ChannelFuture.await方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
boolean success = true;
int timeout = 0;
try {
ChannelFuture future = channel.write(message);
if (sent) {
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.await(timeout);
}
Throwable cause = future.getCause();
if (cause != null) {
throw cause;
}
} catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
if(! success) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
+ "in timeout(" + timeout + "ms) limit");
}
}
示例2: send
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
boolean success = true;
int timeout = 0;
try {
ChannelFuture future = channel.write(message);
//FIXME sent为true的话 要等待数据写完才返回,失败抛出异常 add by jileng
if (sent) {
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
// 写超时了,难道不能取消这次写操作?
success = future.await(timeout);
}
Throwable cause = future.getCause();
if (cause != null) {
throw cause;
}
} catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
if(! success) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
+ "in timeout(" + timeout + "ms) limit");
}
}
示例3: send
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent); //调用父类的send方法进行异常判断
boolean success = true;
int timeout = 0;
try {
//NIO框架通知执行写操作
ChannelFuture future = channel.write(message);
if (sent) {//如果已经发送成功
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.await(timeout);
}
//获得失败原因
Throwable cause = future.getCause();
if (cause != null) {
throw cause;
}
} catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
if(! success) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
+ "in timeout(" + timeout + "ms) limit");
}
}
示例4: write
import org.jboss.netty.channel.ChannelFuture; //导入方法依赖的package包/类
public void write(byte[] data, int offest, int length) throws IOException {
ChannelBuffer channelBuffer = ChannelBuffers.wrappedBuffer(data, offest, length);
ChannelFuture channelFuture = httpChannel.channel().write(channelBuffer);
try {
channelFuture.await();
} catch (InterruptedException e) {
throw new IOException(e);
}
if(!channelFuture.isSuccess()){
logger.error("stream write fail. connected[{}]", channelFuture.getChannel().isConnected());
throw new IOException();
}
}