Java Code Examples for org.xnio.IoFuture#Status

The following examples show how to use org.xnio.IoFuture#Status . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneralTimeoutHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;
}
 
Example 2
Source File: JConsoleCLIPlugin.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 3
Source File: ProtocolConnectionUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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());
}
 
Example 4
Source File: ProtocolTimeoutHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * 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);