本文整理汇总了Java中org.apache.thrift.protocol.TBinaryProtocol.Factory方法的典型用法代码示例。如果您正苦于以下问题:Java TBinaryProtocol.Factory方法的具体用法?Java TBinaryProtocol.Factory怎么用?Java TBinaryProtocol.Factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.protocol.TBinaryProtocol
的用法示例。
在下文中一共展示了TBinaryProtocol.Factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
});
}
示例2: 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();
}
}
示例3: startRPCServer
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
public static void startRPCServer(leafServer leafserver , String ip , int port) throws Exception
{
ServerSocket serverSocket = new ServerSocket(port,10000, InetAddress.getByName(ip));
TServerSocket serverTransport = new TServerSocket(serverSocket);
//设置协议工厂为TBinaryProtocolFactory
Factory proFactory = new TBinaryProtocol.Factory();
//关联处理器leafrpc的实现
TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver));
TThreadPoolServer.Args args2 = new TThreadPoolServer.Args(serverTransport);
args2.processor(processor);
args2.protocolFactory(proFactory);
TServer server = new TThreadPoolServer(args2);
LOG.info("leaf RPCServer(type:TThreadPoolServer) start at ip:port : "+ ip +":" + port );
server.serve();
}
示例4: start
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的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();
}
}
示例5: init
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
protected void init() throws Exception {
TServerTransport serverTransport = new TServerSocket( PORT );
TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
server = new TThreadPoolServer(
new TThreadPoolServer.Args( serverTransport )
.inputProtocolFactory( bFactory )
.outputProtocolFactory( bFactory )
.inputTransportFactory( getTransportFactory() )
.outputTransportFactory( getTransportFactory() )
.processor( getProcessor() ) );
Thread startTread = new Thread() {
@Override
public void run() {
server.serve();
}
};
startTread.setName( "thrift-server" );
startTread.start();
while( !server.isServing() ) {
Thread.sleep( 100 );
}
protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
.getExtension( ThriftProtocol.NAME );
invoker = protocol.refer( getInterface(), getUrl() );
}
示例6: testProcessor
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
throws Exception
{
try (TServerSocket serverTransport = new TServerSocket(0)) {
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
TTransportFactory transportFactory = new TFramedTransport.Factory();
TServer server = new TSimpleServer(new Args(serverTransport)
.protocolFactory(protocolFactory)
.transportFactory(transportFactory)
.processor(processor));
Thread serverThread = new Thread(server::serve);
try {
serverThread.start();
int localPort = serverTransport.getServerSocket().getLocalPort();
HostAndPort address = HostAndPort.fromParts("localhost", localPort);
int sum = 0;
for (ToIntFunction<HostAndPort> client : clients) {
sum += client.applyAsInt(address);
}
return sum;
}
finally {
server.stop();
serverThread.interrupt();
}
}
}
示例7: getTProtocolFactory
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
private static TProtocolFactory getTProtocolFactory(boolean isCompact) {
if (isCompact) {
log.debug("Using compact protocol");
return new TCompactProtocol.Factory();
} else {
log.debug("Using binary protocol");
return new TBinaryProtocol.Factory();
}
}
示例8: startExtension
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的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);
}
}
示例9: init
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
public void init() {
try {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
for (ServiceArgs service : serverArgs.getServices()) {
String className = service.getService();
if (className.endsWith("$Processor")) {
className = className.substring(0, className.indexOf("$Processor"));
}
processor.registerProcessor(className, service.getProcessor());
}
if (serverArgs.getNettyServerArgs() != null) {
this.server = new TNettyServer(serverArgs.getNettyServerArgs().ip(serverArgs.getHost()).port(serverArgs.getPort()));
} else {
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress(serverArgs.getHost(), serverArgs.getPort()));
//异步IO,需要使用TFramedTransport,它将分块缓存读取。
TTransportFactory transportFactory = new TFramedTransport.Factory();
//使用高密度二进制协议
TProtocolFactory proFactory = new TBinaryProtocol.Factory();
// Use this for a multithreaded key
this.server = new TThreadedSelectorServer(new
TThreadedSelectorServer.Args(serverTransport)
.transportFactory(transportFactory)
.protocolFactory(proFactory)
.processor(processor)
);
}
log.info("Starting the Thrift key...");
this.server.setServerEventHandler(new TrpcRegistryEventHandler(serverArgs));
this.server.serve();
if (this.serverArgs.getNettyServerArgs() != null) {
((TNettyServer) this.server).waitForClose();
}
} catch (Exception e) {
log.error("publish thrift key error", e);
}
}
示例10: getProtocolFactory
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
public TProtocolFactory getProtocolFactory() {
switch (this) {
case COMPACT:
return new TCompactProtocol.Factory();
case BINARY:
return new TBinaryProtocol.Factory();
default:
return new TBinaryProtocol.Factory();
}
}
示例11: stream
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
/**
* Given a message, produce an {@link InputStream} for it so that it can be written to the wire.
* Where possible implementations should produce streams that are {@link KnownLength} to improve
* transport efficiency.
*
* @param value to serialize.
* @return serialized value as stream of bytes.
*/
@Override
public InputStream stream(T value) {
TSerializer ttSerializer = new TSerializer(new TBinaryProtocol.Factory());
try {
byte[] data = ttSerializer.serialize(value);
return new ByteArrayInputStream(data);
} catch (TException e) {
e.printStackTrace();
}
return null;
}
示例12: getProtocolFactory
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
private TProtocolFactory getProtocolFactory() {
switch (protocol) {
case BINARY: return new TBinaryProtocol.Factory();
case COMPACT: return new TCompactProtocol.Factory();
case JSON: return new TJSONProtocol.Factory();
default:
throw new AssertionError("Invalid protocol value: " + protocol);
}
}
示例13: makeObject
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
@Override
public T makeObject(InetSocketAddress socket) throws Exception {
TNonblockingTransport nbTr = new TNonblockingSocket(
socket.getAddress().getHostAddress(), socket.getPort());
TProtocolFactory factory = new TBinaryProtocol.Factory();
T client = maker.create(nbTr, clientManager, factory);
transports.put(client, nbTr);
return client;
}
示例14: startServer
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
public static void startServer() {
// Create the handler
//ThriftTestService.Iface serviceInterface =
// MyService.Iface serviceInterface = new MyServiceHandler();
// Create the processor
//TProcessor processor = new MyService.Processor<>(serviceInterface);
// Create the processor
//TProcessor processor = new ThriftTestService.Processor<>(new InMemoryScribe());
InMemoryScribe inMemoryScribe = new InMemoryScribeImpl();
TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
ThriftCodecManager thriftCodecManager = new ThriftCodecManager();
List list = new ArrayList<>();
list.add(inMemoryScribe);
ThriftServiceProcessor processor = new ThriftServiceProcessor(thriftCodecManager, Arrays.<ThriftEventHandler>asList(), inMemoryScribe);
// Build the server definition
ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
.build();
// Create the server transport
final NettyServerTransport server = new NettyServerTransport(serverDef );
// Create netty boss and executor thread pools
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();
// Start the server
//server.start(bossExecutor, workerExecutor);
server.start();
// Arrange to stop the server at shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
}
示例15: tProtocolFactory
import org.apache.thrift.protocol.TBinaryProtocol; //导入方法依赖的package包/类
@Bean
TProtocolFactory tProtocolFactory() {
return new TBinaryProtocol.Factory();
}