Example usage for org.apache.thrift.transport TSocket getSocket

List of usage examples for org.apache.thrift.transport TSocket getSocket

Introduction

In this page you can find the example usage for org.apache.thrift.transport TSocket getSocket.

Prototype

public Socket getSocket() 

Source Link

Document

Returns a reference to the underlying socket.

Usage

From source file:alluxio.network.thrift.SocketTrackingTServerSocket.java

License:Apache License

@Override
public TSocket acceptImpl() throws TTransportException {
    TSocket socket = super.acceptImpl();
    mSockets.add(socket.getSocket());
    return socket;
}

From source file:bidiDemo.server.MessageServiceClient.java

public MessageServiceClient(TTransport trans) {
    transport = trans;/*from   ww w .  j  a v  a  2 s  . c o  m*/
    TSocket tsocket = (TSocket) transport;
    client = new MessageService.Client(new TBinaryProtocol(transport));
    address = tsocket.getSocket().getInetAddress().getHostAddress();
    port = tsocket.getSocket().getPort();
}

From source file:com.cloudera.flume.handlers.thrift.AckServiceClient.java

License:Apache License

public AckServiceClient(TTransport transport) {

    if (!transport.getClass().equals(TStatsTransport.class)) {
        String errMsg = String.format("Expecting %s wrapped in %s.", TStatsTransport.class.getName(),
                transport.getClass().getName());
        LOG.error(errMsg);//  w w  w . j a v a2s  . c om
        throw new Error(errMsg);
    }
    TStatsTransport strans = (TStatsTransport) transport;

    TTransport trans = strans.getTransport();

    if (!trans.getClass().equals(TSocket.class)) {
        String errMsg = String.format("Expecting %s wrapped in %s.", TSocket.class.getName(),
                trans.getClass().getName());
        LOG.error(errMsg);
        throw new Error(errMsg);
    }
    TSocket tsocket = (TSocket) trans;

    this.transport = transport;
    this.client = new ThriftFlumeEventServer.Client(new TBinaryProtocol(transport));
    this.addr = tsocket.getSocket().getInetAddress().getHostAddress();
    this.hostName = tsocket.getSocket().getInetAddress().getCanonicalHostName();
    this.port = tsocket.getSocket().getPort();

    int localPort = tsocket.getSocket().getLocalPort();
    LOG.info("Get new client. HostName: " + this.hostName + ", local port: " + localPort + ", remote port: "
            + this.port);
}

From source file:com.flipkart.phantom.thrift.impl.ThriftProxy.java

License:Apache License

/**
 * Returns the specified TSocket back to the pool
 * @param socket the pooled TSocket instance
 * @param isConnectionValid flag to indicate if the socket was found to be invalid during use
 *//*from w w w  . ja va2 s.  co  m*/
public void returnPooledSocket(TSocket socket, boolean isConnectionValid) {
    try {
        if (isConnectionValid) {
            this.socketPool.returnObject(socket.getSocket());
        } else {
            this.socketPool.invalidateObject(socket.getSocket());
        }
    } catch (Exception e) {
        LOGGER.error("Error while returning TSocket : " + e.getMessage(), e);
        throw new RuntimeException("Error while borrowing TSocket : " + e.getMessage(), e);
    }
}

From source file:com.icloud.framework.thrift.server.TCustomServerSocket.java

License:Apache License

@Override
protected TSocket acceptImpl() throws TTransportException {
    TSocket tsocket = super.acceptImpl();
    Socket socket = tsocket.getSocket();

    try {//from  www  .j  a  va  2 s . c  om
        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:com.netflix.metacat.thrift.CatalogThriftEventHandler.java

License:Apache License

/**
 * {@inheritDoc}// w  w w  .  j a v a 2  s  . co  m
 */
@Override
public ServerContext createContext(final TProtocol input, final TProtocol output) {
    final String userName = "metacat-thrift-interface";
    String clientHost = null; //requestContext.getHeaderString("X-Forwarded-For");
    final long requestThreadId = Thread.currentThread().getId();

    final TTransport transport = input.getTransport();
    if (transport instanceof TSocket) {
        final TSocket thriftSocket = (TSocket) transport;
        clientHost = thriftSocket.getSocket().getInetAddress().getHostAddress();
    }

    final CatalogServerRequestContext context = new CatalogServerRequestContext(userName, null, clientHost,
            null, "hive", requestThreadId);
    MetacatContextManager.setContext(context);
    return context;
}

From source file:com.netflix.suro.server.HealthCheck.java

License:Apache License

private SuroServer.Client getClient(String host, int port, int timeout)
        throws SocketException, TTransportException {
    TSocket socket = new TSocket(host, port, timeout);
    socket.getSocket().setTcpNoDelay(true);
    socket.getSocket().setKeepAlive(true);
    socket.getSocket().setSoLinger(true, 0);
    TTransport transport = new TFramedTransport(socket);
    transport.open();/*from   ww w  .  j av a2  s  . c  om*/

    TProtocol protocol = new TBinaryProtocol(transport);

    return new SuroServer.Client(protocol);
}

From source file:com.palantir.atlasdb.keyvalue.cassandra.CassandraClientFactory.java

License:Open Source License

public static Cassandra.Client getClientInternal(InetSocketAddress addr, boolean isSsl, int socketTimeoutMillis,
        int socketQueryTimeoutMillis) throws TTransportException {
    TSocket tSocket = new TSocket(addr.getHostString(), addr.getPort(), socketTimeoutMillis);
    tSocket.open();//  www  .  j  a v  a2 s . co  m
    try {
        tSocket.getSocket().setKeepAlive(true);
        tSocket.getSocket().setSoTimeout(socketQueryTimeoutMillis);
    } catch (SocketException e) {
        log.error("Couldn't set socket keep alive for {}", addr);
    }

    if (isSsl) {
        boolean success = false;
        try {
            SSLSocketFactory factory = sslSocketFactories.getUnchecked(addr);
            SSLSocket socket = (SSLSocket) factory.createSocket(tSocket.getSocket(), addr.getHostString(),
                    addr.getPort(), true);
            tSocket = new TSocket(socket);
            success = true;
        } catch (IOException e) {
            throw new TTransportException(e);
        } finally {
            if (!success) {
                tSocket.close();
            }
        }
    }
    TTransport tFramedTransport = new TFramedTransport(tSocket,
            CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES);
    TProtocol protocol = new TBinaryProtocol(tFramedTransport);
    Cassandra.Client client = new Cassandra.Client(protocol);
    return client;
}

From source file:com.twitter.common.thrift.monitoring.TMonitoredServerSocket.java

License:Apache License

@Override
protected TSocket acceptImpl() throws TTransportException {
    final TSocket socket = super.acceptImpl();
    final InetSocketAddress remoteAddress = (InetSocketAddress) socket.getSocket().getRemoteSocketAddress();

    TSocket monitoredSocket = new TSocket(socket.getSocket()) {
        boolean closed = false;

        @Override//from w  w w  .  j  a  va2 s  .c  o m
        public void close() {
            try {
                super.close();
            } finally {
                if (!closed) {
                    monitor.released(remoteAddress);
                    addressMap.remove(this);
                }
                closed = true;
            }
        }
    };

    addressMap.put(monitoredSocket, remoteAddress);

    monitor.connected(remoteAddress);
    return monitoredSocket;
}

From source file:org.apache.accumulo.core.rpc.TBufferedSocket.java

License:Apache License

public TBufferedSocket(TSocket sock, int bufferSize) throws IOException {
    super(new BufferedInputStream(sock.getSocket().getInputStream(), bufferSize),
            new BufferedOutputStream(sock.getSocket().getOutputStream(), bufferSize));
    client = sock.getSocket().getInetAddress().getHostAddress() + ":" + sock.getSocket().getPort();
}