当前位置: 首页>>代码示例>>Java>>正文


Java IoFuture类代码示例

本文整理汇总了Java中org.xnio.IoFuture的典型用法代码示例。如果您正苦于以下问题:Java IoFuture类的具体用法?Java IoFuture怎么用?Java IoFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IoFuture类属于org.xnio包,在下文中一共展示了IoFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChannel

import org.xnio.IoFuture; //导入依赖的package包/类
private static Channel getChannel ( ConnectionProviderContextImpl context, ConnectionHandler ch, OptionMap options ) throws IOException {
    Channel c;
    FutureResult<Channel> chResult = new FutureResult<Channel>(context.getExecutor());
    ch.open("jmx", chResult, options);

    IoFuture<Channel> cFuture = chResult.getIoFuture();
    Status s2 = cFuture.await();
    if ( s2 == Status.FAILED ) {
        System.err.println("Cannot connect");
        if ( cFuture.getException() != null ) {
            throw new IOException("Connect failed", cFuture.getException());
        }
    }
    else if ( s2 != Status.DONE ) {
        cFuture.cancel();
        throw new IOException("Connect timeout");
    }

    c = cFuture.get();
    return c;
}
 
开发者ID:hucheat,项目名称:APacheSynapseSimplePOC,代码行数:22,代码来源:JBoss.java

示例2: readRequestData

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public IoFuture<byte[]> readRequestData() {
    final ByteArrayOutputStream data = new ByteArrayOutputStream();
    try {
        final ServletInputStream in = request.getInputStream();
        byte[] buf = new byte[1024];
        int r;
        while ((r = in.read(buf)) != -1) {
            data.write(buf, 0, r);
        }
        return new FinishedIoFuture<>(data.toByteArray());
    } catch (IOException e) {
        final FutureResult<byte[]> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ServletWebSocketHttpExchange.java

示例3: connect

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final Pool<ByteBuffer> bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AjpClientProvider.java

示例4: connect

import org.xnio.IoFuture; //导入依赖的package包/类
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, XnioSsl ssl, Pool<ByteBuffer> bufferPool, OptionMap options) {
    ClientProvider provider = getClientProvider(uri);
    final FutureResult<ClientConnection> result = new FutureResult<>();
    provider.connect(new ClientCallback<ClientConnection>() {
        @Override
        public void completed(ClientConnection r) {
            result.setResult(r);
        }

        @Override
        public void failed(IOException e) {
            result.setException(e);
        }
    }, bindAddress, uri, worker, ssl, bufferPool, options);
    return result.getIoFuture();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:UndertowClient.java

示例5: readRequestData

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public IoFuture<byte[]> readRequestData() {
    final ByteArrayOutputStream data = new ByteArrayOutputStream();
    try {
        byte[] buf = new byte[1024];
        int r;
        while ((r = in.read(buf)) != -1) {
            data.write(buf, 0, r);
        }
        return new FinishedIoFuture<>(data.toByteArray());
    } catch (IOException e) {
        final FutureResult<byte[]> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:BlockingWebSocketHttpServerExchange.java

示例6: connect

import org.xnio.IoFuture; //导入依赖的package包/类
/**
 * Non-blocking connection attempt to the given URI endpoint
 * @throws XNIOException if unable to create XNIO worker
 */
@Override
public void connect() throws XNIOException {
    logger.debug("Trying to connect to {}", this.uri);
    IoFuture<WebSocketChannel> chanFuture = connectionBuilder().connect();
    chanFuture.addNotifier((ioFuture, client) -> {
        if (ioFuture.getStatus() == IoFuture.Status.DONE) {
            try {
                this.channel = ioFuture.get();
                this.channel.setIdleTimeout(this.idleTimeout);
                registerChannelReceivers();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            handlerService.submit(() -> onError(ioFuture.getException()));
        }
    }, this);
}
 
开发者ID:BraindeadCrew,项目名称:java-websocket,代码行数:23,代码来源:WebSocketClientImpl.java

示例7: 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;
    }
}
 
开发者ID:BraindeadCrew,项目名称:java-websocket,代码行数:27,代码来源:WebSocketClientImpl.java

示例8: connect

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public void connect() throws XNIOException {
    logger.debug("Trying to connect to {} ... {}", this.uri, this);
    connectionBuilder().connect().addNotifier(((ioFuture, client) -> {
        if (ioFuture.getStatus() == IoFuture.Status.DONE) {
            // ok
            try {
                this.channel = ioFuture.get();
                registerChannelReceivers();
                logger.debug("Connected :) {}", this.uri, this);
            } catch (IOException ignore) {}
        } else {
            handlerService.submit(() -> onError(ioFuture.getException()));
            startReconnectTask();
        }
    }), this);
}
 
开发者ID:BraindeadCrew,项目名称:java-websocket,代码行数:18,代码来源:ReconnectWebSocketClient.java

示例9: 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;
    }
}
 
开发者ID:BraindeadCrew,项目名称:java-websocket,代码行数:26,代码来源:ReconnectWebSocketClient.java

示例10: 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;
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:GeneralTimeoutHandler.java

示例11: openChannel

import org.xnio.IoFuture; //导入依赖的package包/类
Channel openChannel(final Connection connection) throws IOException {
    final IoFuture<Channel> future = connection.openChannel(DEFAULT_CHANNEL_SERVICE_TYPE, OptionMap.EMPTY);
    future.await(10L, TimeUnit.SECONDS);
    if (future.getStatus() == IoFuture.Status.WAITING) {
        future.cancel();
        throw ProtocolLogger.ROOT_LOGGER.channelTimedOut();
    }
    final Channel channel = future.get();
    channel.addCloseHandler(new CloseHandler<Channel>() {
        @Override
        public void handleClose(final Channel old, final IOException e) {
            synchronized (ChannelStrategy.this) {
                if(ChannelStrategy.this.channel == old) {
                    ChannelStrategy.this.handler.handleClose(old, e);
                    ChannelStrategy.this.channel = null;
                }
            }
            handler.handleChannelClosed(old, e);
        }
    });
    return channel;
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:23,代码来源:DomainTestConnection.java

示例12: 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;
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:19,代码来源:JConsoleCLIPlugin.java

示例13: sendData

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public IoFuture<Void> sendData(final ByteBuffer data) {
    try {
        final ServletOutputStream outputStream = response.getOutputStream();
        while (data.hasRemaining()) {
            outputStream.write(data.get());
        }
        return new FinishedIoFuture<>(null);
    } catch (IOException e) {
        final FutureResult<Void> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ServletWebSocketHttpExchange.java

示例14: createNotifier

import org.xnio.IoFuture; //导入依赖的package包/类
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:HttpClientProvider.java

示例15: sendData

import org.xnio.IoFuture; //导入依赖的package包/类
@Override
public IoFuture<Void> sendData(final ByteBuffer data) {
    try {
        while (data.hasRemaining()) {
            out.write(data.get());
        }
        return new FinishedIoFuture<>(null);
    } catch (IOException e) {
        final FutureResult<Void> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:BlockingWebSocketHttpServerExchange.java


注:本文中的org.xnio.IoFuture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。