Example usage for org.apache.thrift.server TThreadPoolServer TThreadPoolServer

List of usage examples for org.apache.thrift.server TThreadPoolServer TThreadPoolServer

Introduction

In this page you can find the example usage for org.apache.thrift.server TThreadPoolServer TThreadPoolServer.

Prototype

public TThreadPoolServer(Args args) 

Source Link

Usage

From source file:org.apache.airavata.registry.api.service.RegistryAPIServer.java

License:Apache License

public void StartRegistryServer(
        RegistryService.Processor<RegistryServerHandler> orchestratorServerHandlerProcessor) throws Exception {
    // creating experiment catalog db
    logger.info("Initializing ExperimentCatalog DB");
    ExperimentCatalogInitUtil.initializeDB();

    // creating app catalog db
    logger.info("Initializing AppCatalog DB");
    AppCatalogInitUtil.initializeDB();// w w  w.  ja v a 2s.  c o  m

    // creating workflow catalog db
    logger.info("Initializing WorkflowCatalog DB");
    WorkflowCatalogInitUtil.initializeDB();

    // creating replica catalog db
    logger.info("Initializing ReplicaCatalog DB");
    ReplicaCatalogInitUtil.initializeDB();

    final int serverPort = Integer.parseInt(ServerSettings.getSetting(Constants.REGISTRY_SERVER_PORT, "8960"));
    try {
        final String serverHost = ServerSettings.getSetting(Constants.REGISTRY_SERVER_HOST, null);
        TServerTransport serverTransport;
        if (serverHost == null) {
            serverTransport = new TServerSocket(serverPort);
        } else {
            InetSocketAddress inetSocketAddress = new InetSocketAddress(serverHost, serverPort);
            serverTransport = new TServerSocket(inetSocketAddress);
        }

        // thrift server start
        TThreadPoolServer.Args options = new TThreadPoolServer.Args(serverTransport);
        options.minWorkerThreads = Integer
                .parseInt(ServerSettings.getSetting(Constants.REGISTRY_SERVER_MIN_THREADS, "30"));
        server = new TThreadPoolServer(options.processor(orchestratorServerHandlerProcessor));
        new Thread() {
            public void run() {
                server.serve();
                setStatus(ServerStatus.STARTING);
                logger.info("Starting Registry 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 Registry Server on Port " + serverPort + " ...");

                    // start db event handlers
                    if (!startDatabaseEventHandlers()) {
                        logger.error("Stopping Registry Server as DB event handlers failed to start!");
                        server.stop();
                    }
                }
            }
        }.start();
    } catch (TTransportException e) {
        logger.error(e.getMessage());
        setStatus(ServerStatus.FAILED);
        logger.error("Failed to start Registry server on port " + serverPort + " ...");
    }
}

From source file:org.apache.airavata.service.profile.server.ProfileServiceServer.java

License:Apache License

public void start() throws Exception {

    try {/*from   w ww  .  j av  a2s  .c om*/
        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);
    }
}

From source file:org.apache.airavata.sharing.registry.server.SharingRegistryServer.java

License:Apache License

@Override
public void start() throws Exception {
    try {// w  ww . j  ava2 s .  c o m
        setStatus(IServer.ServerStatus.STARTING);

        final int serverPort = Integer.parseInt(ServerSettings.getSetting(SHARING_REG_SERVER_PORT));
        final String serverHost = ServerSettings.getSetting(SHARING_REG_SERVER_HOST);
        SharingRegistryService.Processor processor = new SharingRegistryService.Processor(
                new SharingRegistryServerHandler());

        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(processor));

        new Thread() {
            public void run() {
                server.serve();
                setStatus(IServer.ServerStatus.STOPPED);
                logger.info("Sharing Registry Server Stopped.");
            }
        }.start();
        new Thread() {
            public void run() {
                while (!server.isServing()) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        break;
                    }
                }
                if (server.isServing()) {

                    try {

                        logger.info("Register sharing service with DB Event publishers");
                        SharingServiceDBEventMessagingFactory
                                .registerSharingServiceWithPublishers(Constants.PUBLISHERS);

                        logger.info("Start sharing service DB Event subscriber");
                        SharingServiceDBEventMessagingFactory.getDBEventSubscriber();

                    } catch (AiravataException | SharingRegistryException e) {
                        logger.error("Error starting sharing service. Error setting up DB event services.");
                        server.stop();
                    }

                    setStatus(IServer.ServerStatus.STARTED);
                    logger.info("Starting Sharing Registry Server on Port " + serverPort);
                    logger.info("Listening to Sharing Registry server clients ....");
                }
            }
        }.start();

    } catch (TTransportException e) {
        setStatus(IServer.ServerStatus.FAILED);
        throw new Exception("Error while starting the Sharing Registry service", e);
    }
}

From source file:org.apache.airavata.user.profile.server.UserProfileServer.java

License:Apache License

public void start() throws Exception {

    try {//from w  w  w  .  j  a  v  a2  s.com
        setStatus(ServerStatus.STARTING);
        final int serverPort = Integer.parseInt(ServerSettings.getUserProfileServerPort());
        final String serverHost = ServerSettings.getUserProfileServerHost();
        UserProfileService.Processor processor = new UserProfileService.Processor(
                new UserProfileServiceHandler());

        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(processor));

        new Thread() {
            public void run() {
                server.serve();
                setStatus(ServerStatus.STOPPED);
                logger.info("User Profile 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 User Profile Server on Port " + serverPort);
                    logger.info("Listening to User Profile server clients ....");
                }
            }
        }.start();
    } catch (TTransportException e) {
        setStatus(ServerStatus.FAILED);
        throw new Exception("Error while starting the User Profile service", e);
    }
}

From source file:org.apache.dubbo.rpc.protocol.thrift.AbstractTest.java

License:Apache License

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/*  w  w w  .  j  av  a2 s  .c  o m*/
        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());

}

From source file:org.apache.flume.source.thriftLegacy.ThriftLegacySource.java

License:Apache License

@SuppressWarnings("deprecation")
@Override/*from ww w .j a v  a  2  s. c  om*/
public void start() {
    try {
        InetSocketAddress bindAddr = new InetSocketAddress(host, port);
        serverTransport = new TServerSocket(bindAddr);
        ThriftFlumeEventServer.Processor processor = new ThriftFlumeEventServer.Processor(
                new ThriftFlumeEventServerImpl());
        server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
    } catch (TTransportException e) {
        throw new FlumeException("Failed starting source", e);
    }
    ThriftHandler thriftHandler = new ThriftHandler(server);
    thriftHandlerThread = new Thread(thriftHandler);
    thriftHandlerThread.start();
    super.start();
}

From source file:org.apache.flume.source.ThriftSource.java

License:Apache License

private TServer getTThreadPoolServer() {
    TServerTransport serverTransport;/*from   w ww  . j a v a2 s  . c o  m*/
    if (enableSsl) {
        serverTransport = getSSLServerTransport();
    } else {
        serverTransport = getTServerTransport();
    }
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.maxWorkerThreads(maxThreads);
    populateServerParams(serverArgs);
    return new TThreadPoolServer(serverArgs);
}

From source file:org.apache.hadoop.hbase.thrift2.ThriftServer.java

License:Apache License

private static TServer getTThreadPoolServer(TProtocolFactory protocolFactory, TProcessor processor,
        TTransportFactory transportFactory, InetSocketAddress inetSocketAddress) throws TTransportException {
    TServerTransport serverTransport = new TServerSocket(inetSocketAddress);
    log.info("starting HBase ThreadPool Thrift server on " + inetSocketAddress.toString());
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor);/*w w w . j av a  2  s .  c  o  m*/
    serverArgs.transportFactory(transportFactory);
    serverArgs.protocolFactory(protocolFactory);
    return new TThreadPoolServer(serverArgs);
}

From source file:org.apache.hadoop.hdfs.fsshellservice.FsShellServiceImpl.java

License:Apache License

private void initThriftServer(int port, int maxQueue) {
    // Setup the Thrift server
    LOG.info("Setting up Thrift server listening port " + port);
    TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
    TTransportFactory transportFactory = new TFramedTransport.Factory();
    TServerTransport serverTransport;/*from   w w w . ja  v  a2  s. c o m*/
    FsShellService.Processor<FsShellService.Iface> processor = new FsShellService.Processor<FsShellService.Iface>(
            this);

    ServerSocket serverSocket_;
    try {
        // Make server socket. Use loop-back address to only serve requests
        // from local clients, in order to prevent ambiguity for commands
        // of copyFromLocal() and copyToLocal()
        serverSocket_ = new ServerSocket(port, maxQueue, InetAddress.getAllByName(null)[0]);
        // Prevent 2MSL delay problem on server restarts
        serverSocket_.setReuseAddress(true);
    } catch (IOException ioe) {
        LOG.error("Could not create ServerSocket on local address ", ioe);
        return;
    }
    serverTransport = new TServerSocket(serverSocket_, clientTimeout);
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processor(processor).transportFactory(transportFactory).protocolFactory(protocolFactory);
    tserver = new TThreadPoolServer(serverArgs);
}

From source file:org.apache.hadoop.hive.metastore.HiveMetaStore.java

License:Apache License

/**
 * Start Metastore based on a passed {@link HadoopThriftAuthBridge}
 *
 * @param port/*  ww w .  j av  a2 s.  c  o  m*/
 * @param bridge
 * @param conf
 *          configuration overrides
 * @throws Throwable
 */
public static void startMetaStore(int port, HadoopThriftAuthBridge bridge, HiveConf conf) throws Throwable {
    try {

        // Server will create new threads up to max as necessary. After an idle
        // period, it will destory threads to keep the number of threads in the
        // pool to min.
        int minWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMINTHREADS);
        int maxWorkerThreads = conf.getIntVar(HiveConf.ConfVars.METASTORESERVERMAXTHREADS);
        boolean tcpKeepAlive = conf.getBoolVar(HiveConf.ConfVars.METASTORE_TCP_KEEP_ALIVE);
        boolean useFramedTransport = conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_FRAMED_TRANSPORT);
        useSasl = conf.getBoolVar(HiveConf.ConfVars.METASTORE_USE_THRIFT_SASL);

        TServerTransport serverTransport = tcpKeepAlive ? new TServerSocketKeepAlive(port)
                : new TServerSocket(port);

        TProcessor processor;
        TTransportFactory transFactory;
        if (useSasl) {
            // we are in secure mode.
            if (useFramedTransport) {
                throw new HiveMetaException("Framed transport is not supported with SASL enabled.");
            }
            saslServer = bridge.createServer(conf.getVar(HiveConf.ConfVars.METASTORE_KERBEROS_KEYTAB_FILE),
                    conf.getVar(HiveConf.ConfVars.METASTORE_KERBEROS_PRINCIPAL));
            // start delegation token manager
            saslServer.startDelegationTokenSecretManager(conf);
            transFactory = saslServer.createTransportFactory(MetaStoreUtils.getMetaStoreSaslProperties(conf));
            processor = saslServer.wrapProcessor(new ThriftHiveMetastore.Processor<IHMSHandler>(
                    newHMSHandler("new db based metaserver", conf)));
            LOG.info("Starting DB backed MetaStore Server in Secure Mode");
        } else {
            // we are in unsecure mode.
            IHMSHandler handler = newHMSHandler("new db based metaserver", conf);

            if (conf.getBoolVar(ConfVars.METASTORE_EXECUTE_SET_UGI)) {
                transFactory = useFramedTransport
                        ? new ChainedTTransportFactory(new TFramedTransport.Factory(),
                                new TUGIContainingTransport.Factory())
                        : new TUGIContainingTransport.Factory();

                processor = new TUGIBasedProcessor<IHMSHandler>(handler);
                LOG.info("Starting DB backed MetaStore Server with SetUGI enabled");
            } else {
                transFactory = useFramedTransport ? new TFramedTransport.Factory() : new TTransportFactory();
                processor = new TSetIpAddressProcessor<IHMSHandler>(handler);
                LOG.info("Starting DB backed MetaStore Server");
            }
        }

        TThreadPoolServer.Args args = new TThreadPoolServer.Args(serverTransport).processor(processor)
                .transportFactory(transFactory).protocolFactory(new TBinaryProtocol.Factory())
                .minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads);

        TServer tServer = new TThreadPoolServer(args);
        HMSHandler.LOG.info("Started the new metaserver on port [" + port + "]...");
        HMSHandler.LOG.info("Options.minWorkerThreads = " + minWorkerThreads);
        HMSHandler.LOG.info("Options.maxWorkerThreads = " + maxWorkerThreads);
        HMSHandler.LOG.info("TCP keepalive = " + tcpKeepAlive);
        tServer.serve();
    } catch (Throwable x) {
        x.printStackTrace();
        HMSHandler.LOG.error(StringUtils.stringifyException(x));
        throw x;
    }
}