Search in sources :

Example 46 with TServerSocket

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

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

the class SecurityUtils method getServerSSLSocket.

public static TServerSocket getServerSSLSocket(String hiveHost, int portNum, String keyStorePath, String keyStorePassWord, String keyStoreType, String keyStoreAlgorithm, List<String> sslVersionBlacklist) throws TTransportException, UnknownHostException {
    TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
    String kStoreType = keyStoreType.isEmpty() ? KeyStore.getDefaultType() : keyStoreType;
    String kStoreAlgorithm = keyStoreAlgorithm.isEmpty() ? KeyManagerFactory.getDefaultAlgorithm() : keyStoreAlgorithm;
    params.setKeyStore(keyStorePath, keyStorePassWord, kStoreAlgorithm, kStoreType);
    InetSocketAddress serverAddress;
    if (hiveHost == null || hiveHost.isEmpty()) {
        // Wildcard bind
        serverAddress = new InetSocketAddress(portNum);
    } else {
        serverAddress = new InetSocketAddress(hiveHost, portNum);
    }
    TServerSocket thriftServerSocket = TSSLTransportFactory.getServerSocket(portNum, 0, serverAddress.getAddress(), params);
    if (thriftServerSocket.getServerSocket() instanceof SSLServerSocket) {
        List<String> sslVersionBlacklistLocal = new ArrayList<>();
        for (String sslVersion : sslVersionBlacklist) {
            sslVersionBlacklistLocal.add(sslVersion.trim().toLowerCase());
        }
        SSLServerSocket sslServerSocket = (SSLServerSocket) thriftServerSocket.getServerSocket();
        List<String> enabledProtocols = new ArrayList<>();
        for (String protocol : sslServerSocket.getEnabledProtocols()) {
            if (sslVersionBlacklistLocal.contains(protocol.toLowerCase())) {
                LOG.debug("Disabling SSL Protocol: " + protocol);
            } else {
                enabledProtocols.add(protocol);
            }
        }
        sslServerSocket.setEnabledProtocols(enabledProtocols.toArray(new String[0]));
        LOG.info("SSL Server Socket Enabled Protocols: " + Arrays.toString(sslServerSocket.getEnabledProtocols()));
    }
    return thriftServerSocket;
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) SSLServerSocket(javax.net.ssl.SSLServerSocket)

Example 48 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");
    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 49 with TServerSocket

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