Search in sources :

Example 6 with TServerSocket

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

the class AbstractTest method init.

protected void init() throws Exception {
    serverTransport = new TServerSocket(PORT);
    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).inputProtocolFactory(bFactory).outputProtocolFactory(bFactory).inputTransportFactory(getTransportFactory()).outputTransportFactory(getTransportFactory()).processor(getProcessor()));
    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }
    };
    startTread.setName("thrift-server");
    startTread.start();
    while (!server.isServing()) {
        Thread.sleep(100);
    }
    protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension(ThriftProtocol.NAME);
    invoker = protocol.refer(getInterface(), getUrl());
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 7 with TServerSocket

use of org.apache.thrift.transport.TServerSocket 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");
    field.setAccessible(true);
    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(com.alibaba.dubbo.rpc.protocol.thrift.ext.MultiServiceProcessor) MultiServiceProcessor(com.alibaba.dubbo.rpc.protocol.thrift.ext.MultiServiceProcessor) TServerTransport(org.apache.thrift.transport.TServerTransport) com.alibaba.dubbo.rpc.gen.dubbo.$__DemoStub(com.alibaba.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 8 with TServerSocket

use of org.apache.thrift.transport.TServerSocket 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)

Example 9 with TServerSocket

use of org.apache.thrift.transport.TServerSocket 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 10 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project accumulo by apache.

the class TServerUtilsTest method testStopTServer_NoES.

@Test
public void testStopTServer_NoES() {
    TServerSocket socket = createNiceMock(TServerSocket.class);
    TServerWithoutES s = new TServerWithoutES(socket);
    TServerUtils.stopTServer(s);
    assertTrue(s.stopCalled);
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) Test(org.junit.Test)

Aggregations

TServerSocket (org.apache.thrift.transport.TServerSocket)49 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)30 TServerTransport (org.apache.thrift.transport.TServerTransport)20 TServer (org.apache.thrift.server.TServer)15 InetSocketAddress (java.net.InetSocketAddress)14 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)14 TTransportException (org.apache.thrift.transport.TTransportException)13 TTransportFactory (org.apache.thrift.transport.TTransportFactory)11 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)9 ArrayList (java.util.ArrayList)7 TProtocol (org.apache.thrift.protocol.TProtocol)7 TSimpleServer (org.apache.thrift.server.TSimpleServer)7 TTransport (org.apache.thrift.transport.TTransport)7 TProcessor (org.apache.thrift.TProcessor)6 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)6 TServerEventHandler (org.apache.thrift.server.TServerEventHandler)6 IOException (java.io.IOException)5 ExecutorService (java.util.concurrent.ExecutorService)5 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)5 ServerContext (org.apache.thrift.server.ServerContext)5