Search in sources :

Example 16 with TServerSocket

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

the class ProfileServiceServer method start.

public void start() throws Exception {
    try {
        setStatus(ServerStatus.STARTING);
        final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort());
        final String serverHost = ServerSettings.getProfileServiceServerHost();
        // create multiple processors for each profile-service
        UserProfileService.Processor userProfileProcessor = new UserProfileService.Processor(new UserProfileServiceHandler());
        TenantProfileService.Processor teneantProfileProcessor = new TenantProfileService.Processor(new TenantProfileServiceHandler());
        IamAdminServices.Processor iamAdminServicesProcessor = new IamAdminServices.Processor(new IamAdminServicesHandler());
        // create a multiplexed processor
        TMultiplexedProcessor profileServiceProcessor = new TMultiplexedProcessor();
        profileServiceProcessor.registerProcessor(profile_user_cpiConstants.USER_PROFILE_CPI_NAME, userProfileProcessor);
        profileServiceProcessor.registerProcessor(profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME, teneantProfileProcessor);
        profileServiceProcessor.registerProcessor(iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME, iamAdminServicesProcessor);
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = 30;
        server = new TThreadPoolServer(options.processor(profileServiceProcessor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(ServerStatus.STOPPED);
                logger.info("Profile Service Server Stopped.");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    setStatus(ServerStatus.STARTED);
                    logger.info("Starting Profile Service Server on Port " + serverPort);
                    logger.info("Listening to Profile Service Server clients ....");
                }
            }
        }.start();
    } catch (TTransportException e) {
        setStatus(ServerStatus.FAILED);
        throw new Exception("Error while starting the Profile Service Server", e);
    }
}
Also used : TenantProfileService(org.apache.airavata.service.profile.tenant.cpi.TenantProfileService) UserProfileServiceHandler(org.apache.airavata.service.profile.handlers.UserProfileServiceHandler) TMultiplexedProcessor(org.apache.thrift.TMultiplexedProcessor) InetSocketAddress(java.net.InetSocketAddress) UserProfileService(org.apache.airavata.service.profile.user.cpi.UserProfileService) TMultiplexedProcessor(org.apache.thrift.TMultiplexedProcessor) TTransportException(org.apache.thrift.transport.TTransportException) TServerTransport(org.apache.thrift.transport.TServerTransport) TTransportException(org.apache.thrift.transport.TTransportException) TServerSocket(org.apache.thrift.transport.TServerSocket) IamAdminServices(org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices) IamAdminServicesHandler(org.apache.airavata.service.profile.handlers.IamAdminServicesHandler) TenantProfileServiceHandler(org.apache.airavata.service.profile.handlers.TenantProfileServiceHandler) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 17 with TServerSocket

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

the class OrchestratorServer method StartOrchestratorServer.

public void StartOrchestratorServer(OrchestratorService.Processor<OrchestratorServerHandler> orchestratorServerHandlerProcessor) throws Exception {
    final int serverPort = Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_PORT, "8940"));
    try {
        final String serverHost = ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_HOST, null);
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }
        // server = new TSimpleServer(
        // new TServer.Args(serverTransport).processor(orchestratorServerHandlerProcessor));
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = Integer.parseInt(ServerSettings.getSetting(Constants.ORCHESTRATOT_SERVER_MIN_THREADS, "30"));
        server = new TThreadPoolServer(options.processor(orchestratorServerHandlerProcessor));
        new Thread() {

            public void run() {
                server.serve();
                setStatus(ServerStatus.STARTING);
                logger.info("Starting Orchestrator Server ... ");
            }
        }.start();
        new Thread() {

            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {
                    setStatus(ServerStatus.STARTED);
                    logger.info("Started Orchestrator Server on Port " + serverPort + " ...");
                }
            }
        }.start();
    } catch (TTransportException e) {
        logger.error(e.getMessage());
        setStatus(ServerStatus.FAILED);
        logger.error("Failed to start Orchestrator server on port " + serverPort + " ...");
    }
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) 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 TServerSocket

use of org.apache.thrift.transport.TServerSocket in project mlib by myshzzx.

the class ThriftServerFactory method build.

/**
 * @return build but not start server.
 * @throws Exception
 */
@SuppressWarnings("ConstantConditions")
public TServer build() throws Exception {
    final TServer server;
    int poolSize = Runtime.getRuntime().availableProcessors() * 2;
    poolSize = Math.max(poolSize, this.serverPoolSize);
    AtomicInteger tpi = new AtomicInteger(1);
    ThreadPoolExecutor tPool = new ThreadPoolExecutor(poolSize, poolSize, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), r -> {
        Thread t = new Thread(r, "tServer-" + serverTPI.getAndIncrement() + "-" + tpi.getAndIncrement());
        t.setDaemon(true);
        return t;
    });
    tPool.allowCoreThreadTimeOut(true);
    if (useTLS) {
        // TLS server
        TSSLTransportFactory.TSSLTransportParameters transportParams = new TSSLTransportFactory.TSSLTransportParameters();
        transportParams.setKeyStore(ThriftServerFactory.class.getClassLoader().getResource(this.selfKeyStore).getPath(), this.selfKeyStorePw);
        transportParams.requireClientAuth(this.isRequireClientAuth);
        if (this.isRequireClientAuth)
            transportParams.setTrustStore(ThriftServerFactory.class.getClassLoader().getResource(this.trustKeyStore).getPath(), this.trustKeyStorePw);
        TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(this.serverPort, this.clientTimeout, InetAddress.getByName(this.serverHost), transportParams);
        server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(this.processor).protocolFactory(new TCompactProtocol.Factory()).executorService(tPool));
    } else {
        // Non security Server
        TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(new InetSocketAddress(this.serverHost, this.serverPort), this.clientTimeout);
        server = new THsHaServer(new THsHaServer.Args(serverTransport).processor(this.processor).protocolFactory(new TCompactProtocol.Factory()).transportFactory(new TFramedTransport.Factory(nonTLSServerMaxFrameSize)).executorService(tPool));
    }
    if (this.serverEventHandler != null) {
        server.setServerEventHandler(this.serverEventHandler);
    }
    return server;
}
Also used : TServer(org.apache.thrift.server.TServer) InetSocketAddress(java.net.InetSocketAddress) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TServerSocket(org.apache.thrift.transport.TServerSocket) THsHaServer(org.apache.thrift.server.THsHaServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TNonblockingServerSocket(org.apache.thrift.transport.TNonblockingServerSocket) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Example 19 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project HackTutorial by linrongbin16.

the class Server method main.

public static void main(String[] args) throws Exception {
    ServerSocket socket = new ServerSocket(30003);
    TServerSocket serverTransport = new TServerSocket(socket);
    Basic.BasicService.Processor processor = new Basic.BasicService.Processor(new BasicServiceImpl());
    TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
    System.out.println("Server Starting...");
    server.serve();
}
Also used : TServerSocket(org.apache.thrift.transport.TServerSocket) Args(org.apache.thrift.server.TServer.Args) TServer(org.apache.thrift.server.TServer) ServerSocket(java.net.ServerSocket) TServerSocket(org.apache.thrift.transport.TServerSocket) TSimpleServer(org.apache.thrift.server.TSimpleServer)

Example 20 with TServerSocket

use of org.apache.thrift.transport.TServerSocket in project providence by morimekta.

the class RPCThriftSocketTest method setUp.

@Before
public void setUp() throws Exception {
    Log.setLog(new NoLogging());
    rc = copyResourceTo("/pvdrc", temp.getRoot());
    copyResourceTo("/test.thrift", temp.getRoot());
    impl = Mockito.mock(MyService.Iface.class);
    TServerSocket transport = new TServerSocket(0);
    server = new TSimpleServer(new TServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory()).processor(new MyService.Processor<>(impl)));
    ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    Thread.sleep(1);
    port = transport.getServerSocket().getLocalPort();
    exitCode = 0;
    rpc = new RPC(console.tty()) {

        @Override
        protected void exit(int i) {
            exitCode = i;
        }
    };
}
Also used : NoLogging(net.morimekta.providence.tools.rpc.internal.NoLogging) TServerSocket(org.apache.thrift.transport.TServerSocket) MyService(net.morimekta.test.thrift.MyService) ExecutorService(java.util.concurrent.ExecutorService) TSimpleServer(org.apache.thrift.server.TSimpleServer) Before(org.junit.Before)

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