updateThreadPoolConfig(); initializeChannelGroup(); socketChannel = AsynchronousSocketChannel.open(channelGroup); openedConnections.incrementAndGet();
@SuppressWarnings("deprecation") private void initializeSocketChannel(final AsyncCompletionHandler<Void> handler, final Queue<SocketAddress> socketAddressQueue) { if (socketAddressQueue.isEmpty()) { handler.failed(new MongoSocketException("Exception opening socket", serverAddress)); } else { SocketAddress socketAddress = socketAddressQueue.poll(); try { AsynchronousSocketChannel attemptConnectionChannel = AsynchronousSocketChannel.open(group); attemptConnectionChannel.setOption(StandardSocketOptions.TCP_NODELAY, true); attemptConnectionChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, settings.isKeepAlive()); if (settings.getReceiveBufferSize() > 0) { attemptConnectionChannel.setOption(StandardSocketOptions.SO_RCVBUF, settings.getReceiveBufferSize()); } if (settings.getSendBufferSize() > 0) { attemptConnectionChannel.setOption(StandardSocketOptions.SO_SNDBUF, settings.getSendBufferSize()); } attemptConnectionChannel.connect(socketAddress, null, new OpenCompletionHandler(handler, socketAddressQueue, attemptConnectionChannel)); } catch (IOException e) { handler.failed(new MongoSocketOpenException("Exception opening socket", serverAddress, e)); } catch (Throwable t) { handler.failed(t); } } }
AsynchronousSocketChannel clientChannel = AsynchronousSocketChannel.open(); Future connected = localSocket.connect(ourServerSocketAddress); // later: if(future.isDone()) connected.get(); //Send something OutputStream os = Channels.newOutputStream(clientChannel ); os.write (...)
//Create an Asynchronous channel. No connection has actually been established yet AsynchronousSocketChannel asynchronousSocketChannel = AsynchronousSocketChannel.open(); /**Connect to an actual server on the given port and address. The operation returns a type of Future, the basis of the all asynchronous operations in java. In this case, a Void is returned because nothing is returned after a successful socket connection */ Void connect = asynchronousSocketChannel.connect(new InetSocketAddress("127.0.0.1", 5000)).get(); //Allocate data structures to use to communicate over the wire ByteBuffer helloBuffer = ByteBuffer.wrap("Hello !".getBytes()); //Send the message Future<Integer> successfullyWritten= asynchronousSocketChannel.write(helloBuffer); //Do some stuff here. The point here is that asynchronousSocketChannel.write() //returns almost immediately, not waiting to actually finish writing //the hello to the channel before returning control to the currently executing thread doSomethingElse(); //now you can come back and check if it was all written (or not) System.out.println("Bytes written "+successfullyWritten.get());
protected AsynchronousSocketChannel openAsynchronousSocketChannel( SocketAddress address, AsynchronousChannelGroup group) throws IOException { return AsynchronousSocketChannel.open(group); }
protected AsynchronousSocketChannel openAsynchronousSocketChannel( SocketAddress address, AsynchronousChannelGroup group) throws IOException { return AsynchronousSocketChannel.open(group); }
public static AsynchronousSocketChannel open() throws IOException { return open(null); }
protected AsynchronousSocketChannel openAsynchronousSocketChannel( SocketAddress address, AsynchronousChannelGroup group) throws IOException { return AsynchronousSocketChannel.open(group); }
public AsyncTimeClientHandler(String host, int port){ this.host = host; this.port = port; try{ client = AsynchronousSocketChannel.open(); }catch(IOException e){ e.printStackTrace(); } }
public AsyncTimeClientHandler(String host, int port) { this.host = host; this.port = port; try { client = AsynchronousSocketChannel.open(); } catch (IOException e) { e.printStackTrace(); } }
public AsyncClientHandler(String host, int port) { this.host = host; this.port = port; try { //첽Ŀͻͨ clientChannel = AsynchronousSocketChannel.open(); } catch (IOException e) { e.printStackTrace(); } } @Override
@Override public Socket sslClient(SSLContext sslc) throws IOException { AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(); return new Nio2SSLSocket(channel, sslc, true); }
@Override public Socket client() throws IOException { AsynchronousSocketChannel channel = AsynchronousSocketChannel.open(); return new Nio2Socket(channel); }
public static FiberSocketChannel open(SocketAddress remote) throws IOException { return new FiberSocketChannel(AsynchronousSocketChannel.open()); }
@Override FiberSocketChannel newFiberSocketChannel() throws IOException { return new AsyncFiberSocketChannel(AsynchronousSocketChannel.open(group)); }
protected NetworkChannel openSocketChannel(boolean isAIO) throws IOException { if (isAIO) { return AsynchronousSocketChannel.open(DbleServer.getInstance().getNextAsyncChannelGroup()); } else { SocketChannel channel = null; channel = SocketChannel.open(); channel.configureBlocking(false); return channel; } }
void ready() { try { channel = AsynchronousSocketChannel.open(); channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true); Future<Void> future = channel.connect(remote.getAddress()); if (future.get() != null) { log.log(Level.WARNING, "Can't connect to {0}", remote); } else { log.log(Level.INFO, "Connected to server {0}", remote); } } catch (Exception e) { e.printStackTrace(); } }
public AsyncDirectTcpTransport(int soTimeout, PacketHandlers<D, P> handlers, AsynchronousChannelGroup group) throws IOException { this.soTimeout = soTimeout; this.handlers = handlers; this.socketChannel = AsynchronousSocketChannel.open(group); this.packetReader = new AsyncPacketReader<>(this.socketChannel, handlers.getPacketFactory(), handlers.getReceiver()); this.writeQueue = new LinkedBlockingQueue<>(); this.connected = new AtomicBoolean(false); this.writingNow = new AtomicBoolean(false); }
public AsyncDirectTcpTransport(int soTimeout, PacketHandlers<D, P> handlers, AsynchronousChannelGroup group) throws IOException { this.soTimeout = soTimeout; this.handlers = handlers; this.socketChannel = AsynchronousSocketChannel.open(group); this.packetReader = new AsyncPacketReader<>(this.socketChannel, handlers.getPacketFactory(), handlers.getReceiver()); this.writeQueue = new LinkedBlockingQueue<>(); this.connected = new AtomicBoolean(false); this.writingNow = new AtomicBoolean(false); }
InetSocketAddress serverAddress = new InetSocketAddress(InetAddress.getByName("10.1.1.98"), 1236); AsynchronousSocketChannel clientSocketChannel = AsynchronousSocketChannel.open(); clientSocketChannel.connect(hostAddress).get(); ByteBuffer buffer = getBuffer(); clientSocketChannel.read(buffer, Void, new ReadHandler(buffer));