本文整理汇总了Java中org.xnio.IoFuture.Status方法的典型用法代码示例。如果您正苦于以下问题:Java IoFuture.Status方法的具体用法?Java IoFuture.Status怎么用?Java IoFuture.Status使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xnio.IoFuture
的用法示例。
在下文中一共展示了IoFuture.Status方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectBlocking
import org.xnio.IoFuture; //导入方法依赖的package包/类
/**
* Blocking connection attempt to the given URI endpoint
*
* @param timeout time to wait in seconds before aborting connection attempt
* @return true if connected; false otherwise
* @throws IOException if something goes wrong with XNIO worker
*/
@Override
public boolean connectBlocking(long timeout) throws IOException {
logger.debug("Connect blocking... ({})", this);
IoFuture<WebSocketChannel> futureChan = connectionBuilder().connect();
IoFuture.Status status = futureChan.await(timeout, TimeUnit.SECONDS);
logger.debug("Connect blocking status: {}", status);
switch (status) {
case DONE:
// ok
this.channel = futureChan.get();
this.channel.setIdleTimeout(this.idleTimeout);
registerChannelReceivers();
return true;
default:
// error or interrupted or timed-out
return false;
}
}
示例2: connectBlocking
import org.xnio.IoFuture; //导入方法依赖的package包/类
@Override
public boolean connectBlocking(long timeout) throws IOException {
logger.debug("Connect blocking... ({})", this);
IoFuture<WebSocketChannel> futureChan = connectionBuilder().connect();
IoFuture.Status status = futureChan.await(timeout, TimeUnit.MILLISECONDS);
logger.debug("Connect blocking status: {}", status);
switch (status) {
case DONE:
// ok
this.channel = futureChan.get();
registerChannelReceivers();
return true;
default:
handlerService.submit(() -> onError(futureChan.getException()));
try {
Thread.sleep(reconnectDelay);
return this.connectBlocking(timeout);
} catch (InterruptedException e) {
logger.warn("Connect blocking interrupted while sleeping", e);
}
// error or interrupted or timed-out
return false;
}
}
示例3: await
import org.xnio.IoFuture; //导入方法依赖的package包/类
@Override
public Status await(IoFuture<?> future, long timeoutMillis) {
final long startTime = System.currentTimeMillis();
IoFuture.Status status = future.await(timeoutMillis, TimeUnit.MILLISECONDS);
while (status == IoFuture.Status.WAITING) {
if (thinking) {
status = future.await(timeoutMillis, TimeUnit.MILLISECONDS);
} else {
long timeToWait = (timeoutMillis + thinkTime.get()) - (System.currentTimeMillis() - startTime);
if (timeToWait > 0) {
status = future.await(timeToWait, TimeUnit.MILLISECONDS);
} else {
return status;
}
}
}
return status;
}
示例4: connectUsingRemoting
import org.xnio.IoFuture; //导入方法依赖的package包/类
private boolean connectUsingRemoting(CommandContext cmdCtx, RemotingMBeanServerConnection rmtMBeanSvrConn)
throws IOException, CliInitializationException {
Connection conn = rmtMBeanSvrConn.getConnection();
Channel channel;
final IoFuture<Channel> futureChannel = conn.openChannel("management", OptionMap.EMPTY);
IoFuture.Status result = futureChannel.await(5, TimeUnit.SECONDS);
if (result == IoFuture.Status.DONE) {
channel = futureChannel.get();
} else {
futureChannel.cancel();
return false;
}
ModelControllerClient modelCtlrClient = ExistingChannelModelControllerClient.createReceiving(channel, createExecutor());
cmdCtx.bindClient(modelCtlrClient);
return true;
}
示例5: connectSync
import org.xnio.IoFuture; //导入方法依赖的package包/类
/**
* Connect sync.
*
* @param configuration the protocol configuration
* @return the connection
* @throws IOException
*/
public static Connection connectSync(final ProtocolConnectionConfiguration configuration) throws IOException {
long timeoutMillis = configuration.getConnectionTimeout();
CallbackHandler handler = configuration.getCallbackHandler();
final CallbackHandler actualHandler;
ProtocolTimeoutHandler timeoutHandler = configuration.getTimeoutHandler();
// Note: If a client supplies a ProtocolTimeoutHandler it is taking on full responsibility for timeout management.
if (timeoutHandler == null) {
GeneralTimeoutHandler defaultTimeoutHandler = new GeneralTimeoutHandler();
// No point wrapping our AnonymousCallbackHandler.
actualHandler = handler != null ? new WrapperCallbackHandler(defaultTimeoutHandler, handler) : null;
timeoutHandler = defaultTimeoutHandler;
} else {
actualHandler = handler;
}
final IoFuture<Connection> future = connect(actualHandler, configuration);
IoFuture.Status status = timeoutHandler.await(future, timeoutMillis);
if (status == IoFuture.Status.DONE) {
return future.get();
}
if (status == IoFuture.Status.FAILED) {
throw ProtocolLogger.ROOT_LOGGER.failedToConnect(configuration.getUri(), future.getException());
}
throw ProtocolLogger.ROOT_LOGGER.couldNotConnect(configuration.getUri());
}
示例6: await
import org.xnio.IoFuture; //导入方法依赖的package包/类
/**
* Wait for the specified time on the supplied {@link IoFuture}, taking into account that some of this time could actually
* not be related to the establishment of the connection but instead some local task such as user think time.
*
* @param future - The {@link IoFuture} to wait on.
* @param timeoutMillis - The configures timeout in milliseconds.
* @return The {@link IoFuture.Status} when available or at the time the timeout is reached - whichever is soonest.
*/
IoFuture.Status await(IoFuture<?> future, long timeoutMillis);