本文整理汇总了Java中org.apache.thrift.transport.TFramedTransport类的典型用法代码示例。如果您正苦于以下问题:Java TFramedTransport类的具体用法?Java TFramedTransport怎么用?Java TFramedTransport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TFramedTransport类属于org.apache.thrift.transport包,在下文中一共展示了TFramedTransport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createNativeTransport
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
/**
* 根据rc的设置来确定创建什么类型的transport;
*
* @param instance
* @return
*/
protected TTransport createNativeTransport(
ServiceInstance<RpcPayload> instance) {
TSocket socket = new TSocket(instance.getAddress(), instance.getPort());
socket.setTimeout(socketTimeout);
RpcPayload server = instance.getPayload();
if ((server == null) || (server.getTransport() == null)
|| (server.getTransport().equals("socket"))) {
return socket;
} else if ("framed-transport".equals(server.getTransport())) {
return new TFramedTransport(socket);
}
// for default, use TSocket;
return socket;
}
示例2: logThrift
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
try {
TSocket socket = new TSocket(address.getHost(), address.getPort());
socket.open();
try {
TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
}
finally {
socket.close();
}
}
catch (TException e) {
throw new RuntimeException(e);
}
return 1;
}
示例3: run
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
public void run() {
try {
Scribe.Processor processor = new Scribe.Processor(new Receiver());
TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(transport);
args.workerThreads(workers);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory(maxReadBufferBytes));
args.protocolFactory(new TBinaryProtocol.Factory(false, false));
args.maxReadBufferBytes = maxReadBufferBytes;
server = new THsHaServer(args);
LOG.info("Starting Scribe Source on port " + port);
server.serve();
} catch (Exception e) {
LOG.warn("Scribe failed", e);
}
}
示例4: testScribeMessage
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
@Test
public void testScribeMessage() throws Exception {
TTransport transport = new TFramedTransport(new TSocket("localhost", port));
TProtocol protocol = new TBinaryProtocol(transport);
Scribe.Client client = new Scribe.Client(protocol);
transport.open();
LogEntry logEntry = new LogEntry("INFO", "Sending info msg to scribe source");
List<LogEntry> logEntries = new ArrayList<LogEntry>(1);
logEntries.add(logEntry);
client.Log(logEntries);
// try to get it from Channels
Transaction tx = memoryChannel.getTransaction();
tx.begin();
Event e = memoryChannel.take();
Assert.assertNotNull(e);
Assert.assertEquals("Sending info msg to scribe source", new String(e.getBody()));
tx.commit();
tx.close();
}
示例5: hshaServer
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
/**
* The function to create a thrift Half-Sync and Half-Async Server.
* @param processor
*/
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
try {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
args.protocolFactory(new TBinaryProtocol.Factory(true, true));
TServer server = new THsHaServer(args);
log.info("Starting the packetstreamer hsha server on port {} ...", port);
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: main
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
public static void main(String[] args){
ExecutorService es = Executors.newFixedThreadPool(2);
for(int i=0; i<ports.length; i++){
final int index = i;
es.execute(new Runnable() {
@Override
public void run() {
try{
TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
arg.protocolFactory(new TBinaryProtocol.Factory());
arg.transportFactory(new TFramedTransport.Factory());
arg.processorFactory(new TProcessorFactory(processor));
TServer server = new TNonblockingServer (arg);
logger.info("127.0.0.1:" + ports[index] + " start");
server.serve();
}catch(Exception e){
logger.error("127.0.0.1:" + ports[index] + " error");
}
}
});
}
}
示例7: main
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
public static void main(String[] args){
ExecutorService es = Executors.newFixedThreadPool(2);
for(int i=0; i<ports.length; i++){
final int index = i;
es.execute(new Runnable() {
@Override
public void run() {
try{
TNonblockingServerSocket socket = new TNonblockingServerSocket(ports[index]);
TestThriftJ.Processor processor = new TestThriftJ.Processor(new QueryImp());
TNonblockingServer.Args arg = new TNonblockingServer.Args(socket);
arg.protocolFactory(new TBinaryProtocol.Factory());
arg.transportFactory(new TFramedTransport.Factory());
arg.processorFactory(new TProcessorFactory(processor));
TServer server = new TNonblockingServer(arg);
logger.info("127.0.0.1:" + ports[index] + " start");
server.serve();
}catch(Exception e){
logger.error("127.0.0.1:" + ports[index] + " error");
}
}
});
}
}
示例8: startClient2
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
public static void startClient2(String ip ,int port ,int timeout) throws Exception
{
TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout));
TProtocol protocol = new TBinaryProtocol(transport);
leafrpc.Client client = new leafrpc.Client(protocol);
transport.open();
for(int i = 0; i< 1000000; i++)
{
client.getID("");
if (i % 100000 == 0)
{
System.out.println(Thread.currentThread().getName() + " " + client.getID(""));
}
//ai.incrementAndGet();
}
transport.close();
}
示例9: makeObject
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
@Override
public TServiceClient makeObject() throws Exception {
InetSocketAddress address = serverAddressProvider.selector();
if(address==null){
new ThriftException("No provider available for remote service");
}
TSocket tsocket = new TSocket(address.getHostName(), address.getPort());
TTransport transport = new TFramedTransport(tsocket);
TProtocol protocol = new TBinaryProtocol(transport);
TServiceClient client = this.clientFactory.getClient(protocol);
transport.open();
if (callback != null) {
try {
callback.make(client);
} catch (Exception e) {
logger.warn("makeObject:{}", e);
}
}
return client;
}
示例10: start
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
public void start(CountDownLatch latch, int port) {
try {
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(port);
//异步IO,需要使用TFramedTransport,它将分块缓存读取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
//使用高密度二进制协议
TProtocolFactory proFactory = new TBinaryProtocol.Factory();
//发布多个服务
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));
TServer server = new TThreadedSelectorServer(new
TThreadedSelectorServer.Args(serverTransport)
.transportFactory(transportFactory)
.protocolFactory(proFactory)
.processor(processor)
);
System.out.println("Starting the hello server...");
latch.countDown();
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: hshaServer
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
/**
* The function to create a thrift Half-Sync and Half-Async Server.
* @param processor
*/
public static void hshaServer(PacketStreamer.Processor<PacketStreamerHandler> processor) {
try {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(port);
THsHaServer.Args args = new THsHaServer.Args(serverTransport);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
args.protocolFactory(new TBinaryProtocol.Factory(true, true));
TServer server = new THsHaServer(args);
log.info("Starting the packetstreamer hsha server on port {} ...", port);
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: connectToCMD
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
private static void connectToCMD() {
QueryInput query_input = new QueryInput();
query_input.type = "ensemble";
query_input.data = new ArrayList<String>();
query_input.data.add("localhost");
query_input.tags = new ArrayList<String>();
query_input.tags.add("9090");
QuerySpec spec = new QuerySpec();
spec.content = new ArrayList<QueryInput>();
spec.content.add(query_input);
// Initialize thrift objects.
TTransport transport = new TSocket("localhost", 8080);
TProtocol protocol = new TBinaryProtocol(new TFramedTransport(transport));
LucidaService.Client client = new LucidaService.Client(protocol);
try {
transport.open();
System.out.println("Connecting to CMD at port " + 8080);
// Register itself to CMD.
client.create("", spec);
transport.close();
System.out.println("Successfully connected to CMD");
} catch (TException x) {
x.printStackTrace();
}
}
示例13: createThrift
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
private static boolean createThrift() {
String flag = getClassName() + ".createThrift";
try {
TProcessor tProcessor = new FrcService.Processor<FrcService.Iface>(theInstance);
TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(thrift_port);
TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
tnbArgs.maxReadBufferBytes = DefaultValues.THRIFT_MAX_READ_BUF;
tnbArgs.processor(tProcessor);
// tnbArgs.transportFactory(new LCQTFramedTransport.Factory());
tnbArgs.transportFactory(new TFramedTransport.Factory());
tnbArgs.protocolFactory(new TBinaryProtocol.Factory());
server = new TNonblockingServer(tnbArgs);
// server.setServerEventHandler(new LCQTServerEventHandler());
return true;
} catch (Exception e) {
FRCLogger.getInstance().warn(-100, flag, "exception", e);
return false;
}
}
示例14: makeObject
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public PooledObject makeObject() throws Exception {
//logger.debug("makeObject...........");
try {
String host = this.host;
int port = this.port;
int timeout = this.timeout;
TFramedTransport transport = new TFramedTransport(new TSocket(host, port, timeout));
TBinaryProtocol protocol = new TBinaryProtocol(transport);
FrcService.Client client = new FrcService.Client(protocol, protocol);
transport.open();
RpcClient<Client> rpcClient = new RpcClient(client, transport, 1);
return this.wrap(rpcClient);
} catch (Exception e) {
logger.error("exception", e);
return null;
}
}
示例15: getPJTClient
import org.apache.thrift.transport.TFramedTransport; //导入依赖的package包/类
/**
* Used for getting a client to the CoronaProxyJobTracker
* @param conf
* @return Returns a client to the CPJT
* @throws IOException
*/
public static CoronaProxyJobTrackerService.Client
getPJTClient(CoronaConf conf) throws IOException {
InetSocketAddress address =
NetUtils.createSocketAddr(conf.getProxyJobTrackerThriftAddress());
TFramedTransport transport = new TFramedTransport(
new TSocket(address.getHostName(), address.getPort()));
CoronaProxyJobTrackerService.Client client =
new CoronaProxyJobTrackerService.Client(new TBinaryProtocol(transport));
try {
transport.open();
} catch (TException e) {
LOG.info("Transport Exception: ", e);
}
return client;
}