Factory fac = new AsyncClient.Factory(new TAsyncClientManager(), new TProtocolFactory() { @Override public TProtocol getProtocol( TTransport trans ) { return new TBinaryProtocol(trans); } }); AsyncClient cl = fac.getAsyncClient( new TNonblockingSocket( "127.0.0.1", 12345 ));
@Override public void invoke() { if (trans_ instanceof TNonblockingSocket) { TNonblockingSocket tsock = (TNonblockingSocket) trans_; Socket sock = tsock.getSocketChannel().socket(); TServerUtils.clientAddress .set(sock.getInetAddress().getHostAddress() + ":" + sock.getPort()); } super.invoke(); } }
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(0); // disabling client timeout tsocket.getSocketChannel().socket().setKeepAlive(true); tsocket.getSocketChannel().socket().setSendBufferSize(config.getSocketSendBufferBytes()); tsocket.getSocketChannel().socket().setReceiveBufferSize(config.getSocketRecvBufferBytes()); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress) throws IOException { socketChannel_ = socketChannel; socketAddress_ = socketAddress; // make it a nonblocking channel socketChannel.configureBlocking(false); // set options Socket socket = socketChannel.socket(); socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); socket.setKeepAlive(true); setTimeout(timeout); }
/** * Returns a reference to the underlying socket. */ public Socket getSocket() { if (socket_ == null) { initSocket(); } return socket_; }
private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress) throws IOException { socketChannel_ = socketChannel; socketAddress_ = socketAddress; // make it a nonblocking channel socketChannel.configureBlocking(false); // set options Socket socket = socketChannel.socket(); socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); setTimeout(timeout); }
instances.add( fac.getAsyncClient( new TNonblockingSocket( host, port ) ) );
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
public void beforeClose(Message buffer) { TNonblockingSocket socket = (TNonblockingSocket) buffer.transport; ThriftSessionManager.instance.connectionComplete(socket.getSocketChannel().socket().getRemoteSocketAddress()); }
private TNonblockingSocket(SocketChannel socketChannel, int timeout, SocketAddress socketAddress) throws IOException { socketChannel_ = socketChannel; socketAddress_ = socketAddress; // make it a nonblocking channel socketChannel.configureBlocking(false); // set options Socket socket = socketChannel.socket(); socket.setSoLinger(false, 0); socket.setTcpNoDelay(true); setTimeout(timeout); }
TNonblockingTransport transport = new TNonblockingSocket("127.0.0.1", 9160); TAsyncClientManager clientManager = new TAsyncClientManager(); TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); Hive.AsyncClient client = new Hive.AsyncClient(protocolFactory, clientManager, transport);
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
@Override protected void beforeInvoke(Message buffer) { TNonblockingSocket socket = (TNonblockingSocket) buffer.transport; ThriftSessionManager.instance.setCurrentSocket(socket.getSocketChannel().socket().getRemoteSocketAddress()); }
TNonblockingTransport transport = new TNonblockingSocket("127.0.0.1", 9160); TAsyncClientManager clientManager = new TAsyncClientManager(); TProtocolFactory protocolFactory = new TBinaryProtocol.Factory(); Cassandra.AsyncClient client = new Cassandra.AsyncClient(protocolFactory, clientManager, transport); Cassandra.method_call(parameters, new Callback());
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
@Override protected void beforeInvoke(Message buffer) { TNonblockingSocket socket = (TNonblockingSocket) buffer.transport; ThriftSessionManager.instance.setCurrentSocket(socket.getSocketChannel().socket().getRemoteSocketAddress()); }
public ThriftAsyncClient(String host, int port) throws IOException, TTransportException { this.host = host; this.port = port; this.client = new Send.AsyncClient(new TBinaryProtocol.Factory(), new TAsyncClientManager(), new TNonblockingSocket(host, port)); logger.info("set up client on host " + this.host + " , port " + this.port); }
protected TNonblockingSocket acceptImpl() throws TTransportException { if (serverSocket_ == null) { throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket."); } try { SocketChannel socketChannel = serverSocketChannel.accept(); if (socketChannel == null) { return null; } TNonblockingSocket tsocket = new TNonblockingSocket(socketChannel); tsocket.setTimeout(clientTimeout_); return tsocket; } catch (IOException iox) { throw new TTransportException(iox); } }
@Override protected void beforeInvoke(Message buffer) { TNonblockingSocket socket = (TNonblockingSocket) buffer.transport; ThriftSessionManager.instance.setCurrentSocket(socket.getSocketChannel().socket().getRemoteSocketAddress()); }