Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.kristofa.brave.zipkin;
 
 import  org.apache.thrift.TException;
 import  org.apache.thrift.protocol.TBinaryProtocol;
 import  org.apache.thrift.protocol.TProtocol;
 import  org.apache.thrift.transport.TFramedTransport;
 import  org.apache.thrift.transport.TSocket;
 import  org.apache.thrift.transport.TTransport;
import  org.apache.thrift.transport.TTransportException;
ThriftClientProvider for ZipkinCollector.

Author(s):
adriaens
    private final static Logger LOGGER = LoggerFactory.getLogger(ZipkinCollectorClientProvider.class);
    private final String host;
    private final int port;
    private final int timeout;
    private TTransport transport;
    private ZipkinCollector.Client client;

    
Create a new instance.

Parameters:
host Host. Should not be empty.
port Port.
timeout Socket time out in milliseconds.
    public ZipkinCollectorClientProvider(final String hostfinal int portfinal int timeout) {
        Validate.notEmpty(host);
        this. = host;
        this. = port;
        this. = timeout;
    }

    
    @Override
    public void setup() throws TException {
        final TSocket socket = new TSocket();
        socket.setTimeout();
         = new TFramedTransport(socket);
        final TProtocol protocol = new TBinaryProtocol();
         = new ZipkinCollector.Client(protocol);
        .open();
    }

    
    @Override
    public Client getClient() {
        return ;
    }

    
    @Override
    public Client exception(final TException exception) {
        .error("Thrift exception."exception);
        if (exception instanceof TTransportException) {
            // Close existing transport.
            close();
            try {
                setup();
            } catch (final TException e) {
                .error("Trying to reconnect to Thrift server failed."e);
                return null;
            }
            return ;
        }
        return null;
    }

    
    @Override
    public void close() {
        if ( != null) {
            .close();
        }
    }
New to GrepCode? Check out our FAQ X