Search in sources :

Example 1 with TransportOptions

use of io.crossbar.autobahn.wamp.types.TransportOptions in project autobahn-java by crossbario.

the class Client method connect.

public CompletableFuture<ExitInfo> connect(TransportOptions options) {
    CompletableFuture<ExitInfo> exitFuture = new CompletableFuture<>();
    mSession.addOnConnectListener((session) -> mSession.join(mRealm, mAuthenticators).thenAccept(details -> LOGGER.i(String.format("JOINED session=%s realm=%s", details.sessionID, details.realm))));
    mSession.addOnDisconnectListener((session, wasClean) -> exitFuture.complete(new ExitInfo(wasClean)));
    CompletableFuture.runAsync(() -> {
        try {
            mTransports.get(0).connect(mSession, options);
        } catch (Exception e) {
            throw new CompletionException(e);
        }
    }, getExecutor());
    return exitFuture;
}
Also used : List(java.util.List) Executor(java.util.concurrent.Executor) ITransport(io.crossbar.autobahn.wamp.interfaces.ITransport) IABLogger(io.crossbar.autobahn.utils.IABLogger) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) TransportOptions(io.crossbar.autobahn.wamp.types.TransportOptions) Platform(io.crossbar.autobahn.wamp.utils.Platform) ABLogger(io.crossbar.autobahn.utils.ABLogger) ArrayList(java.util.ArrayList) IAuthenticator(io.crossbar.autobahn.wamp.interfaces.IAuthenticator) ExitInfo(io.crossbar.autobahn.wamp.types.ExitInfo) CompletableFuture(java.util.concurrent.CompletableFuture) ExitInfo(io.crossbar.autobahn.wamp.types.ExitInfo) CompletionException(java.util.concurrent.CompletionException) CompletionException(java.util.concurrent.CompletionException)

Example 2 with TransportOptions

use of io.crossbar.autobahn.wamp.types.TransportOptions in project autobahn-java by crossbario.

the class NettyWebSocket method connect.

@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
    if (options == null) {
        if (mOptions == null) {
            options = new TransportOptions();
        } else {
            options = new TransportOptions();
            options.setAutoPingInterval(mOptions.getAutoPingInterval());
            options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
            options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
        }
    }
    URI uri;
    uri = new URI(mUri);
    int port = validateURIAndGetPort(uri);
    String scheme = uri.getScheme();
    String host = uri.getHost();
    final SslContext sslContext = getSSLContext(scheme);
    WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
    mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
    EventLoopGroup group = new NioEventLoopGroup();
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(group);
    bootstrap.channel(NioSocketChannel.class);
    TransportOptions opt = options;
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline channelPipeline = ch.pipeline();
            if (sslContext != null) {
                channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
            }
            channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
        }
    });
    mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
    mHandler.getHandshakeFuture().sync();
}
Also used : WebSocketClientHandshaker(io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) TransportOptions(io.crossbar.autobahn.wamp.types.TransportOptions) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) URI(java.net.URI) SSLException(javax.net.ssl.SSLException) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) Bootstrap(io.netty.bootstrap.Bootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

TransportOptions (io.crossbar.autobahn.wamp.types.TransportOptions)2 ABLogger (io.crossbar.autobahn.utils.ABLogger)1 IABLogger (io.crossbar.autobahn.utils.IABLogger)1 IAuthenticator (io.crossbar.autobahn.wamp.interfaces.IAuthenticator)1 ITransport (io.crossbar.autobahn.wamp.interfaces.ITransport)1 ExitInfo (io.crossbar.autobahn.wamp.types.ExitInfo)1 Platform (io.crossbar.autobahn.wamp.utils.Platform)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 WebSocketClientHandshaker (io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker)1 SslContext (io.netty.handler.ssl.SslContext)1 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)1 URI (java.net.URI)1