本文整理匯總了Java中org.apache.thrift.server.TServer類的典型用法代碼示例。如果您正苦於以下問題:Java TServer類的具體用法?Java TServer怎麽用?Java TServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TServer類屬於org.apache.thrift.server包,在下文中一共展示了TServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
TMultiplexedProcessor proc = new TMultiplexedProcessor();
proc.registerProcessor("Message", new Message.Processor<>(new MessageHandler()));
proc.registerProcessor("ServerTime", new ServerTime.Processor<>(new ServerTimeHandler()));
TServer server = new TThreadedSelectorServer(
new TThreadedSelectorServer.Args(trans_svr)
.processor(proc)
.protocolFactory(new TJSONProtocol.Factory())
.workerThreads(6)
.selectorThreads(3));
Thread server_thread = new Thread(new RunnableServer(server), "server_thread");
server_thread.start();
System.out.println("[Server] press enter to shutdown> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
System.out.println("[Server] shutting down...");
server.stop();
server_thread.join();
System.out.println("[Server] down, exiting");
}
示例2: poolServer
import org.apache.thrift.server.TServer; //導入依賴的package包/類
@Bean(name = "pool-server")
public TServer poolServer() throws Exception {
TServerTransport transport = new TServerSocket(this.port());
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.transportFactory(new TTransportFactory());
args.protocolFactory(new TBinaryProtocol.Factory());
args.processor(this.processor());
args.executorService(new ThreadPoolExecutor(env.getProperty(
"rpc.server.min.worker.threads", Integer.class, 512), env
.getProperty("rpc.server.max.worker.threads", Integer.class,
65535), env.getProperty(
"rpc.server.thread.keep.alive.time", Long.class, 600l),
TimeUnit.SECONDS, new SynchronousQueue<Runnable>()));
return new TThreadPoolServer(args);
}
示例3: startSchedulerThriftService
import org.apache.thrift.server.TServer; //導入依賴的package包/類
/**
* @Title: startSchedulerThriftService
* @Description: 開啟scheduler 同步、異步調用服務
* @return void 返回類型
*/
private static void startSchedulerThriftService() {
LOG.info("start scheduler thrift service....");
new Thread() {
@Override
public void run(){
try {
SchedulerServiceImpl schedulerServiceImpl = SpringUtil.getBean(SchedulerServiceImpl.class);
TProcessor tprocessor = new SchedulerService.Processor<SchedulerService.Iface>(schedulerServiceImpl);
TServerSocket serverTransport = new TServerSocket(PropertyLoader.THRIFT_SCHEDULER_PORT);
TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
ttpsArgs.processor(tprocessor);
ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
//線程池服務模型,使用標準的阻塞式IO,預先創建一組線程處理請求。
TServer server = new TThreadPoolServer(ttpsArgs);
server.serve();
} catch (Exception e) {
LOG.error("start scheduler thrift service error,msg:"+ExceptionUtil.getStackTraceAsString(e));
}
}
}.start();
LOG.info("start scheduler thrift server success!");
}
示例4: startServer
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public void startServer() {
try {
logger.info("TSimpleServer start ....");
// TMultiplexedProcessor
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor("Algorithm",
new AlgorithmService.Processor<>(new AlgorithmServiceImpl()));
TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
TServer.Args args = new TServer.Args(serverTransport);
args.processor(processor);
args.protocolFactory(new TBinaryProtocol.Factory());
// args.protocolFactory(new TJSONProtocol.Factory());
TServer server = new TSimpleServer(args);
server.serve();
} catch (Exception e) {
logger.error("Server start error!!!");
e.printStackTrace();
}
}
示例5: hshaServer
import org.apache.thrift.server.TServer; //導入依賴的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.server.TServer; //導入依賴的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.server.TServer; //導入依賴的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: getTThreadPoolServer
import org.apache.thrift.server.TServer; //導入依賴的package包/類
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
TProcessor processor,
TTransportFactory transportFactory,
int workerThreads,
InetSocketAddress inetSocketAddress,
int backlog,
int clientTimeout)
throws TTransportException {
TServerTransport serverTransport = new TServerSocket(
new TServerSocket.ServerSocketTransportArgs().
bindAddr(inetSocketAddress).backlog(backlog).
clientTimeout(clientTimeout));
log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
if (workerThreads > 0) {
serverArgs.maxWorkerThreads(workerThreads);
}
return new TThreadPoolServer(serverArgs);
}
示例9: start
import org.apache.thrift.server.TServer; //導入依賴的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();
}
}
示例10: stop
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public synchronized void stop() {
final TServer thriftServer = this.thriftServer;
if (thriftServer != null) {
this.service.stop();
thriftServer.stop();
final ThreadPoolExecutor connExecutor = this.thriftThreadPerConnExecutor;
if (connExecutor != null) {
connExecutor.shutdown();
}
this.thriftExecutor.shutdown();
try {
this.thriftMainThread.join(5000L);
// force stop the executor if required
if (this.thriftMainThread.isAlive()) {
if (connExecutor != null) {
connExecutor.shutdownNow();
}
this.thriftExecutor.shutdownNow();
this.thriftMainThread.join();
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
}
示例11: hshaServer
import org.apache.thrift.server.TServer; //導入依賴的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: main
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public static void main(String[] args) {
try {
userProfileServerHandler = new UserProfileServerHandler();
userProfileProcessor = new UserProfileService.Processor(userProfileServerHandler);
TMultiplexedProcessor airavataServerProcessor = new TMultiplexedProcessor();
airavataServerProcessor.registerProcessor("UserProfileService", userProfileProcessor);
TServerTransport serverTransport = new TServerSocket(9190);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(airavataServerProcessor));
System.out.println("Starting User Profile server...");
server.serve();
} catch (Exception x) {
x.printStackTrace();
}
}
示例13: buildTServer
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public TServer buildTServer(Args args)
{
if (DatabaseDescriptor.getClientEncryptionOptions().enabled)
throw new RuntimeException("Client SSL is not supported for non-blocking sockets. Please remove client ssl from the configuration.");
final InetSocketAddress addr = args.addr;
TNonblockingServerTransport serverTransport;
try
{
serverTransport = new TCustomNonblockingServerSocket(addr, args.keepAlive, args.sendBufferSize, args.recvBufferSize);
}
catch (TTransportException e)
{
throw new RuntimeException(String.format("Unable to create thrift socket to %s:%s", addr.getAddress(), addr.getPort()), e);
}
// This is single threaded hence the invocation will be all
// in one thread.
TNonblockingServer.Args serverArgs = new TNonblockingServer.Args(serverTransport).inputTransportFactory(args.inTransportFactory)
.outputTransportFactory(args.outTransportFactory)
.inputProtocolFactory(args.tProtocolFactory)
.outputProtocolFactory(args.tProtocolFactory)
.processor(args.processor);
return new CustomTNonBlockingServer(serverArgs);
}
示例14: startServer2
import org.apache.thrift.server.TServer; //導入依賴的package包/類
public void startServer2() throws Exception
{
AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer);
TServerTransport serverTransport = new TServerSocket(9090);
TServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).processor(processor));
ServerRunner serverRunner = new ServerRunner(server);
Thread serverThread = new Thread(serverRunner);
serverThread.start();
logger.info("Started binary interface");
joinMethods.add(() -> {
try {
serverThread.join();
} catch (InterruptedException ignored) {
}
});
}
示例15: setUp
import org.apache.thrift.server.TServer; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
Log.setLog(new NoLogging());
rc = copyResourceTo("/pvdrc", temp.getRoot());
copyResourceTo("/test.thrift", temp.getRoot());
impl = Mockito.mock(MyService.Iface.class);
TServerSocket transport = new TServerSocket(0);
server = new TSimpleServer(
new TServer.Args(transport)
.protocolFactory(new TBinaryProtocol.Factory())
.processor(new MyService.Processor<>(impl)));
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
Thread.sleep(1);
port = transport.getServerSocket().getLocalPort();
exitCode = 0;
rpc = new RPC(console.tty()) {
@Override
protected void exit(int i) {
exitCode = i;
}
};
}