本文整理汇总了Java中org.apache.mina.common.WriteFuture.join方法的典型用法代码示例。如果您正苦于以下问题:Java WriteFuture.join方法的具体用法?Java WriteFuture.join怎么用?Java WriteFuture.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.common.WriteFuture
的用法示例。
在下文中一共展示了WriteFuture.join方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.apache.mina.common.WriteFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
boolean success = true;
int timeout = 0;
try {
WriteFuture future = session.write(message);
if (sent) {
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.join(timeout);
}
} 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.apache.mina.common.WriteFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
if (isClosed()) {
throw new RemotingException(this, "Failed to send message "
+ (message == null ? "" : message.getClass().getName()) + ":" + message
+ ", cause: Channel closed. channel: " + getLocalAddress() + " -> " + getRemoteAddress());
}
boolean success = true;
int timeout = 0;
try {
WriteFuture future = session.write(message);
if (sent) {
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.join(timeout);
}
} 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.apache.mina.common.WriteFuture; //导入方法依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
boolean success = true;
int timeout = 0;
try {
WriteFuture future = session.write(message);
if (sent) {
timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.join(timeout);
}
} 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: writeBody
import org.apache.mina.common.WriteFuture; //导入方法依赖的package包/类
/**
* Asynchronously writes the given body to MINA session. Will wait at most for
* 10 seconds until the body has been written.
*
* @param session the MINA session
* @param body the body to write (send)
* @param exchange the exchange
* @throws CamelExchangeException is thrown if the body could not be written for some reasons
* (eg remote connection is closed etc.)
*/
public static void writeBody(IoSession session, Object body, Exchange exchange) throws CamelExchangeException {
// the write operation is asynchronous. Use WriteFuture to wait until the session has been written
WriteFuture future = session.write(body);
// must use a timeout (we use 10s) as in some very high performance scenarios a write can cause
// thread hanging forever
LOG.trace("Waiting for write to complete for body: {} using session: {}", body, session);
future.join(10000L);
if (!future.isWritten()) {
throw new CamelExchangeException("Cannot write body: " + body + " using session: " + session, exchange);
}
}