本文整理匯總了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();
}
}