Search in sources :

Example 16 with TProtocol

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);
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol)

Example 17 with TProtocol

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);
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) InetSocketAddress(java.net.InetSocketAddress) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 18 with TProtocol

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();
    }
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport)

Example 19 with TProtocol

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;
}
Also used : CaratService(edu.berkeley.cs.amplab.carat.thrift.CaratService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) TSocket(org.apache.thrift.transport.TSocket)

Example 20 with TProtocol

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();
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport)

Aggregations

TProtocol (org.apache.thrift.protocol.TProtocol)78 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TTransport (org.apache.thrift.transport.TTransport)28 TSocket (org.apache.thrift.transport.TSocket)23 TException (org.apache.thrift.TException)22 TFramedTransport (org.apache.thrift.transport.TFramedTransport)17 IOException (java.io.IOException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)10 THttpClient (org.apache.thrift.transport.THttpClient)9 TTransportException (org.apache.thrift.transport.TTransportException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)7 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 TProcessor (org.apache.thrift.TProcessor)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)4 TTransportFactory (org.apache.thrift.transport.TTransportFactory)4 OutputStream (java.io.OutputStream)3