Example usage for org.apache.thrift.transport TNonblockingSocket getSocketChannel

List of usage examples for org.apache.thrift.transport TNonblockingSocket getSocketChannel

Introduction

In this page you can find the example usage for org.apache.thrift.transport TNonblockingSocket getSocketChannel.

Prototype

public SocketChannel getSocketChannel() 

Source Link

Document

Returns a reference to the underlying SocketChannel.

Usage

From source file:com.netflix.suro.input.thrift.CustomServerSocket.java

License:Apache License

protected TNonblockingSocket acceptImpl() throws TTransportException {
    if (serverSocket_ == null) {
        throw new TTransportException(TTransportException.NOT_OPEN, "No underlying server socket.");
    }// ww  w  .  j a v a2  s.com
    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);
    }
}

From source file:org.apache.accumulo.server.rpc.CustomNonBlockingServer.java

License:Apache License

@Override
protected Runnable getRunnable(final FrameBuffer frameBuffer) {
    return new Runnable() {
        @Override//from   w w  w.  j a  v  a  2s. c  om
        public void run() {
            if (frameBuffer instanceof CustomNonblockingFrameBuffer) {
                TNonblockingTransport trans = ((CustomNonblockingFrameBuffer) frameBuffer).getTransport();
                if (trans instanceof TNonblockingSocket) {
                    TNonblockingSocket tsock = (TNonblockingSocket) trans;
                    Socket sock = tsock.getSocketChannel().socket();
                    TServerUtils.clientAddress
                            .set(sock.getInetAddress().getHostAddress() + ":" + sock.getPort());
                }
            }
            frameBuffer.invoke();
        }
    };
}

From source file:org.apache.accumulo.server.rpc.CustomThreadedSelectorServer.java

License:Apache License

@Override
protected Runnable getRunnable(FrameBuffer frameBuffer) {
    return () -> {

        try {//from   w  w  w .  j  a v  a 2s.c om
            TNonblockingTransport transport = getTransport(frameBuffer);

            if (transport instanceof TNonblockingSocket) {
                // This block of code makes the client address available to the server side code that
                // executes a RPC. It is made available for informational purposes.
                TNonblockingSocket tsock = (TNonblockingSocket) transport;
                Socket sock = tsock.getSocketChannel().socket();
                TServerUtils.clientAddress.set(sock.getInetAddress().getHostAddress() + ":" + sock.getPort());
            }
        } catch (Exception e) {
            LoggerFactory.getLogger(CustomThreadedSelectorServer.class).warn("Failed to get client address ",
                    e);
        }
        frameBuffer.invoke();
    };
}

From source file:org.apache.cassandra.CustomTNonBlockingServer.java

License:Apache License

@Override
@SuppressWarnings("resource")
protected boolean requestInvoke(FrameBuffer frameBuffer) {
    TNonblockingSocket socket = (TNonblockingSocket) ((CustomFrameBuffer) frameBuffer).getTransport();
    ThriftSessionManager.instance.setCurrentSocket(socket.getSocketChannel().socket().getRemoteSocketAddress());
    frameBuffer.invoke();//  www. j a  va2 s .c  om
    return true;
}

From source file:org.apache.cassandra.thrift.TCustomNonblockingServerSocket.java

License:Apache License

@Override
@SuppressWarnings("resource")
protected TNonblockingSocket acceptImpl() throws TTransportException {
    TNonblockingSocket tsocket = super.acceptImpl();
    if (tsocket == null || tsocket.getSocketChannel() == null)
        return tsocket;
    Socket socket = tsocket.getSocketChannel().socket();
    try {/*  w  ww.j a  v a 2 s .  c o  m*/
        socket.setKeepAlive(this.keepAlive);
    } catch (SocketException se) {
        logger.warn("Failed to set keep-alive on Thrift socket.", se);
    }

    if (this.sendBufferSize != null) {
        try {
            socket.setSendBufferSize(this.sendBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set send buffer size on Thrift socket.", se);
        }
    }

    if (this.recvBufferSize != null) {
        try {
            socket.setReceiveBufferSize(this.recvBufferSize.intValue());
        } catch (SocketException se) {
            logger.warn("Failed to set receive buffer size on Thrift socket.", se);
        }
    }
    return tsocket;
}

From source file:org.apache.cassandra.thrift.THsHaDisruptorServer.java

License:Apache License

@Override
protected void beforeInvoke(Message buffer) {
    TNonblockingSocket socket = (TNonblockingSocket) buffer.transport;
    ThriftSessionManager.instance.setCurrentSocket(socket.getSocketChannel().socket().getRemoteSocketAddress());
}

From source file:org.apache.cassandra.thrift.THsHaDisruptorServer.java

License:Apache License

public void beforeClose(Message buffer) {
    TNonblockingSocket socket = (TNonblockingSocket) buffer.transport;
    ThriftSessionManager.instance//w w w.  j  a  v a 2s  . c  om
            .connectionComplete(socket.getSocketChannel().socket().getRemoteSocketAddress());
}