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


Java TServer.serve方法代碼示例

本文整理匯總了Java中org.apache.thrift.server.TServer.serve方法的典型用法代碼示例。如果您正苦於以下問題:Java TServer.serve方法的具體用法?Java TServer.serve怎麽用?Java TServer.serve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.thrift.server.TServer的用法示例。


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: main

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public static void main(String[] args) {
	try {
		handler = new CalculatorHandler();
		processor = new Calculator.Processor(handler);

		try {
			TServerTransport serverTransport = new TServerSocket(9090);
			TServer server = new TThreadPoolServer(new TThreadPoolServer.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,代碼來源:StandardBIOServer.java

示例7: startHshaServer

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
@VisibleForTesting
public static TServer startHshaServer(TProcessor processor, int portNumber) throws Exception {

    final TNonblockingServerSocket socket = new TNonblockingServerSocket(portNumber);
    final THsHaServer.Args serverArgs = new THsHaServer.Args(socket);
    serverArgs.processor(processor);
    serverArgs.inputProtocolFactory(new TCompactProtocol.Factory());
    serverArgs.outputProtocolFactory(new TCompactProtocol.Factory());
    final TServer server = new THsHaServer(serverArgs);
    final Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    });
    t.start();
    return server;
}
 
開發者ID:ezbake,項目名稱:ezbake-common-java,代碼行數:19,代碼來源:ThriftUtils.java

示例8: main

import org.apache.thrift.server.TServer; //導入方法依賴的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

示例9: main

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public static void main(String[] args)
        throws TTransportException, IOException, InterruptedException {

    FloorBroker floor = new FloorBroker();
    (new Thread(floor)).start();

    TProcessor proc = new TradeReporting.TradeHistory.AsyncProcessor(
        new AsyncTradeHistoryHandler(floor.getQ()));
    TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
    TServer server = 
        new THsHaServer(new THsHaServer.Args(trans_svr)
            .processor(proc)
            .protocolFactory(new TBinaryProtocol.Factory())
            .minWorkerThreads(4)
            .maxWorkerThreads(4));
    System.out.println("[Server] listening of port 9090");
    server.serve();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:19,代碼來源:AsyncServer.java

示例10: secure

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
private void secure(Asker.Processor processor) {
    try {
   /*
   * Use TSSLTransportParameters to setup the required SSL parameters. In this example
   * we are setting the keystore and the keystore password. Other things like algorithms,
   * cipher suites, client auth etc can be set.
   */
        TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
        // The Keystore contains the private key
        params.setKeyStore(keyStore, keyPass, null, null);

  /*
   * Use any of the TSSLTransportFactory to get a server transport with the appropriate
   * SSL configuration. You can use the default settings if properties are set in the command line.
   * Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
   *
   * Note: You need not explicitly call open(). The underlying server socket is bound on return
   * from the factory class.
   */
        TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(port, 0, null, params);
        TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

        // Use this for a multi threaded server
        // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

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

示例11: startExtension

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
/**
 * Start extension by communicating with osquery core and starting thrift
 * server
 * 
 * @param name
 *            name of extension
 * @param version
 *            version of extension
 * @param sdkVersion
 *            version of the osquery SDK used to build this extension
 * @param minSdkVersion
 *            minimum version of the osquery SDK that you can use
 * @throws IOException
 * @throws ExtensionException
 */
public void startExtension(String name, String version, String sdkVersion, String minSdkVersion)
		throws IOException, ExtensionException {
	ExtensionManager.Client client = new ClientManager(EXTENSION_SOCKET).getClient();
	InternalExtensionInfo info = new InternalExtensionInfo(name, version, sdkVersion, minSdkVersion);
	try {
		ExtensionStatus status = client.registerExtension(info, registry);
		if (status.getCode() == 0) {
			this.uuid = status.uuid;
			Processor<PluginManager> processor = new Processor<PluginManager>(this);
			String serverSocketPath = EXTENSION_SOCKET + "." + String.valueOf(uuid);
			File socketFile = new File(serverSocketPath);
			if (socketFile.exists()) {
				socketFile.delete();
			}
			AFUNIXServerSocket socket = AFUNIXServerSocket.bindOn(new AFUNIXSocketAddress(socketFile));
			socketFile.setExecutable(true, false);
			socketFile.setWritable(true, false);
			socketFile.setReadable(true, false);
			TServerSocket transport = new TServerSocket(socket);
			TTransportFactory transportFactory = new TTransportFactory();
			TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
			TServer server = new TSimpleServer(new Args(transport).processor(processor)
					.transportFactory(transportFactory).protocolFactory(protocolFactory));

			// Run it
			System.out.println("Starting the server...");
			server.serve();
		} else {
			throw new ExtensionException(1, status.getMessage(), uuid);
		}
	} catch (TException e) {
		throw new ExtensionException(1, "Could not connect to socket", uuid);
	}
}
 
開發者ID:melastmohican,項目名稱:osquery-java,代碼行數:50,代碼來源:PluginManager.java

示例12: runServer

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public void runServer() throws TException{
    TServerSocket serverTransport = new TServerSocket(LOCAL_PORT);
    TProcessor    processor = new NotificationService.Processor<NotificationService.Iface>(new NotificationServiceImpl());
    TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
    System.out.println("Start server on port "+ LOCAL_PORT + "......");
    server.serve();
}
 
開發者ID:CassiaNetworks,項目名稱:CassiaHubSDKSamples,代碼行數:8,代碼來源:UserApp.java

示例13: startServer

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
/**
 * 啟動thrift server,如果存在server容器或者多個service,則一些需要設置為daemon模式
 */
private void startServer() throws Exception {

    TServerSocket serverTransport = new TServerSocket(serverConfig.getPort());
    TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport);
    args.maxWorkerThreads = serverConfig.getMaxWorkerThreads();
    args.minWorkerThreads = serverConfig.getMinWorkerThreads();
    args.protocolFactory(new TBinaryProtocol.Factory());

    TProcessor tProcessor = getProcessorIface(getIfaceClass());
    args.processor(tProcessor);
    final TServer server = new TThreadPoolServer(args);
    server.setServerEventHandler(serverConfig.getServerEventHandler());
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            server.serve();
        }
    });
    thread.setDaemon(serverConfig.isDaemonRun());
    thread.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override public void run() {
            if (!serverConfig.isDirectInvoke()) {
                unZkRegister(providerInfo, serviceInfo);
            }
            server.stop();
        }
    }));

    LOGGER.info("----------------start thrift server--------------");
}
 
開發者ID:ketao1989,項目名稱:ourea,代碼行數:35,代碼來源:ServiceProvider.java

示例14: startThriftServer

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public static void startThriftServer(final TServer thriftServer) {
    Registry.thriftServer = thriftServer;
    Thread t = new Thread("Thrift Server") {
        public void run() {
            thriftServer.serve();
        }
    };
    t.start();
}
 
開發者ID:btnguyen2k,項目名稱:queue-server,代碼行數:10,代碼來源:Registry.java

示例15: simple

import org.apache.thrift.server.TServer; //導入方法依賴的package包/類
public static void simple(Calculator.Processor<CalculatorHandler> processor) throws Exception {
		TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(9090);
		TServer server = new TNonblockingServer(new TNonblockingServer.Args(serverTransport).processor(processor));
		
//		TServerTransport serverTransport = new TServerSocket(9090);
//		TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

		// Use this for a multithreaded server
		// TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

		System.out.println("Starting the simple server...");
		server.serve();
	}
 
開發者ID:haogrgr,項目名稱:haogrgr-projects,代碼行數:14,代碼來源:ServerMain.java


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