本文整理汇总了Java中org.apache.thrift.protocol.TProtocolFactory类的典型用法代码示例。如果您正苦于以下问题:Java TProtocolFactory类的具体用法?Java TProtocolFactory怎么用?Java TProtocolFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TProtocolFactory类属于org.apache.thrift.protocol包,在下文中一共展示了TProtocolFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClientConstructor
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};
Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
if (clientClass == null) {
throw new ThriftRuntimeException("the client class is null");
}
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
if (constructor == null) {
throw new ThriftRuntimeException("the clientClass constructor is null");
}
return constructor;
}
示例2: ApacheThriftMethodInvoker
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public ApacheThriftMethodInvoker(
ListeningExecutorService executorService,
ListeningScheduledExecutorService delayService,
TTransportFactory transportFactory,
TProtocolFactory protocolFactory,
Duration connectTimeout,
Duration requestTimeout,
Optional<HostAndPort> socksProxy,
Optional<SSLContext> sslContext)
{
this.executorService = requireNonNull(executorService, "executorService is null");
this.delayService = requireNonNull(delayService, "delayService is null");
this.transportFactory = requireNonNull(transportFactory, "transportFactory is null");
this.protocolFactory = requireNonNull(protocolFactory, "protocolFactory is null");
this.connectTimeoutMillis = Ints.saturatedCast(requireNonNull(connectTimeout, "connectTimeout is null").toMillis());
this.requestTimeoutMillis = Ints.saturatedCast(requireNonNull(requestTimeout, "requestTimeout is null").toMillis());
this.socksProxy = requireNonNull(socksProxy, "socksProxy is null");
this.sslContext = requireNonNull(sslContext, "sslContext is null");
}
示例3: ThriftTestingSource
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的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();
}
});
}
示例4: getProtocolFactory
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的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();
}
}
示例5: getTThreadPoolServer
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory,
TProcessor processor,
TTransportFactory transportFactory,
int workerThreads,
InetSocketAddress inetSocketAddress,
int backlog,
int clientTimeout)
throws TTransportException {
TServerTransport serverTransport = new TServerSocket(
new TServerSocket.ServerSocketTransportArgs().
bindAddr(inetSocketAddress).backlog(backlog).
clientTimeout(clientTimeout));
log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
if (workerThreads > 0) {
serverArgs.maxWorkerThreads(workerThreads);
}
return new TThreadPoolServer(serverArgs);
}
示例6: getClient
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <X extends TAsyncClient> X getClient(final Class<X> clazz) {
return (X) super.clients.computeIfAbsent(ClassNameUtils.getOuterClassName(clazz), (className) -> {
TProtocolFactory protocolFactory = (TProtocolFactory) tTransport -> {
TProtocol protocol = new TBinaryProtocol(tTransport);
return new TMultiplexedProtocol(protocol, className);
};
try {
return clazz.getConstructor(TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class)
.newInstance(protocolFactory, this.clientManager, this.transport);
} catch (Throwable e) {
if (e instanceof UnresolvedAddressException) {
this.isOpen = false;
}
return null;
}
});
}
示例7: start
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的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();
}
}
示例8: messageReceived
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
@Override
protected void messageReceived(ChannelHandlerContext ctx, ThriftMessage message) throws Exception {
ByteBuf buffer = message.getContent();
logger.debug("msg.content:: {}", buffer);
try {
TNettyTransport transport = new TNettyTransport(ctx.channel(), buffer);
TProtocolFactory protocolFactory = message.getProtocolFactory();
TProtocol protocol = protocolFactory.getProtocol(transport);
serverDef.nettyProcessor.process(ctx, protocol, protocol,
new DefaultWriterListener(message, transport, ctx, serverDef));
} catch (Throwable ex) {
int refCount = buffer.refCnt();
if (refCount > 0) {
buffer.release(refCount);
}
throw ex;
}
}
示例9: run
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public void run() {
ThriftTestHandler handler = new ThriftTestHandler(System.out);
ThriftTest.Processor<ThriftTestHandler> processor = new ThriftTest.Processor<>(handler);
TProtocolFactory factory = getProtocolFactory();
serverTransport = getServerTransport();
server = startServer(processor, factory);
final CountDownLatch latch = new CountDownLatch(1);
serverThread = new Thread(() -> {
latch.countDown();
server.serve();
});
serverThread.start();
try {
latch.await(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignored) {
// continue
}
}
示例10: getClientConstructor
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
public static Constructor<?> getClientConstructor(Class<?> svcInterface) {
String client = svcInterface.getName().indexOf("Async") > 0 ? ASYNC_CLIENT_NAME : CLIENT_NAME;
Class<?>[] args = svcInterface.getName().indexOf("Async") > 0 ? new Class[]{TProtocolFactory.class, TAsyncClientManager.class, TNonblockingTransport.class} : new Class[]{TProtocol.class};
Class<?> clientClass = getThriftServiceInnerClassOrNull(svcInterface.getEnclosingClass(), client, false);
if (clientClass == null) {
throw new ThriftRuntimeException("the client class is null");
}
Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientClass, args);
if (constructor == null) {
throw new ThriftRuntimeException("the clientClass constructor is null");
}
return constructor;
}
示例11: get
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
/**
* Returns the {@link TProtocolFactory} for the specified {@link SerializationFormat}.
*
* @throws IllegalArgumentException if the specified {@link SerializationFormat} is not for Thrift
*/
public static TProtocolFactory get(SerializationFormat serializationFormat) {
requireNonNull(serializationFormat, "serializationFormat");
if (serializationFormat == ThriftSerializationFormats.BINARY) {
return BINARY;
}
if (serializationFormat == ThriftSerializationFormats.COMPACT) {
return COMPACT;
}
if (serializationFormat == ThriftSerializationFormats.JSON) {
return JSON;
}
if (serializationFormat == ThriftSerializationFormats.TEXT) {
return TEXT;
}
throw new IllegalArgumentException("non-Thrift serializationFormat: " + serializationFormat);
}
示例12: toSerializationFormat
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
/**
* Returns the {@link SerializationFormat} for the specified {@link TProtocolFactory}.
*
* @throws IllegalArgumentException if the specified {@link TProtocolFactory} is not known by this class
*/
public static SerializationFormat toSerializationFormat(TProtocolFactory protoFactory) {
requireNonNull(protoFactory, "protoFactory");
if (protoFactory instanceof TBinaryProtocol.Factory) {
return ThriftSerializationFormats.BINARY;
} else if (protoFactory instanceof TCompactProtocol.Factory) {
return ThriftSerializationFormats.COMPACT;
} else if (protoFactory instanceof TJSONProtocol.Factory) {
return ThriftSerializationFormats.JSON;
} else if (protoFactory instanceof TTextProtocol.Factory) {
return ThriftSerializationFormats.TEXT;
} else {
throw new IllegalArgumentException(
"unsupported TProtocolFactory: " + protoFactory.getClass().getName());
}
}
示例13: getTHsHaServer
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTHsHaServer(TProtocolFactory protocolFactory,
TProcessor processor, TTransportFactory transportFactory,
int workerThreads, int maxCallQueueSize,
InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
throws TTransportException {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
log.info("starting HBase HsHA Thrift server on " + inetSocketAddress.toString());
THsHaServer.Args serverArgs = new THsHaServer.Args(serverTransport);
if (workerThreads > 0) {
// Could support the min & max threads, avoiding to preserve existing functionality.
serverArgs.minWorkerThreads(workerThreads).maxWorkerThreads(workerThreads);
}
ExecutorService executorService = createExecutor(
workerThreads, maxCallQueueSize, metrics);
serverArgs.executorService(executorService);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
return new THsHaServer(serverArgs);
}
示例14: getTThreadedSelectorServer
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private static TServer getTThreadedSelectorServer(TProtocolFactory protocolFactory,
TProcessor processor, TTransportFactory transportFactory,
int workerThreads, int selectorThreads, int maxCallQueueSize,
InetSocketAddress inetSocketAddress, ThriftMetrics metrics)
throws TTransportException {
TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(inetSocketAddress);
log.info("starting HBase ThreadedSelector Thrift server on " + inetSocketAddress.toString());
TThreadedSelectorServer.Args serverArgs = new TThreadedSelectorServer.Args(serverTransport);
if (workerThreads > 0) {
serverArgs.workerThreads(workerThreads);
}
if (selectorThreads > 0) {
serverArgs.selectorThreads(selectorThreads);
}
ExecutorService executorService = createExecutor(
workerThreads, maxCallQueueSize, metrics);
serverArgs.executorService(executorService);
serverArgs.processor(processor);
serverArgs.transportFactory(transportFactory);
serverArgs.protocolFactory(protocolFactory);
return new TThreadedSelectorServer(serverArgs);
}
示例15: getServer
import org.apache.thrift.protocol.TProtocolFactory; //导入依赖的package包/类
private TServer getServer(int workerThreads, int selectorThreads, int maxCallQueueSize,
int readTimeout, int backlog, boolean nonblocking, boolean hsha, boolean selector,
ThriftMetrics metrics, TProtocolFactory protocolFactory, TProcessor processor,
TTransportFactory transportFactory, InetSocketAddress inetSocketAddress)
throws TTransportException {
TServer server;
if (nonblocking) {
server = getTNonBlockingServer(protocolFactory, processor, transportFactory,
inetSocketAddress);
} else if (hsha) {
server = getTHsHaServer(protocolFactory, processor, transportFactory, workerThreads,
maxCallQueueSize, inetSocketAddress, metrics);
} else if (selector) {
server = getTThreadedSelectorServer(protocolFactory, processor, transportFactory,
workerThreads, selectorThreads, maxCallQueueSize, inetSocketAddress, metrics);
} else {
server = getTThreadPoolServer(protocolFactory, processor, transportFactory, workerThreads,
inetSocketAddress, backlog, readTimeout, metrics);
}
return server;
}