当前位置: 首页>>代码示例>>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;未经允许,请勿转载。