org.apache.thrift.TMultiplexedProcessor Java Examples

The following examples show how to use org.apache.thrift.TMultiplexedProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DKSQLUtilsServer.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        multiplexedProcessor = new TMultiplexedProcessor();

        sqlEngineHandler = new DKSQLEngineImpl();
        sqlEngineProcessor = new DKSQLEngine.Processor(sqlEngineHandler);
        multiplexedProcessor.registerProcessor("SQLEngineService", sqlEngineProcessor);

        Runnable simple = new Runnable() {
            public void run() {
                simple(multiplexedProcessor);
            }
        };
        new Thread(simple).start();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
 
Example #2
Source File: DKSearchService.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *
 * 简单的单线程模式
 *
 */
public  void  startService(){
    System.out.println( " start ...." );
    //单接口声明
    //TProcessor tProcessor=new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() );
    //多接口声明
    TMultiplexedProcessor processor = new TMultiplexedProcessor();
    processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) );
    processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl()  ) );
    processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) );
    try {
        TServerSocket serverSocket=new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")) );
        TServer.Args targs=new TServer.Args( serverSocket );
        targs.processor( processor );
        //二进制TBinaryProtocol
        //二进制高密度TCompactProtocol
        targs.protocolFactory( new TCompactProtocol.Factory(  ) );
        TServer tServer=new TSimpleServer( targs );
        tServer.serve();
    } catch (TTransportException e) {
        System.err.println("Service Start error");
        e.printStackTrace();
    }
}
 
Example #3
Source File: DKSearchService.java    From dk-fitting with Apache License 2.0 6 votes vote down vote up
/**
 *  线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
 */
public void startTThreadPoolServer() {
    try {
        System.out.println("UserInfoServiceDemo TThreadPoolServer start ....");
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) );
        processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl()  ) );
        processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) );
        //TProcessor tprocessor = new UserInfoService.Processor<UserInfoService.Iface>(new UserInfoServiceImpl());
        TServerSocket serverTransport = new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")));
        TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
        ttpsArgs.processor(processor);
        ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
        // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
        TServer server = new TThreadPoolServer(ttpsArgs);
        server.serve();
    } catch (Exception e) {
        System.out.println("Server start error!!!");
        e.printStackTrace();

    }

}
 
Example #4
Source File: MultiServiceServer.java    From ThriftBook with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #5
Source File: DKDataSourceServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    try {
        multiplexedProcessor = new TMultiplexedProcessor();

        dkdbInputHandler = new DKDBInputImpl();
        dkdbInputProcessor = new DKDBInput.Processor(dkdbInputHandler);

        dkdbOutputHandler = new DKDBOutputImpl();
        dkdbOutputProcessor = new DKDBOutput.Processor(dkdbOutputHandler);

        dkFileInputHandler = new DKFileInputImpl();
        dkFileInputProcessor = new DKFileInput.Processor(dkFileInputHandler);

        dkFileOutputHandler = new DKFileOutputImpl();
        dkFileOutputProcessor = new DKFileOutput.Processor(dkFileOutputHandler);

        dkEsHandleHandler = new DKESHandleImpl();
        dkEsHandleProcessor = new DKESHandle.Processor(dkEsHandleHandler);

        multiplexedProcessor.registerProcessor("DKDBInputService", dkdbInputProcessor);
        multiplexedProcessor.registerProcessor("DKDBOutputService", dkdbOutputProcessor);
        multiplexedProcessor.registerProcessor("DKFileInputService", dkFileInputProcessor);
        multiplexedProcessor.registerProcessor("DKFileOutputService", dkFileOutputProcessor);
        multiplexedProcessor.registerProcessor("DKESHandleService", dkEsHandleProcessor);

        Runnable simple = new Runnable() {
            public void run() {
                simple(multiplexedProcessor);
            }
        };
        new Thread(simple).start();
    } catch (Exception x) {
        x.printStackTrace();
    }
}
 
Example #6
Source File: DKDataSourceServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void simple(TMultiplexedProcessor processor) {
    try {
        Properties Prop = PropUtil.loadProp(System.getProperty("user.dir") + "/conf/datasource.properties");
        //Properties Prop = PropUtil.loadProp("D:\\workspace\\fitting\\fitting-datasource\\src\\main\\resources\\datasource.properties");
        int port = Integer.valueOf(Prop.getProperty("datasource.port"));
        TServerTransport serverTransport = new TServerSocket(port);
        TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Start server on port " + port + "...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #7
Source File: DKSQLUtilsServer.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void simple(TMultiplexedProcessor processor) {
    try {
        Properties Prop = PropUtil.loadProp(System.getProperty("user.dir") + "/conf/sqlutils.properties");
        //Properties Prop = PropUtil.loadProp("D:\\workspace\\fitting\\fitting-sqlutils\\src\\main\\resources\\sqlutils.properties");
        int port = Integer.valueOf(Prop.getProperty("sqlutils.port"));
        TServerTransport serverTransport = new TServerSocket(port);
        TThreadPoolServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Start server on port " + port + "...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: SentryHDFSServiceProcessorFactory.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: SentryGenericPolicyProcessorFactory.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
@Override
public boolean register(TMultiplexedProcessor multiplexedProcessor) throws Exception {
  SentryGenericPolicyProcessor processHandler = new SentryGenericPolicyProcessor(conf);
  TProcessor processor = new SentryGenericPolicyProcessorWrapper<SentryGenericPolicyService.Iface>(
      processHandler);
  multiplexedProcessor.registerProcessor(SentryGenericPolicyProcessor.SENTRY_GENERIC_SERVICE_NAME, processor);
  return true;
}
 
Example #10
Source File: SentryPolicyStoreProcessorFactory.java    From incubator-sentry with Apache License 2.0 5 votes vote down vote up
public boolean register(TMultiplexedProcessor multiplexedProcessor) throws Exception {
  SentryPolicyStoreProcessor sentryServiceHandler =
      new SentryPolicyStoreProcessor(SentryPolicyStoreProcessor.SENTRY_POLICY_SERVICE_NAME,
          conf);
  TProcessor processor =
    new SentryProcessorWrapper<SentryPolicyService.Iface>(sentryServiceHandler);
  multiplexedProcessor.registerProcessor(SentryPolicyStoreProcessor.SENTRY_POLICY_SERVICE_NAME, processor);
  return true;
}
 
Example #11
Source File: BasicAbstractTest.java    From Thrift-Connection-Pool with Apache License 2.0 4 votes vote down vote up
protected ThriftServerInfo startMulitServiceServer() throws Throwable {
	// 获取一个监听端口
	final int port = choseListenPort();
	ThriftServerInfo serverInfo = new ThriftServerInfo(LOACLHOST, port);
	final AtomicReference<Throwable> ex = new AtomicReference<Throwable>();
	// TODO
	Thread runner = new Thread("thrift-server-starter") {
		@Override
		public void run() {
			try {
				TMultiplexedProcessor processor = new TMultiplexedProcessor();
				TServerTransport serverTransport = new TServerSocket(port);
				Factory proFactory = new TBinaryProtocol.Factory();

				processor.registerProcessor("example", new Example.Processor<Example.Iface>(new Example.Iface() {

					@Override
					public void pong() throws TException {
						logger.info("example pong");
					}

					@Override
					public void ping() throws TException {
						logger.info("example ping");
					}
				}));

				processor.registerProcessor("other", new Other.Processor<Other.Iface>(new Other.Iface() {

					@Override
					public void pong() throws TException {
						logger.info("other pong");
					}

					@Override
					public void ping() throws TException {
						logger.info("other ping");
					}
				}));
				Args thriftArgs = new Args(serverTransport);
				thriftArgs.processor(processor);
				thriftArgs.protocolFactory(proFactory);
				TServer tserver = new TThreadPoolServer(thriftArgs);
				servers.add(tserver);
				logger.info("启动测试服务监听:" + port);
				tserver.serve();
			} catch (TTransportException e) {
				logger.error("thrift服务器启动失败", e);
				ex.set(e);
			}
		}
	};

	runner.start();

	Throwable throwable = ex.get();
	if (throwable != null) {
		throw throwable;
	}
	// 等待服务器启动
	Thread.sleep(1000);
	return serverInfo;
}
 
Example #12
Source File: DKStreamDataServer.java    From dk-fitting with Apache License 2.0 2 votes vote down vote up
public void startServer() {

        try {
            System.out.println("Server start ....");


            // 简单的单线程服务模型,一般用于测试
            TServerSocket serverTransport = new TServerSocket(  SERVER_PORT  );
            TMultiplexedProcessor processor = new TMultiplexedProcessor();



            //注册一个服务接口
            DKStreamProducerService.Processor<DKStreamProducerServiceImpl> pro =
                    new DKStreamProducerService.Processor<DKStreamProducerServiceImpl>(new DKStreamProducerServiceImpl());
            processor.registerProcessor("DKStreamProducerService", pro);

            //注册一个服务接口
            JavaKafkaConsumerHighAPIESService.Processor<JavaKafkaConsumerHighAPIESImpl> pro1 =
                    new JavaKafkaConsumerHighAPIESService.Processor<JavaKafkaConsumerHighAPIESImpl>(new JavaKafkaConsumerHighAPIESImpl());
            processor.registerProcessor("ESService", pro1);



            //注册一个服务接口

            JavaKafkaConsumerHighAPIHdfsService.Processor<JavaKafkaConsumerHighAPIHdfsImpl> pro3 =
                    new JavaKafkaConsumerHighAPIHdfsService.Processor<>(new JavaKafkaConsumerHighAPIHdfsImpl());
            processor.registerProcessor("JavaKafkaConsumerHighAPIHdfsService", pro3);


            TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
            ttpsArgs.processor(processor);
            ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());
            // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
            TServer server = new TThreadPoolServer(ttpsArgs);
            server.serve();


        } catch (Exception e) {
            System.out.println("Server start error!!!");
            e.printStackTrace();
        }


    }
 
Example #13
Source File: DataProcess.java    From dk-fitting with Apache License 2.0 2 votes vote down vote up
public void startServer() {

        try {
            System.out.println("Start server on port "+ SERVER_PORT +"...");

            // 简单的单线程服务模型,一般用于测试
            TServerSocket serverTransport = new TServerSocket(SERVER_PORT);

            TMultiplexedProcessor processor = new TMultiplexedProcessor();


            DataAnalysisService.Processor<DataAnalysisService.Iface> tprocessor =
                    new DataAnalysisService.Processor<>(new DataAnalysisImpl());
            processor.registerProcessor("DataAnalysisService", tprocessor);


            DataStaticKerberosService.Processor<DataStaticKerberosService.Iface> tprocessor1 =
                    new DataStaticKerberosService.Processor<DataStaticKerberosService.Iface>(new DataStaticKerberosImpl());
            processor.registerProcessor("DataStaticKerberosService", tprocessor1);

            DataStaticService.Processor<DataStaticService.Iface> tprocessor2 =
                    new DataStaticService.Processor<DataStaticService.Iface>(new DataStaticImpl());
            processor.registerProcessor("DataStaticService", tprocessor2);


            DedupeKerberosService.Processor<DedupeKerberosService.Iface> tprocessor3 =
                    new DedupeKerberosService.Processor<DedupeKerberosService.Iface>(new DedupeKerberosImpl());
            processor.registerProcessor("DedupeKerberosService", tprocessor3);


            DedupeService.Processor<DedupeService.Iface> tprocessor4 =
                    new DedupeService.Processor<DedupeService.Iface>(new DedupeImpl());
            processor.registerProcessor("DedupeService", tprocessor4);

            FormatFieldService.Processor<FormatFieldService.Iface> tprocessor5 =
                    new FormatFieldService.Processor<FormatFieldService.Iface>(new FormatFieldImpl());
            processor.registerProcessor("FormatFieldService", tprocessor5);


            FormatRecService.Processor<FormatRecService.Iface> tprocessor6 =
                    new FormatRecService.Processor<FormatRecService.Iface>(new FormatRecImpl());
            processor.registerProcessor("FormatRecService", tprocessor6);

            SelectFieldService.Processor<SelectFieldService.Iface> tprocessor7 =
                    new SelectFieldService.Processor<SelectFieldService.Iface>(new SelectFieldImlp());
            processor.registerProcessor("SelectFieldService", tprocessor7);

            SelectRecService.Processor<SelectRecService.Iface> tprocessor8 =
                    new SelectRecService.Processor<SelectRecService.Iface>(new SelectRecImpl());
            processor.registerProcessor("SelectRecService", tprocessor8);


            DataCleanKerberosService.Processor<DataCleanKerberosService.Iface> tprocessor9 =
                    new DataCleanKerberosService.Processor<DataCleanKerberosService.Iface>(new DataCleanKerberosImpl());
            processor.registerProcessor("DataCleanKerberosService", tprocessor9);

            TThreadPoolServer.Args ttpsArgs = new TThreadPoolServer.Args(serverTransport);
            ttpsArgs.processor(processor);
            ttpsArgs.protocolFactory(new TBinaryProtocol.Factory());

            // 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求。
            TServer server = new TThreadPoolServer(ttpsArgs);
            server.serve();



        } catch (Exception e) {
            System.out.println("Server start error!!!");
            e.printStackTrace();
        }


    }
 
Example #14
Source File: ProcessorFactory.java    From incubator-sentry with Apache License 2.0 votes vote down vote up
public abstract boolean register(TMultiplexedProcessor processor) throws Exception;