本文整理汇总了Java中org.apache.thrift.TMultiplexedProcessor类的典型用法代码示例。如果您正苦于以下问题:Java TMultiplexedProcessor类的具体用法?Java TMultiplexedProcessor怎么用?Java TMultiplexedProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TMultiplexedProcessor类属于org.apache.thrift包,在下文中一共展示了TMultiplexedProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
public static void main(String[] args) throws TTransportException, IOException, InterruptedException {
TNonblockingServerSocket trans_svr = new TNonblockingServerSocket(9090);
TMultiplexedProcessor proc = new TMultiplexedProcessor();
proc.registerProcessor("Message", new Message.Processor<>(new MessageHandler()));
proc.registerProcessor("ServerTime", new ServerTime.Processor<>(new ServerTimeHandler()));
TServer server = new TThreadedSelectorServer(
new TThreadedSelectorServer.Args(trans_svr)
.processor(proc)
.protocolFactory(new TJSONProtocol.Factory())
.workerThreads(6)
.selectorThreads(3));
Thread server_thread = new Thread(new RunnableServer(server), "server_thread");
server_thread.start();
System.out.println("[Server] press enter to shutdown> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
System.out.println("[Server] shutting down...");
server.stop();
server_thread.join();
System.out.println("[Server] down, exiting");
}
示例2: start
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的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();
}
}
示例3: startServer
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的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();
}
}
示例4: ServerThread
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的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);
}
示例5: main
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
public static void main(String[] args) {
try {
userProfileServerHandler = new UserProfileServerHandler();
userProfileProcessor = new UserProfileService.Processor(userProfileServerHandler);
TMultiplexedProcessor airavataServerProcessor = new TMultiplexedProcessor();
airavataServerProcessor.registerProcessor("UserProfileService", userProfileProcessor);
TServerTransport serverTransport = new TServerSocket(9190);
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(airavataServerProcessor));
System.out.println("Starting User Profile server...");
server.serve();
} catch (Exception x) {
x.printStackTrace();
}
}
示例6: testKaaNodeInitializationServiceStart
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
/**
* Test kaa node initialization service start.
*
* @throws Exception the exception
*/
@Test
public void testKaaNodeInitializationServiceStart() throws Exception {
KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();
TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
Mockito.doNothing().when(server).serve();
Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
Mockito.any(TMultiplexedProcessor.class));
kaaNodeInitializationService.start();
Mockito.verify(controlInitializationService).start();
Mockito.verify(bootstrapInitializationService).start();
Mockito.verify(operationsInitializationService).start();
}
示例7: testKaaNodeInitializationServiceStartTransportException
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
/**
* Test kaa node initialization service start with transport exception.
*
* @throws Exception the exception
*/
@Test
public void testKaaNodeInitializationServiceStartTransportException() throws Exception {
KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();
TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
Mockito.doThrow(TTransportException.class).when(server).serve();
Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
Mockito.any(TMultiplexedProcessor.class));
kaaNodeInitializationService.start();
Mockito.verify(controlInitializationService).start();
Mockito.verify(bootstrapInitializationService).start();
Mockito.verify(operationsInitializationService).start();
}
示例8: testKaaNodeInitializationServiceStop
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
/**
* Test kaa node initialization service stop.
*
* @throws Exception the exception
*/
@Test
public void testKaaNodeInitializationServiceStop() throws Exception {
KaaNodeInitializationService kaaNodeInitializationService = kaaNodeInitializationServiceSpy();
TThreadPoolServer server = Mockito.mock(TThreadPoolServer.class);
Mockito.doNothing().when(server).serve();
Mockito.doReturn(server).when(kaaNodeInitializationService).createServer(Mockito.any(TServerTransport.class),
Mockito.any(TMultiplexedProcessor.class));
kaaNodeInitializationService.start();
kaaNodeInitializationService.stop();
Mockito.verify(controlInitializationService).start();
Mockito.verify(bootstrapInitializationService).start();
Mockito.verify(operationsInitializationService).start();
Mockito.verify(controlInitializationService).stop();
Mockito.verify(bootstrapInitializationService).stop();
Mockito.verify(operationsInitializationService).stop();
}
示例9: init
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的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: startNettyServer
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
public void startNettyServer(int port) throws InterruptedException {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
processor.registerProcessor(ClassNameUtils.getClassName(Hello.class), new Hello.Processor<>(new HelloServer()));
NettyServerArgs serverArgs = new NettyServerArgs()
.port(port)
.processor(processor);
TNettyServer server = new TNettyServer(serverArgs);
server.serve();
server.waitForClose();
}
示例11: init
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
@Override
public void init(NettyEmbeddedContext context) {
TMultiplexedProcessor tProcessor = new TMultiplexedProcessor();
context.setProcessor(tProcessor);
WebApplicationContext webApplicationContext = WebApplicationContextUtils.findWebApplicationContext(context);
String[] strarr = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(webApplicationContext, Object.class);
for (String s :strarr){
Object target = webApplicationContext.getBean(s);
ThriftEndpoint thriftEndpointAnnotation = target.getClass().getAnnotation(ThriftEndpoint.class);
if(thriftEndpointAnnotation!=null){
try {
Class targetInterface = target.getClass().getInterfaces()[0];
Class processorClass = Class.forName(targetInterface.getName().split("\\$")[0] + "$Processor");
TProcessor p = (TProcessor) processorClass.getDeclaredConstructors()[0].newInstance(target);
if(StringUtils.isNotBlank(thriftEndpointAnnotation.serviceName())){
s = thriftEndpointAnnotation.serviceName();
}
System.out.println(thriftEndpointAnnotation.serviceName());
logger.info("registerProcessorName : " + s + " registerProcessorClass: " + p.getClass());
tProcessor.registerProcessor(s,p);
} catch (Exception e) {
logger.error("registerProcessor error : " + e.getMessage() , e);
}
}
}
}
示例12: createProcessor
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
private static TProcessor createProcessor() {
TMultiplexedProcessor res = new TMultiplexedProcessor();
res.registerProcessor(QueryResultServiceConstants.SERVICE_NAME,
new LazyBindingProcessorProvider<>(QueryResultServiceHandler.class,
handler -> new QueryResultService.Processor<QueryResultService.Iface>(handler)));
res.registerProcessor(KeepAliveServiceConstants.SERVICE_NAME, new LazyBindingProcessorProvider<>(
KeepAliveServiceHandler.class, handler -> new KeepAliveService.Processor<KeepAliveService.Iface>(handler)));
res.registerProcessor(IdentityCallbackServiceConstants.SERVICE_NAME,
new LazyBindingProcessorProvider<>(IdentityCallbackHandler.class,
handler -> new IdentityCallbackService.Processor<IdentityCallbackService.Iface>(handler)));
// when adding new processors, update NUMBER_OF_PROCESSORS
return res;
}
示例13: createServer
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
/**
* Creates the server.
*
* @param serverTransport the server transport
* @param processor the processor
* @return the t server
*/
public TServer createServer(TServerTransport serverTransport, TMultiplexedProcessor processor) {
TThreadPoolServer.Args args = new Args(serverTransport).processor(processor);
args.stopTimeoutVal = 3;
args.stopTimeoutUnit = TimeUnit.SECONDS;
SynchronousQueue<Runnable> executorQueue = // NOSONAR
new SynchronousQueue<Runnable>();
executorService = new ThreadPoolExecutor(args.minWorkerThreads, args.maxWorkerThreads,
60, TimeUnit.SECONDS, executorQueue);
args.executorService = executorService;
return new TThreadPoolServer(args);
}
示例14: run
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
@Override
public void run() {
LOG.info("Initializing Thrift Service for Bootstrap Server....");
LOG.info("thrift host: {}", thriftHost);
LOG.info("thrift port: {}", thriftPort);
try {
TMultiplexedProcessor processor = new TMultiplexedProcessor();
BootstrapThriftService.Processor<BootstrapThriftService.Iface> bootstrapProcessor = new BootstrapThriftService.Processor<BootstrapThriftService.Iface>(
bootstrapThriftService);
processor.registerProcessor(KaaThriftService.BOOTSTRAP_SERVICE.getServiceName(), bootstrapProcessor);
TServerTransport serverTransport = new TServerSocket(new InetSocketAddress(thriftHost, thriftPort));
server = new TThreadPoolServer(new Args(serverTransport).processor(processor));
LOG.info("Bootstrap test Server {}:{} Started.", thriftHost, thriftPort);
synchronized (startSync) {
startComplete = true;
startSync.notify();
}
server.serve();
LOG.info("Bootstrap test Server {}:{} Stopped.", thriftHost, thriftPort);
} catch (TTransportException e) {
LOG.error("TTransportException", e);
} finally {
synchronized (stopSync) {
stopComplete = true;
bootstrapThriftService.reset();
stopSync.notify();
}
}
}
示例15: register
import org.apache.thrift.TMultiplexedProcessor; //导入依赖的package包/类
@Override
public boolean register(TMultiplexedProcessor multiplexedProcessor) throws Exception {
SentryHDFSServiceProcessor sentryServiceHandler =
new SentryHDFSServiceProcessor();
LOGGER.info("Calling registerProcessor from SentryHDFSServiceProcessorFactory");
TProcessor processor = new ProcessorWrapper(sentryServiceHandler);
multiplexedProcessor.registerProcessor(
SentryHDFSServiceClient.SENTRY_HDFS_SERVICE_NAME, processor);
return true;
}