Search in sources :

Example 11 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 12 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project hbase by apache.

the class ThriftServer method getTThreadPoolServer.

protected TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor, TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws Exception {
    LOG.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    // Thrift's implementation uses '0' as a placeholder for 'use the default.'
    int backlog = conf.getInt(BACKLOG_CONF_KEY, BACKLOG_CONF_DEAFULT);
    int readTimeout = conf.getInt(THRIFT_SERVER_SOCKET_READ_TIMEOUT_KEY, THRIFT_SERVER_SOCKET_READ_TIMEOUT_DEFAULT);
    TServerTransport serverTransport = new TServerSocket(new TServerSocket.ServerSocketTransportArgs().bindAddr(inetSocketAddress).backlog(backlog).clientTimeout(readTimeout));
    TBoundedThreadPoolServer.Args serverArgs = new TBoundedThreadPoolServer.Args(serverTransport, conf);
    serverArgs.processor(processor).transportFactory(transportFactory).protocolFactory(protocolFactory);
    return new TBoundedThreadPoolServer(serverArgs, metrics);
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 13 with TServerTransport

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

the class AMServer method simple.

public void simple(JstormAM.Processor processor) {
    try {
        TServerTransport serverTransport = new TServerSocket(port);
        TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        LOG.info("Starting the simple server...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
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 14 with TServerTransport

use of org.apache.thrift.transport.TServerTransport in project vcell by virtualcell.

the class VCellProxyServer method startSimpleVCellProxyServer.

private static void startSimpleVCellProxyServer(VCellProxy.Processor<VCellProxyHandler> processor) {
    try {
        InetSocketAddress inetSocketAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 9090);
        TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
        TServer vcellProxyServer = new TSimpleServer(new org.apache.thrift.server.TServer.Args(serverTransport).processor(processor));
        System.out.println("Starting the VCell-VisIt Data Server thread...");
        vcellProxyServer.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TServer(org.apache.thrift.server.TServer) InetSocketAddress(java.net.InetSocketAddress) TSimpleServer(org.apache.thrift.server.TSimpleServer) TServerTransport(org.apache.thrift.transport.TServerTransport)

Example 15 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);
    RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService);
    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) RegistryUtil(com.netflix.metacat.common.server.util.RegistryUtil) 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) Registry(com.netflix.spectator.api.Registry) 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)

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