use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.
the class TBaseStream method write.
public void write(final TBase<?, ?> base) throws TException {
final TBaseStreamNode node = new TBaseStreamNode(transport);
node.setClassName(base.getClass().getName());
node.setBeginPosition(transport.getBufferPosition());
final TProtocol protocol = protocolFactory.getProtocol(transport);
base.write(protocol);
node.setEndPosition(transport.getBufferPosition());
nodes.add(node);
}
use of org.apache.thrift.protocol.TProtocol in project brisk by riptano.
the class ThriftUtils method createNamenodeClient.
/**
* Creates a Thrift name node client.
*
* @param conf the HDFS instance
* @return a Thrift name node client.
*/
public static Namenode.Client createNamenodeClient(Configuration conf) throws Exception {
String s = conf.get(NamenodePlugin.THRIFT_ADDRESS_PROPERTY, NamenodePlugin.DEFAULT_THRIFT_ADDRESS);
// TODO(todd) use fs.default.name here if set to 0.0.0.0 - but share this with the code in
// SecondaryNameNode that does the same
InetSocketAddress addr = NetUtils.createSocketAddr(s);
// in the thrift config.
if (addr.getAddress().isAnyLocalAddress()) {
InetSocketAddress nnAddr = NameNode.getAddress(conf);
addr = new InetSocketAddress(nnAddr.getAddress(), addr.getPort());
}
TTransport t = new TSocket(addr.getHostName(), addr.getPort());
if (UserGroupInformation.isSecurityEnabled()) {
t = new HadoopThriftAuthBridge.Client().createClientTransport(conf.get(DFSConfigKeys.DFS_NAMENODE_USER_NAME_KEY), addr.getHostName(), "KERBEROS", t);
}
t.open();
TProtocol p = new TBinaryProtocol(t);
return new Namenode.Client(p);
}
use of org.apache.thrift.protocol.TProtocol in project carat by amplab.
the class CommunicationManager method safeClose.
public static void safeClose(CaratService.Client c) {
if (c == null)
return;
TProtocol i = c.getInputProtocol();
TProtocol o = c.getOutputProtocol();
if (i != null) {
TTransport it = i.getTransport();
if (it != null)
it.close();
}
if (o != null) {
TTransport it = o.getTransport();
if (it != null)
it.close();
}
}
use of org.apache.thrift.protocol.TProtocol in project carat by amplab.
the class ProtocolClient method getInstance.
/**
* FIXME: this needs to come from a factory, so that connections are not
* kept open unnecessarily, and that they do not become stale, and that we
* handle disconnections gracefully.
*
* @param c
* @return
* @throws NumberFormatException
* @throws TTransportException
*/
public static CaratService.Client getInstance(Context c) throws NumberFormatException, TTransportException {
if (SERVER_ADDRESS == null) {
Properties properties = new Properties();
try {
InputStream raw = c.getAssets().open(SERVER_PROPERTIES);
if (raw != null) {
properties.load(raw);
if (properties.containsKey("PORT"))
SERVER_PORT = Integer.parseInt(properties.getProperty("PORT", "8080"));
if (properties.containsKey("ADDRESS"))
SERVER_ADDRESS = properties.getProperty("ADDRESS", "server.caratproject.com");
Log.d(TAG, "Set address=" + SERVER_ADDRESS + " port=" + SERVER_PORT);
} else
Log.e(TAG, "Could not open server property file!");
} catch (IOException e) {
Log.e(TAG, "Could not open server property file: " + e.toString());
}
}
if (SERVER_ADDRESS == null || SERVER_PORT == 0)
return null;
TSocket soc = new TSocket(SERVER_ADDRESS, SERVER_PORT, 60000);
TProtocol p = new TBinaryProtocol(soc, true, true);
CaratService.Client instance = new CaratService.Client(p);
if (soc != null && !soc.isOpen())
soc.open();
return instance;
}
use of org.apache.thrift.protocol.TProtocol in project disruptor_thrift_server by xedin.
the class Message method invoke.
/**
* Actually invoke the method signified by this Message.
*/
public void invoke() {
assert state == State.READ_FRAME_COMPLETE : "Invoke called in invalid state: " + state;
TTransport inTrans = getInputTransport();
TProtocol inProt = thriftFactories.inputProtocolFactory.getProtocol(inTrans);
TProtocol outProt = thriftFactories.outputProtocolFactory.getProtocol(getOutputTransport());
try {
thriftFactories.processorFactory.getProcessor(inTrans).process(inProt, outProt);
responseReady();
return;
} catch (TException te) {
logger.warn("Exception while invoking!", te);
} catch (Throwable t) {
logger.error("Unexpected throwable while invoking!", t);
}
// This will only be reached when there is a throwable.
state = State.AWAITING_CLOSE;
changeSelectInterests();
}
Aggregations