本文整理匯總了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;
}