本文整理汇总了Java中org.apache.thrift.TProcessor类的典型用法代码示例。如果您正苦于以下问题:Java TProcessor类的具体用法?Java TProcessor怎么用?Java TProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TProcessor类属于org.apache.thrift包,在下文中一共展示了TProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testApacheServer
import org.apache.thrift.TProcessor; //导入依赖的package包/类
private static int testApacheServer(List<MethodInvocationFilter> filters)
throws Exception
{
ScribeService scribeService = new ScribeService();
TProcessor processor = new scribe.Processor<>(scribeService);
int invocationCount = 0;
for (boolean secure : ImmutableList.of(true, false)) {
for (Transport transport : Transport.values()) {
for (Protocol protocol : Protocol.values()) {
invocationCount += testApacheServer(secure, transport, protocol, processor, ImmutableList.<ToIntFunction<HostAndPort>>builder()
.addAll(legacyApacheThriftTestClients(filters, transport, protocol, secure))
.addAll(driftNettyTestClients(filters, transport, protocol, secure))
.addAll(apacheThriftTestClients(filters, transport, protocol, secure))
.build());
}
}
}
assertEquals(scribeService.getMessages(), newArrayList(concat(nCopies(invocationCount, MESSAGES))));
return invocationCount;
}
示例2: startSchedulerThriftService
import org.apache.thrift.TProcessor; //导入依赖的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!");
}
示例3: startRPCServer
import org.apache.thrift.TProcessor; //导入依赖的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: startRPCServer2
import org.apache.thrift.TProcessor; //导入依赖的package包/类
public static void startRPCServer2(leafServer leafserver , String ip , int port) throws Exception
{
//关联处理器leafrpc的实现
TProcessor processor = new leafrpc.Processor<leafrpc.Iface>(new RPCService(leafserver));
//传输通道,非阻塞模式
InetSocketAddress address = new InetSocketAddress(InetAddress.getByName(ip),port);
TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(address,10000);
//多线程半同步半异步
TThreadedSelectorServer.Args tArgs = new TThreadedSelectorServer.Args(serverTransport);
tArgs.processor(processor);
//二进制协议
tArgs.protocolFactory(new TBinaryProtocol.Factory());
//多线程半同步半异步的服务模型
TServer server = new TThreadedSelectorServer(tArgs);
LOG.info("leaf RPCServer(type:TThreadedSelectorServer) start at ip:port : "+ ip +":" + port );
server.serve();
}
示例5: ServerThread
import org.apache.thrift.TProcessor; //导入依赖的package包/类
ServerThread() throws TTransportException {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
for (String beanName : serviceMap.keySet()) {
IThriftServerService serverService = (IThriftServerService) serviceMap.getService(beanName);
String processorName = serverService.getName();
TProcessor tProcessor = serverService.getProcessor(serverService);
processor.registerProcessor(processorName, tProcessor);
logger.info("Register a processorName {} processorImpl {}", processorName, tProcessor);
}
logger.info("init default TServerTransport in addr {} port {}", applicationProperties.getAddr(), applicationProperties.getPort());
TServerTransport tServerTransport = new TServerSocket(new InetSocketAddress(applicationProperties.getAddr(),
applicationProperties.getPort()));
TThreadPoolServer.Args args = new TThreadPoolServer.Args(tServerTransport);
args.processor(processor);
args.protocolFactory(tProtocolFactory);
server = new TThreadPoolServer(args);
}
示例6: getTThreadPoolServer
import org.apache.thrift.TProcessor; //导入依赖的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);
}
示例7: getProcessor
import org.apache.thrift.TProcessor; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public TProcessor getProcessor() {
return new ThriftHiveMetastore.Processor<>(
new CatalogThriftHiveMetastore(config, hiveConverters, metacatV1, partitionV1, catalogName, registry)
);
}
示例8: ClientProcessData
import org.apache.thrift.TProcessor; //导入依赖的package包/类
protected ClientProcessData(GfxdTSocket socket, int connectionNumber,
TProcessor proc, TTransport in, TTransport out, TProtocol inp,
TProtocol outp, TServerEventHandler eventHandler) {
this.clientSocket = socket;
this.connectionNumber = connectionNumber;
this.processor = proc;
this.inputTransport = in;
this.outputTransport = out;
this.inputProtocol = inp;
this.outputProtocol = outp;
this.eventHandler = eventHandler;
if (eventHandler != null) {
this.connectionContext = eventHandler.createContext(inp, outp);
}
else {
this.connectionContext = null;
}
this.idle = true;
}
示例9: testAysncServiceImpl
import org.apache.thrift.TProcessor; //导入依赖的package包/类
@Test
public void testAysncServiceImpl() {
int serverPort = 49001;
TProcessor p = new ServiceProcessor(new TestThriftServiceImpl1());
thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(p));
Factory factory = new GeneralFactory(thriftServerConfiguration);
ThriftServer thriftServer = factory.getThriftServer(serverPort, new TestThriftServiceImpl1());
thriftServer.run();
try {
AsyncService service = factory.getAsyncService(new TNonblockingSocket(LOCAL_HOST, serverPort));
Thread.sleep(500);
TestCallback1 callback = new TestCallback1();
service.get(testString1, callback);
Thread.sleep(1000);
} catch (Exception e) {
fail();
} finally {
thriftServer.stop();
}
}
示例10: testMultiplexedThriftServerImpl
import org.apache.thrift.TProcessor; //导入依赖的package包/类
@Test
public void testMultiplexedThriftServerImpl() {
int serverPort = 39101;
Map<String, TProcessor> processorMap = new HashMap<>();
processorMap.put("testServer", new ThriftSimpleService.Processor<Iface>(new ThriftSimpleServiceImpl()));
MultiplexedProcessor processor = new MultiplexedProcessor(processorMap);
ThriftServer defaultThriftServer = new DefaultThriftServerImpl(serverName, serverPort, configuration,
processor);
assertEquals(defaultThriftServer.getServerName(), serverName);
assertEquals(defaultThriftServer.getServerPort(), serverPort);
assertEquals(defaultThriftServer.getThriftServerConfiguration(), configuration);
defaultThriftServer.run();
try (ThriftClient thriftClient = factory.getThriftClient(LOCAL_HOST, serverPort);
TTransport transport = thriftClient.getTransport()) {
Thread.sleep(500);
transport.open();
ThriftSimpleService.Client client = new ThriftSimpleService.Client(
thriftClient.getProtocol(transport, "testServer"));
assertEquals(testString, client.get(testString));
} catch (Exception e) {
fail();
} finally {
defaultThriftServer.stop();
}
}
示例11: createProcessor
import org.apache.thrift.TProcessor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private TProcessor createProcessor(final Class<T> handlerType, Class<I> serviceType) {
// Pick the Iface inner interface and the Processor class
Class<? extends TProcessor> processorType = null;
Class<?> ifaceType = null;
for (Class<?> clz : serviceType.getDeclaredClasses()) {
if (TProcessor.class.isAssignableFrom(clz)) {
processorType = (Class<? extends TProcessor>) clz;
} else if (clz.isInterface() && "Iface".equals(clz.getSimpleName())) {
ifaceType = clz;
}
}
Preconditions.checkArgument(processorType != null,
"Missing TProcessor, %s is not a valid thrift service.", serviceType.getName());
Preconditions.checkArgument(ifaceType != null,
"Missing Iface, %s is not a valid thrift service.", serviceType.getName());
// If handler already implements the Iface, simply delegate
if (ifaceType.isAssignableFrom(handlerType)) {
return createProxyProcessor(handlerType, processorType, ifaceType);
}
throw new IllegalArgumentException("Unsupported handler type.");
}
示例12: getProcessorIface
import org.apache.thrift.TProcessor; //导入依赖的package包/类
/**
* 根据refImpl来获取相应的TProcessor,然后构造一个对象
*
* @return
*/
private TProcessor getProcessorIface(Class iface) {
if (iface == null) {
LOGGER.error("refImpl is not thrift implement class instance.");
throw new OureaException("invalid null refImpl params");
}
String parentClazzName = StringUtils.substringBeforeLast(iface.getCanonicalName(), ".Iface");
String processorClazzName = parentClazzName + "$Processor";
try {
Class clazz = Class.forName(processorClazzName);
if (clazz.isMemberClass() && !clazz.isInterface()) {
@SuppressWarnings("unchecked")
Class<TProcessor> processorClazz = (Class<TProcessor>) clazz;
return processorClazz.getConstructor(iface).newInstance(refImpl);
}
return null;
} catch (Exception e) {
LOGGER.error("get thrift Porcessor class from Iface class fail.e:", e);
throw new OureaException("invalid iface class params maybe not thrift class.");
}
}
示例13: createThrift
import org.apache.thrift.TProcessor; //导入依赖的package包/类
private static boolean createThrift() {
String flag = getClassName() + ".createThrift";
try {
TProcessor tProcessor = new FrcService.Processor<FrcService.Iface>(theInstance);
TNonblockingServerSocket tnbSocketTransport = new TNonblockingServerSocket(thrift_port);
TNonblockingServer.Args tnbArgs = new TNonblockingServer.Args(tnbSocketTransport);
tnbArgs.maxReadBufferBytes = DefaultValues.THRIFT_MAX_READ_BUF;
tnbArgs.processor(tProcessor);
// tnbArgs.transportFactory(new LCQTFramedTransport.Factory());
tnbArgs.transportFactory(new TFramedTransport.Factory());
tnbArgs.protocolFactory(new TBinaryProtocol.Factory());
server = new TNonblockingServer(tnbArgs);
// server.setServerEventHandler(new LCQTServerEventHandler());
return true;
} catch (Exception e) {
FRCLogger.getInstance().warn(-100, flag, "exception", e);
return false;
}
}
示例14: ThriftServerThread
import org.apache.thrift.TProcessor; //导入依赖的package包/类
public ThriftServerThread(InetAddress listenAddr,
int listenPort,
int listenBacklog,
TProcessor processor,
TTransportFactory transportFactory)
{
// now we start listening for clients
logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort));
TServerFactory.Args args = new TServerFactory.Args();
args.tProtocolFactory = new TBinaryProtocol.Factory(true, true);
args.addr = new InetSocketAddress(listenAddr, listenPort);
args.listenBacklog = listenBacklog;
args.processor = processor;
args.keepAlive = DatabaseDescriptor.getRpcKeepAlive();
args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize();
args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize();
args.inTransportFactory = transportFactory;
args.outTransportFactory = transportFactory;
serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args);
}
示例15: ThriftServerThread
import org.apache.thrift.TProcessor; //导入依赖的package包/类
public ThriftServerThread(InetAddress listenAddr,
int listenPort,
CassandraServer server,
TProcessor processor,
TTransportFactory transportFactory)
{
// now we start listening for clients
logger.info(String.format("Binding thrift service to %s:%s", listenAddr, listenPort));
TServerFactory.Args args = new TServerFactory.Args();
args.tProtocolFactory = new TBinaryProtocol.Factory(true, true);
args.addr = new InetSocketAddress(listenAddr, listenPort);
args.cassandraServer = server;
args.processor = processor;
args.keepAlive = DatabaseDescriptor.getRpcKeepAlive();
args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize();
args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize();
args.inTransportFactory = transportFactory;
args.outTransportFactory = transportFactory;
serverEngine = new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args);
}