當前位置: 首頁>>代碼示例>>Java>>正文


Java TServer類代碼示例

本文整理匯總了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");
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:24,代碼來源:MultiServiceServer.java

示例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);
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:19,代碼來源:HelloServerConfig.java

示例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!");
}
 
開發者ID:elves-project,項目名稱:scheduler,代碼行數:28,代碼來源:ProgramEntrance.java

示例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();
	}
}
 
開發者ID:kaichao,項目名稱:algorithm.annotation,代碼行數:22,代碼來源:SimpleBackendServer.java

示例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();
    }
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:20,代碼來源:PacketStreamerServer.java

示例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");
				}
			}
		});
	}
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:26,代碼來源:ThriftServerTest2.java

示例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");
				}
			}
		});
	}
}
 
開發者ID:cyfonly,項目名稱:ThriftJ,代碼行數:26,代碼來源:ThriftServerTest.java

示例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);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:23,代碼來源:ThriftServer.java

示例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();
    }
}
 
開發者ID:sofn,項目名稱:trpc,代碼行數:25,代碼來源:DemoServer.java

示例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();
    }
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:26,代碼來源:GfxdThriftServer.java

示例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();
    }
}
 
開發者ID:zhenshengcai,項目名稱:floodlight-hardware,代碼行數:20,代碼來源:PacketStreamerServer.java

示例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();
    }
}
 
開發者ID:SciGaP,項目名稱:allocateme,代碼行數:21,代碼來源:UserProfileServer.java

示例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);
}
 
開發者ID:vcostet,項目名稱:cassandra-kmean,代碼行數:26,代碼來源:CustomTNonBlockingServer.java

示例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) {
        }
    });
}
 
開發者ID:coveord,項目名稱:Blitz-2015,代碼行數:20,代碼來源:ReferenceMain.java

示例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;
        }
    };
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:28,代碼來源:RPCThriftSocketTest.java


注:本文中的org.apache.thrift.server.TServer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。