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


Java TNonblockingServerSocket類代碼示例

本文整理匯總了Java中org.apache.thrift.transport.TNonblockingServerSocket的典型用法代碼示例。如果您正苦於以下問題:Java TNonblockingServerSocket類的具體用法?Java TNonblockingServerSocket怎麽用?Java TNonblockingServerSocket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TNonblockingServerSocket類屬於org.apache.thrift.transport包,在下文中一共展示了TNonblockingServerSocket類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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: nonBlockMode

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
private void nonBlockMode() {
        AskerHandler handler = new AskerHandler();
        Asker.Processor processor = new Asker.Processor(handler);
        try {
            TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
            THsHaServer.Args arg = new THsHaServer.Args(transport);
            arg.protocolFactory(new TCompactProtocol.Factory());
//            arg.transportFactory(new TFramedTransport.Factory());
//            arg.processorFactory(new TProcessorFactory(processor));
            arg.processor(processor);
            server = new THsHaServer(arg);
            start.countDown();

            System.out.println("Starting the nonBlock server...");
            server.serve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
開發者ID:altiplanogao,項目名稱:rpc-comparison,代碼行數:20,代碼來源:AskerServer.java

示例3: ThriftTestingSource

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception {
  TNonblockingServerTransport serverTransport =
      new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port));
  ThriftSourceProtocol.Iface handler = getHandler(handlerName);

  TProtocolFactory transportProtocolFactory = null;
  if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) {
    transportProtocolFactory = new TBinaryProtocol.Factory();
  } else {
    transportProtocolFactory = new TCompactProtocol.Factory();
  }
  server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(
      new ThriftSourceProtocol.Processor(handler)).protocolFactory(
          transportProtocolFactory));
  Executors.newSingleThreadExecutor().submit(new Runnable() {
    @Override
    public void run() {
      server.serve();
    }
  });
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:ThriftTestingSource.java

示例4: run

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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);
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:ScribeSource.java

示例5: hshaServer

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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.transport.TNonblockingServerSocket; //導入依賴的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.transport.TNonblockingServerSocket; //導入依賴的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: startRPCServer2

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
public static void startRPCServer2(leafServer leafserver , String ip , int port) throws Exception
{
	//關聯處理器leafrpc的實現
	TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver));
	//傳輸通道,非阻塞模式
	InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(ip),port);
	TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(address,10000);
	//多線程半同步半異步
	TThreadedSelectorServer.Args tArgs = new TThreadedSelectorServer.Args(serverTransport);
	tArgs.processor(processor);
	//二進製協議
	tArgs.protocolFactory(new TBinaryProtocol.Factory());
	//多線程半同步半異步的服務模型
	TServer server = new TThreadedSelectorServer(tArgs);
	LOG.info("leaf RPCServer(type:TThreadedSelectorServer) start at ip:port : "+ ip +":" + port );
	server.serve();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:18,代碼來源:rpcServer.java

示例9: start

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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: hshaServer

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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

示例11: createThrift

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的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;
    }
}
 
開發者ID:songbin,項目名稱:frc,代碼行數:22,代碼來源:Application.java

示例12: setUp

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    rc = copyResourceTo("/pvdrc", temp.getRoot());
    copyResourceTo("/test.thrift", temp.getRoot());

    impl = Mockito.mock(MyService.Iface.class);

    TNonblockingServerSocket transport = new TNonblockingServerSocket(0);
    server = new TNonblockingServer(new TNonblockingServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory())
                                                                          .processor(new MyService.Processor<>(impl)));

    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    Thread.sleep(1);
    port = transport.getPort();

    exitCode = 0;
    rpc = new RPC(console.tty()) {
        @Override
        protected void exit(int i) {
            exitCode = i;
        }
    };
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:25,代碼來源:RPCThriftNonblockingSocketTest.java

示例13: setUpServer

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
@BeforeClass
public static void setUpServer() throws Exception {
    setDefaultPollDelay(10, TimeUnit.MILLISECONDS);

    serializer = new TBinaryProtocolSerializer();
    factory = new TBinaryProtocol.Factory();
    port = findFreePort();
    impl = Mockito.mock(Iface.class);

    TNonblockingServerTransport transport = new TNonblockingServerSocket(port);
    server = new TNonblockingServer(
            new TNonblockingServer.Args(transport)
                    .protocolFactory(factory)
                    .processor(new Processor<>(impl)));

    executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    address = new InetSocketAddress("localhost", port);
}
 
開發者ID:morimekta,項目名稱:providence,代碼行數:20,代碼來源:NonblockingSocketClientHandlerTest.java

示例14: initHandlerServer

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
private THsHaServer initHandlerServer(Map conf, final Drpc service) throws Exception {
    int port = JStormUtils.parseInt(conf.get(Config.DRPC_PORT));
    int workerThreadNum = JStormUtils.parseInt(conf.get(Config.DRPC_WORKER_THREADS));
    int queueSize = JStormUtils.parseInt(conf.get(Config.DRPC_QUEUE_SIZE));

    TNonblockingServerSocket socket = new TNonblockingServerSocket(port);
    THsHaServer.Args targs = new THsHaServer.Args(socket);
    targs.workerThreads(64);
    targs.protocolFactory(new TBinaryProtocol.Factory());
    targs.processor(new DistributedRPC.Processor<DistributedRPC.Iface>(service));

    ThreadPoolExecutor executor = new ThreadPoolExecutor(workerThreadNum, workerThreadNum, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(queueSize));
    targs.executorService(executor);

    THsHaServer handlerServer = new THsHaServer(targs);
    LOG.info("Successfully init Handler Server " + port);

    return handlerServer;
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:20,代碼來源:Drpc.java

示例15: initThrift

import org.apache.thrift.transport.TNonblockingServerSocket; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private void initThrift(Map conf) throws TTransportException {
    Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT));
    TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port);

    Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE));

    THsHaServer.Args args = new THsHaServer.Args(socket);
    args.workerThreads(ServiceHandler.THREAD_NUM);
    args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1));

    args.processor(new Nimbus.Processor<Iface>(serviceHandler));
    args.maxReadBufferBytes = maxReadBufSize;

    thriftServer = new THsHaServer(args);

    LOG.info("Successfully started nimbus: started Thrift server...");
    thriftServer.serve();
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:20,代碼來源:NimbusServer.java


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