本文整理匯總了Java中org.apache.thrift.transport.TFramedTransport.Factory方法的典型用法代碼示例。如果您正苦於以下問題:Java TFramedTransport.Factory方法的具體用法?Java TFramedTransport.Factory怎麽用?Java TFramedTransport.Factory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.thrift.transport.TFramedTransport
的用法示例。
在下文中一共展示了TFramedTransport.Factory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
}
示例2: createThreadedSelectorServer
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public static TServer createThreadedSelectorServer(TProcessorFactory processorFactory,
int port, int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
throws TTransportException {
int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
int selectorThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2);
TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
clientTimeoutMillisecs);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport)
.processorFactory(processorFactory).protocolFactory(protocolFactory)
.transportFactory(transportFactory).workerThreads(numThreads)
.acceptPolicy(AcceptPolicy.FAIR_ACCEPT).acceptQueueSizePerThread(10000)
.selectorThreads(selectorThreads);
args.maxReadBufferBytes = maxReadBufferSize;
TThreadedSelectorServer server = new TThreadedSelectorServer(args);
return server;
}
示例3: ThriftServerThread
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public ThriftServerThread(InetAddress listenAddr, int listenPort)
{
// now we start listening for clients
logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort));
TServerFactory.Args args = new TServerFactory.Args();
args.tProtocolFactory = new TBinaryProtocol.Factory(true, true);
args.addr = new InetSocketAddress(listenAddr, listenPort);
args.cassandraServer = new CassandraServer();
args.processor = new Cassandra.Processor(args.cassandraServer);
args.keepAlive = DatabaseDescriptor.getRpcKeepAlive();
args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize();
args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize();
int tFramedTransportSize = DatabaseDescriptor.getThriftFramedTransportSize();
logger.info("Using TFramedTransport with a max frame size of {} bytes.", tFramedTransportSize);
args.inTransportFactory = new TFramedTransport.Factory(tFramedTransportSize);
args.outTransportFactory = new TFramedTransport.Factory(tFramedTransportSize);
serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args);
}
示例4: ConcreteServer
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
/**
*
*/
public ConcreteServer(AnnotateCommunicationService.Iface impl, int port) throws ServerException {
try {
this.serverXport = new TNonblockingServerSocket(port);
// TODO: eval HaHs server?
final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
args.protocolFactory(new TCompactProtocol.Factory());
// TODO: eval FastFramedTransport?
final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
args.transportFactory(transFactory);
// legitimately do not know type bound here - guessing Iface
AnnotateCommunicationService.Processor<Iface> proc = new AnnotateCommunicationService.Processor<>(impl);
args.processorFactory(new TProcessorFactory(proc));
args.maxReadBufferBytes = Long.MAX_VALUE;
this.args = args;
// final TNonblockingServer server = new TNonblockingServer(args);
this.server = new TNonblockingServer(this.args);
} catch (TTransportException e) {
throw new ServerException(e);
}
}
示例5: testProcessor
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
throws Exception
{
try (TServerSocket serverTransport = new TServerSocket(0)) {
TProtocolFactory protocolFactory = new Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory();
TServer server = new TSimpleServer(new Args(serverTransport)
.protocolFactory(protocolFactory)
.transportFactory(transportFactory)
.processor(processor));
Thread serverThread = new Thread(server::serve);
try {
serverThread.start();
int localPort = serverTransport.getServerSocket().getLocalPort();
HostAndPort address = HostAndPort.fromParts("localhost", localPort);
int sum = 0;
for (ToIntFunction<HostAndPort> client : clients) {
sum += client.applyAsInt(address);
}
return sum;
}
finally {
server.stop();
serverThread.interrupt();
}
}
}
示例6: testProcessor
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
throws Exception
{
try (TServerSocket serverTransport = new TServerSocket(0)) {
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory();
TServer server = new TSimpleServer(new Args(serverTransport)
.protocolFactory(protocolFactory)
.transportFactory(transportFactory)
.processor(processor));
Thread serverThread = new Thread(server::serve);
try {
serverThread.start();
int localPort = serverTransport.getServerSocket().getLocalPort();
HostAndPort address = HostAndPort.fromParts("localhost", localPort);
int sum = 0;
for (ToIntFunction<HostAndPort> client : clients) {
sum += client.applyAsInt(address);
}
return sum;
}
finally {
server.stop();
serverThread.interrupt();
}
}
}
示例7: init
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public void init() {
try {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
for (ServiceArgs service : serverArgs.getServices()) {
String className = service.getService();
if (className.endsWith("$Processor")) {
className = className.substring(0, className.indexOf("$Processor"));
}
processor.registerProcessor(className, service.getProcessor());
}
if (serverArgs.getNettyServerArgs() != null) {
this.server = new TNettyServer(serverArgs.getNettyServerArgs().ip(serverArgs.getHost()).port(serverArgs.getPort()));
} else {
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress(serverArgs.getHost(), serverArgs.getPort()));
//異步IO,需要使用TFramedTransport,它將分塊緩存讀取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
//使用高密度二進製協議
TProtocolFactory proFactory = new TBinaryProtocol.Factory();
// Use this for a multithreaded key
this.server = new TThreadedSelectorServer(new
TThreadedSelectorServer.Args(serverTransport)
.transportFactory(transportFactory)
.protocolFactory(proFactory)
.processor(processor)
);
}
log.info("Starting the Thrift key...");
this.server.setServerEventHandler(new TrpcRegistryEventHandler(serverArgs));
this.server.serve();
if (this.serverArgs.getNettyServerArgs() != null) {
((TNettyServer) this.server).waitForClose();
}
} catch (Exception e) {
log.error("publish thrift key error", e);
}
}
示例8: getTTransportFactory
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
private static TTransportFactory getTTransportFactory(boolean framed) {
if (framed) {
log.debug("Using framed transport");
return new TFramedTransport.Factory();
} else {
return new TTransportFactory();
}
}
示例9: createThreadedServer
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public static TServer createThreadedServer(TProcessorFactory processorFactory, int port,
int clientTimeoutMillisecs, int maxFrameSize) throws TTransportException {
int maxWorkerThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
TServerTransport transport = new TServerSocket(port, clientTimeoutMillisecs);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport)
.processorFactory(processorFactory).protocolFactory(protocolFactory)
.transportFactory(transportFactory).minWorkerThreads(1)
.maxWorkerThreads(maxWorkerThreads);
TThreadPoolServer server = new TThreadPoolServer(args);
return server;
}
示例10: createNonBlockingServer
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public static TServer createNonBlockingServer(TProcessorFactory processorFactory, int port,
int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
throws TTransportException {
TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
clientTimeoutMillisecs);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
TNonblockingServer.Args args = new TNonblockingServer.Args(transport)
.processorFactory(processorFactory).protocolFactory(protocolFactory)
.transportFactory(transportFactory);
args.maxReadBufferBytes = maxReadBufferSize;
TNonblockingServer server = new TNonblockingServer(args);
return server;
}
示例11: createHaHsServer
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public static TServer createHaHsServer(TProcessorFactory processorFactory, int port,
int clientTimeoutMillisecs, int maxFrameSize, long maxReadBufferSize)
throws TTransportException {
int numThreads = Math.max(2, Runtime.getRuntime().availableProcessors());
TNonblockingServerTransport transport = new TNonblockingServerSocket(port,
clientTimeoutMillisecs);
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory(maxFrameSize);
THsHaServer.Args args = new THsHaServer.Args(transport).processorFactory(processorFactory)
.protocolFactory(protocolFactory).transportFactory(transportFactory)
.workerThreads(numThreads).stopTimeoutVal(60).stopTimeoutUnit(TimeUnit.SECONDS);
args.maxReadBufferBytes = maxReadBufferSize;
THsHaServer server = new THsHaServer(args);
return server;
}
示例12: SearchServiceWrapper
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
/**
* @param impl
* @param port
* @throws TException
*/
public SearchServiceWrapper(SearchService.Iface impl, int port) throws TException {
this.serverXport = new TNonblockingServerSocket(port);
final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
args.protocolFactory(new TCompactProtocol.Factory());
final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
args.transportFactory(transFactory);
SearchService.Processor<Iface> proc = new SearchService.Processor<>(impl);
args.processorFactory(new TProcessorFactory(proc));
args.maxReadBufferBytes = Long.MAX_VALUE;
this.servArgs = args;
this.server = new TNonblockingServer(this.servArgs);
}
示例13: FetchServiceWrapper
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public FetchServiceWrapper(FetchCommunicationService.Iface impl, int port) throws TException {
this.serverXport = new TNonblockingServerSocket(port);
final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
args.protocolFactory(new TCompactProtocol.Factory());
final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
args.transportFactory(transFactory);
FetchCommunicationService.Processor<Iface> proc = new FetchCommunicationService.Processor<>(impl);
args.processorFactory(new TProcessorFactory(proc));
args.maxReadBufferBytes = Long.MAX_VALUE;
this.servArgs = args;
this.server = new TNonblockingServer(this.servArgs);
}
示例14: SummarizationServiceWrapper
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public SummarizationServiceWrapper(SummarizationService.Iface impl, int port) throws TException {
this.serverXport = new TNonblockingServerSocket(port);
final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
args.protocolFactory(new TCompactProtocol.Factory());
final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
args.transportFactory(transFactory);
SummarizationService.Processor<SummarizationService.Iface> proc = new SummarizationService.Processor<>(impl);
args.processorFactory(new TProcessorFactory(proc));
args.maxReadBufferBytes = Long.MAX_VALUE;
this.servArgs = args;
this.server = new TNonblockingServer(this.servArgs);
}
示例15: StoreServiceWrapper
import org.apache.thrift.transport.TFramedTransport; //導入方法依賴的package包/類
public StoreServiceWrapper(StoreCommunicationService.Iface impl, int port) throws TException {
this.serverXport = new TNonblockingServerSocket(port);
final TNonblockingServer.Args args = new TNonblockingServer.Args(this.serverXport);
args.protocolFactory(new TCompactProtocol.Factory());
final TFramedTransport.Factory transFactory = new TFramedTransport.Factory(Integer.MAX_VALUE);
args.transportFactory(transFactory);
StoreCommunicationService.Processor<Iface> proc = new StoreCommunicationService.Processor<>(impl);
args.processorFactory(new TProcessorFactory(proc));
args.maxReadBufferBytes = Long.MAX_VALUE;
this.servArgs = args;
this.server = new TNonblockingServer(this.servArgs);
}