Search in sources :

Example 31 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project incubator-heron by apache.

the class ScribeSink method open.

// Open the TTransport connection and client to scribe server
private boolean open() {
    try {
        TSocket socket = new TSocket((String) config.get(KEY_SCRIBE_HOST), TypeUtils.getInteger(config.get(KEY_SCRIBE_PORT)), TypeUtils.getInteger(config.get(KEY_SCRIBE_TIMEOUT_MS)));
        transport = new TFramedTransport(socket);
        transport.open();
    } catch (TException tx) {
        LOG.log(Level.SEVERE, "Failed to open connection to scribe server " + connectionString(), tx);
        return false;
    }
    LOG.info("Opened connection to scribe server " + connectionString());
    TProtocol protocol = new TBinaryProtocol(transport);
    client = new scribe.Client(protocol);
    return true;
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TSocket(org.apache.thrift.transport.TSocket) org.apache.scribe.scribe(org.apache.scribe.scribe)

Example 32 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project summer by foxsugar.

the class RpcManager method charge.

private static void charge(String ip, int id, int num) throws TException {
    TTransport adminTransport = new TFramedTransport(new TSocket(ip, 9090));
    adminTransport.open();
    // TTransport adminTransport = TransportManager.getTransport(ip, 9090);
    GameRPC.Client client = GameRpcClient.getAClient(adminTransport);
    // client.getUserInfo(1);
    Order order = new Order();
    order.setUserId(id);
    order.setNum(num);
    order.setType(1);
    int rtn = client.charge(order);
    adminTransport.close();
    // 充值成功
    if (rtn == 0) {
    // todo 插入一条充值记录
    }
}
Also used : Order(com.code.server.rpc.idl.Order) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) GameRPC(com.code.server.rpc.idl.GameRPC) TSocket(org.apache.thrift.transport.TSocket)

Example 33 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project dubbo by alibaba.

the class ThriftProtocol method doReferFrameAndCompact.

private <T> T doReferFrameAndCompact(Class<T> type, URL url) throws RpcException {
    try {
        T thriftClient = null;
        String typeName = type.getName();
        if (typeName.endsWith(THRIFT_IFACE)) {
            String clientClsName = typeName.substring(0, typeName.indexOf(THRIFT_IFACE)) + THRIFT_CLIENT;
            Class<?> clazz = Class.forName(clientClsName);
            Constructor constructor = clazz.getConstructor(TProtocol.class);
            try {
                TSocket tSocket = new TSocket(url.getHost(), url.getPort());
                TTransport transport = new TFramedTransport(tSocket);
                TProtocol tprotocol = new TCompactProtocol(transport);
                TMultiplexedProtocol protocol = new TMultiplexedProtocol(tprotocol, typeName);
                thriftClient = (T) constructor.newInstance(protocol);
                transport.open();
                logger.info("nativethrift client opened for service(" + url + ")");
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                throw new RpcException("Fail to create remote client:" + e.getMessage(), e);
            }
        }
        return thriftClient;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RpcException("Fail to create remote client for service(" + url + "): " + e.getMessage(), e);
    }
}
Also used : TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) Constructor(java.lang.reflect.Constructor) TFramedTransport(org.apache.thrift.transport.TFramedTransport) RpcException(org.apache.dubbo.rpc.RpcException) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TException(org.apache.thrift.TException) RpcException(org.apache.dubbo.rpc.RpcException) TSocket(org.apache.thrift.transport.TSocket)

Example 34 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project logprocessing by cloudian.

the class CassandraClient method open.

public void open() throws IOException {
    try {
        this.currentServer = this.serverSet.get();
    } catch (ServerSet.NoServersAvailableException e) {
        throw new IOException("No Cassandra servers available.");
    }
    int splitIndex = this.currentServer.indexOf(':');
    if (splitIndex == -1) {
        throw new IOException("Bad host:port pair: " + this.currentServer);
    }
    String host = this.currentServer.substring(0, splitIndex);
    int port = Integer.parseInt(this.currentServer.substring(splitIndex + 1));
    TSocket sock = new TSocket(host, port);
    this.transport = new TFramedTransport(sock);
    TProtocol protocol = new TBinaryProtocol(transport);
    this.client = new Cassandra.Client(protocol);
    try {
        this.transport.open();
        this.client.set_keyspace(this.keyspace);
    } catch (TException texc) {
        throw new IOException(texc.getMessage());
    } catch (InvalidRequestException exc) {
        throw new IOException(exc.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) Cassandra(org.apache.cassandra.thrift.Cassandra) IOException(java.io.IOException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TSocket(org.apache.thrift.transport.TSocket)

Example 35 with TFramedTransport

use of org.apache.thrift.transport.TFramedTransport in project tech by ffyyhh995511.

the class ThriftService2 method getDistributedIncrease.

/**
 * 分布式递增
 * @return
 */
public long getDistributedIncrease() {
    int timeout = 100 * 1000;
    TTransport transport = null;
    Long increase = 0L;
    try {
        // 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
        transport = new TFramedTransport(new TSocket("192.168.11.173", 7911, timeout));
        transport.open();
        // 使用高密度二进制协议
        TProtocol protocol = new TCompactProtocol(transport);
        // 创建Client
        ServerTime.Client client = new ServerTime.Client(protocol);
        increase = client.getIncrease();
    } catch (Exception e) {
        // logger.error(e.getStackTrace());
        e.printStackTrace();
    } finally {
        // 关闭资源
        if (transport != null) {
            transport.close();
        }
    }
    return increase;
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) ServerTime(org.tech.commons.model.ServerTime) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TFramedTransport (org.apache.thrift.transport.TFramedTransport)45 TSocket (org.apache.thrift.transport.TSocket)41 TTransport (org.apache.thrift.transport.TTransport)32 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)25 TProtocol (org.apache.thrift.protocol.TProtocol)24 TException (org.apache.thrift.TException)14 IOException (java.io.IOException)11 TTransportException (org.apache.thrift.transport.TTransportException)11 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 Cassandra (org.apache.cassandra.thrift.Cassandra)4 Hello (org.tech.model.Hello)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 GameRPC (com.code.server.rpc.idl.GameRPC)2 UnknownHostException (java.net.UnknownHostException)2 SSLSocket (javax.net.ssl.SSLSocket)2 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)2 ConfigurationException (org.apache.cassandra.config.ConfigurationException)2 AuthenticationRequest (org.apache.cassandra.thrift.AuthenticationRequest)2 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)2