本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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();
}
});
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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!");
}
示例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();
}
}
示例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);
}
示例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();
}
}
示例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");
}
}
});
}
}
示例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");
}
}
});
}
}
示例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();
}
示例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();
}