org.apache.thrift.server.TSimpleServer Java Examples

The following examples show how to use org.apache.thrift.server.TSimpleServer. 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: 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 #2
Source File: ThriftServerApplication.java    From spring-boot-demo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    SpringApplication.run(ThriftServerApplication.class, args);

    try {
        System.out.println("服务端开启....");
        TProcessor tprocessor = new Hello.Processor<Hello.Iface>(new HelloServiceImpl());
        // 简单的单线程服务模型
        TServerSocket serverTransport = new TServerSocket(9898);
        TServer.Args tArgs = new TServer.Args(serverTransport);
        tArgs.processor(tprocessor);
        tArgs.protocolFactory(new TBinaryProtocol.Factory());
        TServer server = new TSimpleServer(tArgs);
        server.serve();
    } catch (TTransportException e) {
        e.printStackTrace();
    }
}
 
Example #3
Source File: SyncEchoTestServer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public static SyncEchoTestServer<TSimpleServer> simpleServer(final TestEnvironment environment)
        throws TTransportException {
    TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(new TServerSocket(environment.getPort()))
            .processor(getProcessor()).inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<TSimpleServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.Client(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
 
Example #4
Source File: TestApacheThriftMethodInvoker.java    From drift with Apache License 2.0 5 votes vote down vote up
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new 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();
        }
    }
}
 
Example #5
Source File: TestDriftNettyMethodInvoker.java    From drift with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example #6
Source File: ThriftExample.java    From pragmatic-java-engineer with GNU General Public License v3.0 5 votes vote down vote up
public static void testRpcServer() throws TTransportException {
    TProcessor tprocessor = new TestService.Processor<TestService.Iface>(new TestServiceImpl());

    TServerSocket serverTransport = new TServerSocket(8088);
    TServer.Args tArgs = new TServer.Args(serverTransport);
    tArgs.processor(tprocessor);
    tArgs.protocolFactory(new TBinaryProtocol.Factory());

    // 简单的单线程服务模型
    TServer server = new TSimpleServer(tArgs);
    server.serve();
}
 
Example #7
Source File: SimpleThriftServerImpl.java    From ikasoa with MIT License 5 votes vote down vote up
protected void initServer(TServerTransport serverTransport) {
	ThriftServerConfiguration configuration = getServerConfiguration();
	server = new TSimpleServer(configuration.getServerArgsAspect().tServerArgsAspect(
			new TServer.Args(serverTransport).transportFactory(configuration.getTransportFactory())
					.protocolFactory(configuration.getProtocolFactory()).processor(getProcessor())));
	if (ObjectUtil.isNotNull(configuration.getServerEventHandler()))
		server.setServerEventHandler(configuration.getServerEventHandler());
}
 
Example #8
Source File: Configurator.java    From xio with Apache License 2.0 5 votes vote down vote up
public void run() {
  log.info("Starting up!");
  try {
    serverTransport = new TServerSocket(bindAddress);
    server = new TSimpleServer(new Args(serverTransport).processor(processor));
    server.serve(); // blocks until stop() is called.
    // timer and timer task should be stopped at this point
    writeToStorage();
  } catch (TTransportException e) {
    log.error("Couldn't start Configurator {}", this, e);
  }
}
 
Example #9
Source File: HelloServer.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new helloSvc.Processor<>(new MessageHandler());
    TServer server =
            new TSimpleServer(
                    new TSimpleServer.Args(trans_svr)
                            .processor(proc)
            );
    System.out.println("[Server] waiting for connections");
    server.serve();
}
 
Example #10
Source File: HelloServer.java    From ThriftBook with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new helloSvc.Processor<>(new MessageHandler());
    TSimpleServer server = 
        new TSimpleServer(
            new TSimpleServer.Args(trans_svr)
                .processor(proc)
        );
    System.out.println("[Server] waiting for connections");
    server.serve();
}
 
Example #11
Source File: CrossPlatformServiceServer.java    From tutorials with MIT License 5 votes vote down vote up
public void start() throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(9090);
    server = new TSimpleServer(new TServer.Args(serverTransport)
        .processor(new CrossPlatformService.Processor<>(new CrossPlatformServiceImpl())));

    System.out.print("Starting the server... ");

    server.serve();

    System.out.println("done.");
}
 
Example #12
Source File: SimpleServer.java    From ThriftBook with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new SocialLookup.Processor<>(new SocialLookupHandler());
    TServer server = new TSimpleServer(new TSimpleServer.Args(trans_svr).processor(proc));
    server.serve();
}
 
Example #13
Source File: ThriftSimpleServerIT.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
protected ThriftEchoTestServer<TSimpleServer> createEchoServer(TestEnvironment environment) throws TTransportException {
    return SyncEchoTestServerFactory.simpleServer(environment);
}