Search in sources :

Example 6 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project metacat by Netflix.

the class AbstractThriftServer method start.

/**
     * Server initialization.
     *
     * @throws Exception error
     */
public void start() throws Exception {
    log.info("initializing thrift server {}", getServerName());
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(threadPoolNameFormat).setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: " + t.getName(), e)).build();
    final ExecutorService executorService = new ThreadPoolExecutor(Math.min(2, config.getThriftServerMaxWorkerThreads()), config.getThriftServerMaxWorkerThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory);
    final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000;
    final TServerTransport serverTransport = new TServerSocket(portNumber, timeout);
    startServing(executorService, serverTransport);
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Getter(lombok.Getter) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NonNull(lombok.NonNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TServer(org.apache.thrift.server.TServer) TServerTransport(org.apache.thrift.transport.TServerTransport) TimeUnit(java.util.concurrent.TimeUnit) TServerSocket(org.apache.thrift.transport.TServerSocket) Slf4j(lombok.extern.slf4j.Slf4j) TServerEventHandler(org.apache.thrift.server.TServerEventHandler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) ThreadFactory(java.util.concurrent.ThreadFactory) Config(com.netflix.metacat.common.server.properties.Config) ExecutorService(java.util.concurrent.ExecutorService) TProcessor(org.apache.thrift.TProcessor) TServerSocket(org.apache.thrift.transport.TServerSocket) ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 7 with TServerTransport

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

the class HelloServer method getPoolServer.

/** 线程池服务模型,使用标准的阻塞式IO,预先创建一组线程处理请求 */
public static TServer getPoolServer(int port, HelloService.Processor<HelloServiceHandler> processor) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(transport).processor(processor));
    return server;
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 8 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project commons by twitter.

the class PingPongServer method run.

@Override
public void run() {
    PingPongHandler handler = new PingPongHandler();
    PingPong.Processor processor = new PingPong.Processor(handler);
    TServer server;
    try {
        TServerTransport transport = new TServerSocket(THRIFT_PORT.get());
        server = new TSimpleServer(processor, transport);
    } catch (TTransportException e) {
        throw new RuntimeException(e);
    }
    LOG.info("Starting thrift server.");
    server.serve();
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) PingPong(com.twitter.common.examples.pingpong.PingPong) TTransportException(org.apache.thrift.transport.TTransportException) TSimpleServer(org.apache.thrift.server.TSimpleServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 9 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)

Aggregations

TServerSocket (org.apache.thrift.transport.TServerSocket)9 TServerTransport (org.apache.thrift.transport.TServerTransport)9 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)6 TServer (org.apache.thrift.server.TServer)5 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)3 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 TProcessor (org.apache.thrift.TProcessor)2 TSimpleServer (org.apache.thrift.server.TSimpleServer)2 TTransportFactory (org.apache.thrift.transport.TTransportFactory)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 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Config (com.netflix.metacat.common.server.properties.Config)1 PingPong (com.twitter.common.examples.pingpong.PingPong)1 Field (java.lang.reflect.Field)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1