Search in sources :

Example 16 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project rubix by qubole.

the class TestPoolingClient method startServer.

private static void startServer(final Configuration conf) throws TTransportException {
    if (server != null) {
        return;
    }
    Processor processor = new Processor();
    TServerTransport serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().bindAddr(new InetSocketAddress(PORT)).backlog(Integer.MAX_VALUE));
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(new TestingService.Processor(processor)).maxWorkerThreads(getServerMaxThreads(conf)));
    server.serve();
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) InetSocketAddress(java.net.InetSocketAddress) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 17 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project rubix by qubole.

the class BookKeeperServer method createThriftServer.

private void createThriftServer(Configuration conf, BookKeeper bookKeeper) {
    processor = new BookKeeperService.Processor(bookKeeper);
    log.info("Starting BookKeeperServer on port " + getBookKeeperServerPort(conf));
    try {
        TServerTransport serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().bindAddr(new InetSocketAddress(getBookKeeperServerPort(conf))).backlog(Integer.MAX_VALUE));
        server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor).maxWorkerThreads(getServerMaxThreads(conf)));
    } catch (TTransportException e) {
        throw new RuntimeException("Error starting BookKeeperServer", e);
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) BookKeeperService(com.qubole.rubix.spi.thrift.BookKeeperService) InetSocketAddress(java.net.InetSocketAddress) TTransportException(org.apache.thrift.transport.TTransportException) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 18 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project dubbo by alibaba.

the class ServiceMethodNotFoundTest method init.

protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket(PORT);
    DubboDemoImpl impl = new DubboDemoImpl();
    $__DemoStub.Processor processor = new $__DemoStub.Processor(impl);
    // for test
    Field field = processor.getClass().getSuperclass().getDeclaredField("processMap");
    ReflectUtils.makeAccessible(field);
    Object obj = field.get(processor);
    if (obj instanceof Map) {
        ((Map) obj).remove("echoString");
    }
    // ~
    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
    MultiServiceProcessor wrapper = new MultiServiceProcessor();
    wrapper.addProcessor(Demo.class, processor);
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).inputProtocolFactory(bFactory).outputProtocolFactory(bFactory).inputTransportFactory(getTransportFactory()).outputTransportFactory(getTransportFactory()).processor(wrapper));
    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }
    };
    startTread.start();
    while (!server.isServing()) {
        Thread.sleep(100);
    }
}
Also used : MultiServiceProcessor(org.apache.dubbo.rpc.protocol.thrift.ext.MultiServiceProcessor) MultiServiceProcessor(org.apache.dubbo.rpc.protocol.thrift.ext.MultiServiceProcessor) TServerTransport(org.apache.thrift.transport.TServerTransport) org.apache.dubbo.rpc.gen.dubbo.$__DemoStub(org.apache.dubbo.rpc.gen.dubbo.$__DemoStub) TServerSocket(org.apache.thrift.transport.TServerSocket) Field(java.lang.reflect.Field) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) Map(java.util.Map)

Example 19 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project yyl_example by Relucent.

the class HelloServer method getSimpleServer.

/**
 * 简单的单线程服务模型,一般用于测试
 */
public static TServer getSimpleServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TServer server = new TSimpleServer(new TServer.Args(transport).processor(processor));
    return server;
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) TSimpleServer(org.apache.thrift.server.TSimpleServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 20 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project tech by ffyyhh995511.

the class Test1 method main.

/**
 * 编写服务端,发布(阻塞式IO + 多线程处理)服务
 *
 * @param args
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
    try {
        // 设置传输通道,普通通道
        TServerTransport serverTransport = new TServerSocket(7911);
        // 使用高密度二进制协议
        TProtocolFactory proFactory = new TCompactProtocol.Factory();
        // 设置处理器HelloImpl
        TProcessor processor = new Hello.Processor(new HelloImpl());
        // 创建服务器
        Args args2 = new Args(serverTransport);
        args2.protocolFactory(proFactory);
        args2.processor(processor);
        TServer server = new TThreadPoolServer(args2);
        System.out.println("Start server on port 7911...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) Args(org.apache.thrift.server.TThreadPoolServer.Args) TProcessor(org.apache.thrift.TProcessor) HelloImpl(org.tech.model.impl.HelloImpl) TProcessor(org.apache.thrift.TProcessor) TServer(org.apache.thrift.server.TServer) TProtocolFactory(org.apache.thrift.protocol.TProtocolFactory) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Aggregations

TServerSocket (org.apache.thrift.transport.TServerSocket)22 TServerTransport (org.apache.thrift.transport.TServerTransport)22 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)16 InetSocketAddress (java.net.InetSocketAddress)11 TTransportException (org.apache.thrift.transport.TTransportException)9 TServer (org.apache.thrift.server.TServer)8 Map (java.util.Map)3 TProcessor (org.apache.thrift.TProcessor)3 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)3 TSimpleServer (org.apache.thrift.server.TSimpleServer)3 Field (java.lang.reflect.Field)2 ExecutorService (java.util.concurrent.ExecutorService)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 com.alibaba.dubbo.rpc.gen.dubbo.$__DemoStub (com.alibaba.dubbo.rpc.gen.dubbo.$__DemoStub)1 MultiServiceProcessor (com.alibaba.dubbo.rpc.protocol.thrift.ext.MultiServiceProcessor)1 CrossPlatformService (com.baeldung.thrift.impl.CrossPlatformService)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Config (com.netflix.metacat.common.server.properties.Config)1 RegistryUtil (com.netflix.metacat.common.server.util.RegistryUtil)1 Registry (com.netflix.spectator.api.Registry)1