Search in sources :

Example 1 with UnsafeSocketSession

use of com.generallycloud.baseio.component.UnsafeSocketSession in project baseio by generallycloud.

the class ClientHttpFuture method updateWebSocketProtocol.

@Override
public void updateWebSocketProtocol() {
    ChannelConnector connector = (ChannelConnector) context.getChannelService();
    UnsafeSocketSession session = (UnsafeSocketSession) connector.getSession();
    SocketChannel channel = session.getSocketChannel();
    channel.setProtocolFactory(WebSocketProtocolFactory.WS_PROTOCOL_FACTORY);
    channel.setProtocolDecoder(WebSocketProtocolFactory.WS_PROTOCOL_DECODER);
    channel.setProtocolEncoder(WebSocketProtocolFactory.WS_PROTOCOL_ENCODER);
}
Also used : SocketChannel(com.generallycloud.baseio.component.SocketChannel) UnsafeSocketSession(com.generallycloud.baseio.component.UnsafeSocketSession) ChannelConnector(com.generallycloud.baseio.connector.ChannelConnector)

Example 2 with UnsafeSocketSession

use of com.generallycloud.baseio.component.UnsafeSocketSession in project baseio by generallycloud.

the class AioSocketChannelConnector method connect.

@Override
protected void connect(InetSocketAddress socketAddress) throws IOException {
    AsynchronousChannelGroup group = context.getAsynchronousChannelGroup();
    final AsynchronousSocketChannel _channel = AsynchronousSocketChannel.open(group);
    _channel.connect(socketAddress, this, new CompletionHandler<Void, AioSocketChannelConnector>() {

        @Override
        public void completed(Void result, AioSocketChannelConnector connector) {
            CachedAioThread aioThread = (CachedAioThread) Thread.currentThread();
            AioSocketChannel channel = new AioSocketChannel(aioThread, _channel, 1);
            connector.finishConnect(channel.getSession(), null);
            aioThread.getReadCompletionHandler().completed(0, channel);
        }

        @Override
        public void failed(Throwable exc, AioSocketChannelConnector connector) {
            connector.finishConnect((UnsafeSocketSession) getSession(), exc);
        }
    });
    wait4connect();
}
Also used : CachedAioThread(com.generallycloud.baseio.component.CachedAioThread) AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) UnsafeSocketSession(com.generallycloud.baseio.component.UnsafeSocketSession) AsynchronousChannelGroup(java.nio.channels.AsynchronousChannelGroup) AioSocketChannel(com.generallycloud.baseio.component.AioSocketChannel)

Aggregations

UnsafeSocketSession (com.generallycloud.baseio.component.UnsafeSocketSession)2 AioSocketChannel (com.generallycloud.baseio.component.AioSocketChannel)1 CachedAioThread (com.generallycloud.baseio.component.CachedAioThread)1 SocketChannel (com.generallycloud.baseio.component.SocketChannel)1 ChannelConnector (com.generallycloud.baseio.connector.ChannelConnector)1 AsynchronousChannelGroup (java.nio.channels.AsynchronousChannelGroup)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1