Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.splout.db.dnode;
  * #%L
  * Splout SQL Server
  * %%
  * Copyright (C) 2012 Datasalt Systems S.L.
  * %%
  * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <>.
 * #L%
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;
A Thrift client interface for the DNode service.
public class DNodeClient {

Get a Thrift client given an address (host:port)
	public static DNodeService.Client get(String hostPortthrows TTransportException {
		int separator = hostPort.lastIndexOf(":");
		String host = hostPort.substring(0, separator);
		int port = Integer.parseInt(hostPort.substring(separator + 1, hostPort.length()));
		return get(hostport);

Get a Thrift client given a host and a port
	public static DNodeService.Client get(String hostint portthrows TTransportException {
		TTransport transport = new TFramedTransport(new TSocket(hostport));
		TProtocol protocol = new TBinaryProtocol(transport);
		DNodeService.Client client = new DNodeService.Client(protocol);;
		return client;		

It is not trivial to properly close a Thrift client. This method encapsulates this.
	public static void close(DNodeService.Client client) {
New to GrepCode? Check out our FAQ X