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


Java TBinaryProtocol類代碼示例

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


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

示例1: poolServer

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

示例2: logThrift

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
    try {
        TSocket socket = new TSocket(address.getHost(), address.getPort());
        socket.open();
        try {
            TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
            assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
        }
        finally {
            socket.close();
        }
    }
    catch (TException e) {
        throw new RuntimeException(e);
    }
    return 1;
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:19,代碼來源:TestApacheThriftMethodInvoker.java

示例3: createModelBridge

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
/**
 * Creates a Model and a Thrift Bridge to this model.
 */
protected static EBMI createModelBridge(String host, String pythonExecutable, File opendaPythonPath, File modelPythonPath,
		String modelPythonModuleName, String modelPythonClassName, File modelRunDir) throws IOException {
	// start local server.
	int port = getFreePort();
	
	if (host == null) {
		//localhost
		host = "127.0.0.1";
	}
	
	Process process = startModelProcess(host, port, pythonExecutable, opendaPythonPath, modelPythonPath,
			modelPythonModuleName, modelPythonClassName, modelRunDir);

	// connect to server.
	TTransport transport = connectToCode(host, port, process);

	// create client.
	TProtocol protocol = new TBinaryProtocol(transport);
	BMIService.Client client = new BMIService.Client(protocol);

	return new ThriftBmiBridge(client, process, transport);
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:26,代碼來源:BmiModelFactory.java

示例4: ThriftTestingSource

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

示例5: getProtocolFactory

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
private TProtocolFactory getProtocolFactory() {
  if (protocol.equals(BINARY_PROTOCOL)) {
    logger.info("Using TBinaryProtocol");
    return new TBinaryProtocol.Factory();
  } else {
    logger.info("Using TCompactProtocol");
    return new TCompactProtocol.Factory();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:10,代碼來源:ThriftSource.java

示例6: run

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

示例7: testScribeMessage

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
@Test
public void testScribeMessage() throws Exception {
  TTransport transport = new TFramedTransport(new TSocket("localhost", port));

  TProtocol protocol = new TBinaryProtocol(transport);
  Scribe.Client client = new Scribe.Client(protocol);
  transport.open();
  LogEntry logEntry = new LogEntry("INFO", "Sending info msg to scribe source");
  List<LogEntry> logEntries = new ArrayList<LogEntry>(1);
  logEntries.add(logEntry);
  client.Log(logEntries);

  // try to get it from Channels
  Transaction tx = memoryChannel.getTransaction();
  tx.begin();
  Event e = memoryChannel.take();
  Assert.assertNotNull(e);
  Assert.assertEquals("Sending info msg to scribe source", new String(e.getBody()));
  tx.commit();
  tx.close();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestScribeSource.java

示例8: startSchedulerThriftService

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

示例9: startServer

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

示例10: load

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
@Override
public Pair<TTransport, Bmv2DeviceThriftClient> load(DeviceId deviceId)
        throws TTransportException {
    log.debug("Instantiating new client... > deviceId={}", deviceId);
    // Make the expensive call
    Bmv2Device device = Bmv2Device.of(deviceId);
    TTransport transport = new TSocket(device.thriftServerHost(), device.thriftServerPort());
    TProtocol protocol = new TBinaryProtocol(transport);
    // Our BMv2 device implements multiple Thrift services, create a client for each one on the same transport.
    Standard.Client standardClient = new Standard.Client(
            new TMultiplexedProtocol(protocol, "standard"));
    SimpleSwitch.Client simpleSwitch = new SimpleSwitch.Client(
            new TMultiplexedProtocol(protocol, "simple_switch"));
    // Wrap clients so to automatically have synchronization and resiliency to connectivity errors
    Standard.Iface safeStandardClient = SafeThriftClient.wrap(standardClient,
                                                              Standard.Iface.class,
                                                              options);
    SimpleSwitch.Iface safeSimpleSwitchClient = SafeThriftClient.wrap(simpleSwitch,
                                                                      SimpleSwitch.Iface.class,
                                                                      options);
    Bmv2DeviceThriftClient client = new Bmv2DeviceThriftClient(deviceId,
                                                               transport,
                                                               safeStandardClient,
                                                               safeSimpleSwitchClient);
    return Pair.of(transport, client);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:Bmv2ControllerImpl.java

示例11: hshaServer

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

示例12: main

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

示例13: main

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

示例14: startClient

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
public static void startClient(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TSocket(ip,port,timeout);
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	int i = 0;
	while(i < 2000000)
	{
		 client.getID("");
		 ++i;
	}

	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:17,代碼來源:rpcClient.java

示例15: startClient2

import org.apache.thrift.protocol.TBinaryProtocol; //導入依賴的package包/類
public static void startClient2(String ip ,int port ,int timeout) throws Exception
{
	TTransport transport = new TFramedTransport(new TSocket(ip,port,timeout));
	TProtocol protocol = new TBinaryProtocol(transport);
	leafrpc.Client client = new leafrpc.Client(protocol);
	transport.open();

	for(int i = 0; i< 1000000; i++)
	{
		client.getID("");
		if (i % 100000 == 0)
		{
			System.out.println(Thread.currentThread().getName() + " " + client.getID(""));
		}
		//ai.incrementAndGet();
	}
	transport.close();
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:19,代碼來源:rpcClient.java


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