public static WebSocketChannel connect(String url, ChannelListener<? super WebSocketChannel> clientEndpoint) { try { WebSocketChannel webSocketChannel = new WebSocketClient.ConnectionBuilder( ClientManager.getWorker(), new DefaultByteBufferPool(false, 2048), URI.create(ClientManager.lookup(url))) .connect().get(); webSocketChannel.getReceiveSetter().set(clientEndpoint); webSocketChannel.resumeReceives(); return webSocketChannel; } catch (Exception e) { throw new RuntimeException(e); } }
IoFuture<WebSocketChannel> connectionFuture = new WebSocketClient.ConnectionBuilder( worker, new DefaultByteBufferPool(false, 2048),
@Override protected synchronized void tryConnect() throws Exception { if (webSocketChannel != null) { return; } shuttingDown = false; logger.info("Connecting to {}", url); webSocketChannel = new WebSocketClient.ConnectionBuilder( worker, new DefaultByteBufferPool(false, 2048), //TODO configurable ? URI.create(url)) .connect() .get(); ProxyClientEndpoint proxyClientEndpoint = new ProxyClientEndpoint(endpoint); webSocketChannel.getReceiveSetter().set(proxyClientEndpoint); webSocketChannel.getCloseSetter().set((ChannelListener<AbstractFramedChannel>) channel -> { if(!clientClose) { closeChannel(); proxyClientEndpoint.onCloseMessage(null, webSocketChannel); reconnect(); } }); proxyClientEndpoint.onConnect(webSocketChannel); webSocketChannel.resumeReceives(); monitor.add(uuid, this::closeChannel); logger.info("Connected to {}", url); clientClose = false; }
public static WebSocketChannel connect(URI uri, ChannelListener<? super WebSocketChannel> clientEndpoint) throws IOException { WebSocketChannel webSocketChannel = new WebSocketClient.ConnectionBuilder( getWorker(), new DefaultByteBufferPool(false, 2048), uri) .connect().get(); webSocketChannel.getReceiveSetter().set(clientEndpoint); webSocketChannel.resumeReceives(); return webSocketChannel; }
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }