当前位置: 首页>>代码示例>>Java>>正文


Java TThreadedSelectorServer类代码示例

本文整理汇总了Java中org.apache.thrift.server.TThreadedSelectorServer的典型用法代码示例。如果您正苦于以下问题:Java TThreadedSelectorServer类的具体用法?Java TThreadedSelectorServer怎么用?Java TThreadedSelectorServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TThreadedSelectorServer类属于org.apache.thrift.server包,在下文中一共展示了TThreadedSelectorServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的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: start

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的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

示例3: main

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
public static void main(String[] args) {
	try {
		handler = new CalculatorHandler();
		processor = new Calculator.Processor(handler);
		try {
			TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(9090);
			TServer server = new TThreadedSelectorServer(
					new TThreadedSelectorServer.Args(serverTransport).processor(processor));

			System.out.println("Starting the  server...");
			server.serve();
		} catch (TTransportException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	} catch (Exception x) {
		x.printStackTrace();
	}
}
 
开发者ID:git5hub43,项目名称:springside-engine,代码行数:21,代码来源:StandardNIOServer.java

示例4: getTThreadedSelectorServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,
    TProcessor processor, TTransportFactory transportFactory,
    int workerThreads, int selectorThreads, int maxCallQueueSize,
    InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
    throws TTransportException {
  TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
  log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
  TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
  if (workerThreads > 0) {
    serverArgs.workerThreads(workerThreads);
  }
  if (selectorThreads > 0) {
    serverArgs.selectorThreads(selectorThreads);
  }

  ExecutorService executorService = createExecutor(
      workerThreads, maxCallQueueSize, metrics);
  serverArgs.executorService(executorService);
  serverArgs.processor(processor);
  serverArgs.transportFactory(transportFactory);
  serverArgs.protocolFactory(protocolFactory);
  return new TThreadedSelectorServer(serverArgs);
}
 
开发者ID:apache,项目名称:hbase,代码行数:24,代码来源:ThriftServer.java

示例5: createThreadedSelectorServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的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;
}
 
开发者ID:DDTH,项目名称:osgi-bundle-frontapi,代码行数:19,代码来源:ThriftUtils.java

示例6: main

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
public static void main(String [] args) 
		throws TTransportException, IOException, InterruptedException {	
	Properties port_cfg = new Properties();
	InputStream input = new FileInputStream("../config.properties");
	port_cfg.load(input);
	String port_str = port_cfg.getProperty("CA_PORT");
	Integer port = Integer.valueOf(port_str);
	TProcessor proc = new LucidaService.AsyncProcessor(
			new CAServiceHandler.AsyncCAServiceHandler());
	TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
	TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport)
	.processor(proc)	
	.protocolFactory(new TBinaryProtocol.Factory())
	.transportFactory(new TFramedTransport.Factory());
	final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments);
	System.out.println("CA at port " + port_str);
	server.serve();
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:19,代码来源:CalendarDaemon.java

示例7: main

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
/** 
 * Entry point for question-answer.
 * @param args the argument list. Provide port numbers
 * for both sirius and qa.
 */
public static void main(String [] args) 
		throws TTransportException, IOException, InterruptedException {	
	Properties port_cfg = new Properties();
	InputStream input = new FileInputStream("../../config.properties");
	port_cfg.load(input);
	String port_str = port_cfg.getProperty("QA_PORT");
	Integer port = Integer.valueOf(port_str);
	TProcessor proc = new LucidaService.AsyncProcessor(
			new QAServiceHandler.AsyncQAServiceHandler());
	TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
	TThreadedSelectorServer.Args arguments = new TThreadedSelectorServer.Args(transport)
	.processor(proc)	
	.protocolFactory(new TBinaryProtocol.Factory())
	.transportFactory(new TFramedTransport.Factory());
	final TThreadedSelectorServer server = new TThreadedSelectorServer(arguments);
	System.out.println("QA at port " + port_str);
	server.serve();
}
 
开发者ID:claritylab,项目名称:lucida,代码行数:24,代码来源:QADaemon.java

示例8: start

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
@PostConstruct
public void start() {
    logger.info("Starting thift server " + name + " on port " + port);

    try {
        transport = new TNonblockingServerSocket(port);
        server = new TThreadedSelectorServer(
                new TThreadedSelectorServer.Args(transport)
            .processor(processor)
            .workerThreads(threads)
            .selectorThreads((threads / 16) + 1)
            .protocolFactory(protocolFactory)
            .transportFactory(new TFramedTransport.Factory()));
        thread.start();

    } catch (TTransportException e) {
        throw new RuntimeException("Unable to start thrift server " + e, e);
    }
}
 
开发者ID:chadmv,项目名称:plow,代码行数:20,代码来源:ThriftServer.java

示例9: threadedSelectorServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
public static AsyncEchoTestServer<TThreadedSelectorServer> threadedSelectorServer(
        final TestEnvironment environment) throws TTransportException {
    TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
            new TNonblockingServerSocket(environment.getPort())).processor(getAsyncProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new AsyncEchoTestServer<TThreadedSelectorServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:19,代码来源:AsyncEchoTestServer.java

示例10: threadedSelectorServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
public static SyncEchoTestServer<TThreadedSelectorServer> threadedSelectorServer(
        final TestEnvironment environment) throws TTransportException {
    TThreadedSelectorServer server = new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
            new TNonblockingServerSocket(environment.getPort())).processor(getProcessor())
            .inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<TThreadedSelectorServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.ClientForNonblockingServer(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:19,代码来源:SyncEchoTestServer.java

示例11: setup

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
private void setup() throws IOException, TTransportException {
  if (mZookeeperMode) {
    mEditLogProcessor.stop();
  }
  mMasterInfo.init();

  mWebServer =
      new UIWebServer("Tachyon Master Server", new InetSocketAddress(
          mMasterAddress.getHostName(), mWebPort), mMasterInfo);

  mMasterServiceHandler = new MasterServiceHandler(mMasterInfo);
  MasterService.Processor<MasterServiceHandler> masterServiceProcessor =
      new MasterService.Processor<MasterServiceHandler>(mMasterServiceHandler);

  mServerTNonblockingServerSocket = new TNonblockingServerSocket(mMasterAddress);
  mMasterServiceServer =
      new TThreadedSelectorServer(new TThreadedSelectorServer.Args(
          mServerTNonblockingServerSocket).processor(masterServiceProcessor)
          .selectorThreads(mSelectorThreads).acceptQueueSizePerThread(mAcceptQueueSizePerThread)
          .workerThreads(mWorkerThreads));

  mIsStarted = true;
}
 
开发者ID:mtunique,项目名称:tachyon-rdma,代码行数:24,代码来源:TachyonMaster.java

示例12: Bmv2ControlPlaneThriftServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
/**
 * Creates a new server.
 *
 * @param port            a listening port
 * @param processor       a processor
 * @param executorService an executor service
 * @throws TTransportException
 */
public Bmv2ControlPlaneThriftServer(int port, TProcessor processor, ExecutorService executorService)
        throws TTransportException {
    super(new TThreadedSelectorServer.Args(new TNonblockingServerSocket(port))
                  .workerThreads(MAX_WORKER_THREADS)
                  .selectorThreads(MAX_SELECTOR_THREADS)
                  .acceptQueueSizePerThread(ACCEPT_QUEUE_LEN)
                  .executorService(executorService)
                  .processor(processor));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:Bmv2ControlPlaneThriftServer.java

示例13: joinThreads

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
@Override
protected void joinThreads() throws InterruptedException {
    // Wait until the io threads exit.
    acceptThread.join();
    for (TThreadedSelectorServer.SelectorThread thread : selectorThreads) {
        thread.join();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:9,代码来源:Bmv2ControlPlaneThriftServer.java

示例14: init

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的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);
    }
}
 
开发者ID:sofn,项目名称:trpc,代码行数:37,代码来源:ThriftServerPublisher.java

示例15: initServer

import org.apache.thrift.server.TThreadedSelectorServer; //导入依赖的package包/类
/**
 * 初始化Thrift服务
 * 
 * @param serverTransport
 *            服务传输类型
 */
@Override
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getThriftServerConfiguration();
	// 使用多线程半同步半异步方式
	TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args((TNonblockingServerSocket) serverTransport)
			.transportFactory(configuration.getTransportFactory())
			.protocolFactory(configuration.getProtocolFactory());
	if (configuration.getExecutorService() != null)
		args.executorService(configuration.getExecutorService());
	server = new TThreadedSelectorServer(
			configuration.getServerArgsAspect().TThreadedSelectorServerArgsAspect(args).processor(getProcessor()));
	if (configuration.getServerEventHandler() != null)
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
开发者ID:venwyhk,项目名称:ikasoa,代码行数:21,代码来源:NonblockingThriftServerImpl.java


注:本文中的org.apache.thrift.server.TThreadedSelectorServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。