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.wso2.andes.thrift.MBThriftServer.java

License:Open Source License

/**
 * Start the thrift server/*from  w  w w. ja  v  a2 s .com*/
 *
 * @param hostName the hostname
 * @param port     thrift server port
 * @param taskName the name of the main server thread
 * @throws org.wso2.andes.kernel.AndesException
 *          throws in case of an starting error
 */
public void start(final String hostName, final int port, final String taskName) throws AndesException {
    /**
     * Stop node if 0.0.0.0 used as thrift server host in broker.xml
     */
    if ("0.0.0.0".equals(hostName)) {
        throw new AndesException("Invalid thrift server host 0.0.0.0");
    }
    try {
        TServerSocket socket = new TServerSocket(new InetSocketAddress(hostName, port));
        SlotManagementService.Processor<SlotManagementServiceImpl> processor = new SlotManagementService.Processor<SlotManagementServiceImpl>(
                slotManagementServerHandler);
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        server = new TThreadPoolServer(
                new TThreadPoolServer.Args(socket).processor(processor).inputProtocolFactory(protocolFactory)
                        .requestTimeoutUnit(TimeUnit.SECONDS).requestTimeout(THRIFT_SERVER_REQUEST_TIMEOUT));

        log.info("Starting the Message Broker Thrift server on host '" + hostName + "' on port '" + port
                + "'...");
        new Thread(new MBServerMainLoop(server), taskName).start();

    } catch (TTransportException e) {
        throw new AndesException("Cannot start Thrift server on port " + port + " on host " + hostName, e);
    }
}

From source file:org.wso2.carbon.apimgt.keymgt.internal.APIKeyMgtServiceComponent.java

License:Open Source License

private void startThriftService() throws Exception {
    try {//from   w ww  .  j  a v  a  2s  .  c o  m
        TSSLTransportFactory.TSSLTransportParameters transportParam = new TSSLTransportFactory.TSSLTransportParameters();

        //read the keystore and password used for ssl communication from config
        String keyStorePath = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location");
        String keyStorePassword = ServerConfiguration.getInstance()
                .getFirstProperty("Security.KeyStore.Password");

        String thriftPortString = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(APIConstants.API_KEY_MANGER_THRIFT_SERVER_PORT);

        if (thriftPortString == null) {
            thriftPortString = "10398";
            log.info("Setting default port for thrift key management service: " + "10398");
        }

        String thriftHostString = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(APIConstants.API_KEY_MANGER_THRIFT_SERVER_HOST);

        if (thriftHostString == null) {
            thriftHostString = NetworkUtils.getLocalHostname();
            log.info("Setting default carbon host for thrift key management service: " + thriftHostString);
        }

        String thriftClientTimeOut = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(APIConstants.API_KEY_MANGER_CONNECTION_TIMEOUT);
        if (thriftPortString == null || thriftClientTimeOut == null) {
            throw new APIKeyMgtException(
                    "Port and Connection timeout not provided to start thrift key mgt service.");
        }

        int receivePort = Integer.parseInt(thriftPortString);
        int clientTimeOut = Integer.parseInt(thriftClientTimeOut);
        //set it in parameters
        transportParam.setKeyStore(keyStorePath, keyStorePassword);

        TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(receivePort, clientTimeOut,
                getHostAddress(thriftHostString), transportParam);

        APIKeyValidationService.Processor processor = new APIKeyValidationService.Processor(
                new APIKeyValidationServiceImpl());

        //TODO: have to decide on the protocol.
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        //TServer server = new TThreadPoolServer(new TThreadPoolServer.Args())

        /*TServer server = new TThreadPoolServer(processor, serverTransport,
        new TCompactProtocol.Factory());*/
        Runnable serverThread = new ServerRunnable(server);
        executor.submit(serverThread);

        log.info("Started thrift key mgt service at port:" + receivePort);
    } catch (TTransportException e) {
        String transportErrorMsg = "Error in initializing thrift transport";
        log.error(transportErrorMsg, e);
        throw new Exception(transportErrorMsg);
    } catch (UnknownHostException e) {
        String hostErrorMsg = "Error in obtaining host name";
        log.error(hostErrorMsg, e);
        throw new Exception(hostErrorMsg);
    }
}

From source file:org.wso2.carbon.appmgt.keymgt.internal.AppMKeyMgtServiceComponent.java

License:Open Source License

private void startThriftService() throws Exception {
    try {//from   w w  w .  j av a2  s. co  m
        TSSLTransportFactory.TSSLTransportParameters transportParam = new TSSLTransportFactory.TSSLTransportParameters();

        //read the keystore and password used for ssl communication from config
        String keyStorePath = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location");
        String keyStorePassword = ServerConfiguration.getInstance()
                .getFirstProperty("Security.KeyStore.Password");

        String thriftPortString = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(AppMConstants.API_KEY_MANGER_THRIFT_SERVER_PORT);

        if (thriftPortString == null) {
            thriftPortString = "10398";
            log.info("Setting default port for thrift key management service: " + "10398");
        }

        String thriftHostString = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(AppMConstants.API_KEY_MANGER_THRIFT_SERVER_HOST);

        if (thriftHostString == null) {
            thriftHostString = NetworkUtils.getLocalHostname();
            log.info("Setting default carbon host for thrift key management service: " + thriftHostString);
        }

        String thriftClientTimeOut = APIKeyMgtDataHolder.getAmConfigService().getAPIManagerConfiguration()
                .getFirstProperty(AppMConstants.API_KEY_MANGER_CONNECTION_TIMEOUT);
        if (thriftPortString == null || thriftClientTimeOut == null) {
            throw new APIKeyMgtException(
                    "Port and Connection timeout not provided to start thrift key mgt service.");
        }

        int receivePort = Integer.parseInt(thriftPortString);
        int clientTimeOut = Integer.parseInt(thriftClientTimeOut);
        //set it in parameters
        transportParam.setKeyStore(keyStorePath, keyStorePassword);

        TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(receivePort, clientTimeOut,
                getHostAddress(thriftHostString), transportParam);

        APIKeyValidationService.Processor processor = new APIKeyValidationService.Processor(
                new APIKeyValidationServiceImpl());

        //TODO: have to decide on the protocol.
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        //TServer server = new TThreadPoolServer(new TThreadPoolServer.Args())

        /*TServer server = new TThreadPoolServer(processor, serverTransport,
        new TCompactProtocol.Factory());*/
        Runnable serverThread = new ServerRunnable(server);
        executor.submit(serverThread);

        log.info("Started thrift key mgt service at port:" + receivePort);
    } catch (TTransportException e) {
        String transportErrorMsg = "Error in initializing thrift transport";
        log.error(transportErrorMsg, e);
        throw new Exception(transportErrorMsg);
    } catch (UnknownHostException e) {
        String hostErrorMsg = "Error in obtaining host name";
        log.error(hostErrorMsg, e);
        throw new Exception(hostErrorMsg);
    }
}

From source file:org.wso2.carbon.cloud.gateway.transport.server.CGThriftServer.java

License:Apache License

/**
 * Start the thrift server/*from  ww w.j av a 2  s .  c  om*/
 *
 * @param hostName         the hostname
 * @param port             thrift server port
 * @param timeOut          the client timeout
 * @param keyStorePath     the path of the key store
 * @param keyStorePassword the password of the key store
 * @param trustStorePath   the path of the trust store
 * @param trustStorePassword the password of the trust store
 * @param taskName         the name of the main server thread
 * @throws AxisFault throws in case of an starting error
 */
public void start(final String hostName, final int port, final int timeOut, final String keyStorePath,
        final String keyStorePassword, final String trustStorePath, final String trustStorePassword,
        final String taskName) throws AxisFault {
    try {
        TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();

        params.setKeyStore(keyStorePath, keyStorePassword);
        params.setTrustStore(trustStorePath, trustStorePassword);

        TServerSocket socket = TSSLTransportFactory.getServerSocket(port, timeOut,
                InetAddress.getByName(hostName), params);

        CloudGatewayService.Processor<CGThriftServerHandler> processor = new CloudGatewayService.Processor<CGThriftServerHandler>(
                csgThriftServerHandler);
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        server = new TThreadPoolServer(
                new TThreadPoolServer.Args(socket).processor(processor).inputProtocolFactory(protocolFactory));

        log.info("Starting the Cloud Gateway Thrift server on host '" + hostName + "' on port '" + port
                + "'...");
        new Thread(new CGServerMainLoop(server), taskName).start();

    } catch (TTransportException e) {
        throw new AxisFault("TTransportException occurs", e);
    } catch (UnknownHostException e) {
        throw new AxisFault("Unknown host exception occurs", e);
    }
}

From source file:org.wso2.carbon.databridge.receiver.thrift.internal.ThriftDataReceiver.java

License:Open Source License

protected void startSecureEventTransmission(String hostName, int port, String keyStore, String keyStorePassword,
        DataBridgeReceiverService dataBridgeReceiverService) throws TransportException, UnknownHostException {
    TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
    params.setKeyStore(keyStore, keyStorePassword);

    TServerSocket serverTransport;//  ww w.  java2 s.  c om
    try {
        InetAddress inetAddress = InetAddress.getByName(hostName);
        serverTransport = TSSLTransportFactory.getServerSocket(port, DataBridgeConstants.CLIENT_TIMEOUT_MS,
                inetAddress, params);
        log.info("Thrift Server started at " + hostName);
    } catch (TTransportException e) {
        throw new TransportException("Thrift transport exception occurred ", e);
    }

    ThriftSecureEventTransmissionService.Processor<ThriftSecureEventTransmissionServiceImpl> processor = new ThriftSecureEventTransmissionService.Processor<ThriftSecureEventTransmissionServiceImpl>(
            new ThriftSecureEventTransmissionServiceImpl(dataBridgeReceiverService));
    authenticationServer = new TThreadPoolServer(
            new TThreadPoolServer.Args(serverTransport).processor(processor));
    Thread thread = new Thread(new ServerThread(authenticationServer));
    log.info("Thrift SSL port : " + port);
    thread.start();
}

From source file:org.wso2.carbon.databridge.receiver.thrift.internal.ThriftDataReceiver.java

License:Open Source License

protected void startEventTransmission(int port, DataBridgeReceiverService dataBridgeReceiverService)
        throws DataBridgeException {

    try {//from  w w  w .j a v a 2  s  . co m
        TServerSocket serverTransport = new TServerSocket(port);
        ThriftEventTransmissionService.Processor<ThriftEventTransmissionServiceImpl> processor = new ThriftEventTransmissionService.Processor<ThriftEventTransmissionServiceImpl>(
                new ThriftEventTransmissionServiceImpl(dataBridgeReceiverService));
        dataReceiverServer = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        Thread thread = new Thread(new ServerThread(dataReceiverServer));
        log.info("Thrift port : " + port);
        thread.start();
    } catch (TTransportException e) {
        log.info("Databridge Exception");
        throw new DataBridgeException("Cannot start Thrift server on port " + port, e);

    }

}

From source file:org.wso2.carbon.databridge.receiver.thrift.ThriftDataReceiver.java

License:Open Source License

protected void startEventTransmission(String hostName, int port,
        DataBridgeReceiverService dataBridgeReceiverService) throws DataBridgeException {
    try {//from   w ww.j a  v a 2  s. c  o m
        TServerSocket serverTransport = new TServerSocket(new InetSocketAddress(hostName, port));
        ThriftEventTransmissionService.Processor<ThriftEventTransmissionServiceImpl> processor = new ThriftEventTransmissionService.Processor<ThriftEventTransmissionServiceImpl>(
                new ThriftEventTransmissionServiceImpl(dataBridgeReceiverService));
        dataReceiverServer = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        Thread thread = new Thread(new ServerThread(dataReceiverServer));
        log.info("Thrift port : " + port);
        thread.start();
    } catch (TTransportException e) {
        throw new DataBridgeException("Cannot start Thrift server on port " + port + " on host " + hostName, e);
    }
}

From source file:org.wso2.carbon.event.processor.core.internal.storm.manager.StormManagerServer.java

License:Open Source License

public StormManagerServer(String hostName, int port) {

    try {/*from   ww  w.j a v a2 s  .co m*/
        stormManagerService = new StormManagerServiceImpl(hostName + ":" + port);
        TServerSocket serverTransport = new TServerSocket(new InetSocketAddress(hostName, port));
        StormManagerService.Processor<StormManagerServiceImpl> processor = new StormManagerService.Processor<StormManagerServiceImpl>(
                stormManagerService);
        stormManagerServer = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        Thread thread = new Thread(new ServerThread(stormManagerServer));
        thread.start();

        log.info("CEP Storm Management Thrift Server started on " + hostName + ":" + port);
        executorService = new ScheduledThreadPoolExecutor(3);
    } catch (TTransportException e) {
        log.error("Cannot start Storm Manager Server on " + hostName + ":" + port, e);
    }
}

From source file:org.wso2.carbon.event.processor.manager.core.internal.ManagementServer.java

License:Open Source License

private static void start(HostAndPort hostAndPort) throws Exception {
    try {//from   w  w w  . j a va2  s.  c o m
        TServerSocket serverTransport = new TServerSocket(
                new InetSocketAddress(hostAndPort.getHostName(), hostAndPort.getPort()));
        ManagementService.Processor<ManagementServiceImpl> processor = new ManagementService.Processor<ManagementServiceImpl>(
                new ManagementServiceImpl());
        TThreadPoolServer dataReceiverServer = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        Thread thread = new Thread(new ServerThread(dataReceiverServer));
        log.info("CEP Management Thrift Server started on " + hostAndPort.getHostName() + ":"
                + hostAndPort.getPort());
        thread.start();
    } catch (TTransportException e) {
        throw new Exception("Cannot start CEP Management Thrift server on port " + hostAndPort.getPort()
                + " on host " + hostAndPort.getHostName(), e);
    }
}

From source file:org.wso2.carbon.event.processor.manager.core.internal.SnapshotServer.java

License:Open Source License

private static void start(HostAndPort hostAndPort) throws Exception {
    try {/* w  w  w.  j  a v a  2 s.  c o  m*/
        TServerSocket serverTransport = new TServerSocket(
                new InetSocketAddress(hostAndPort.getHostName(), hostAndPort.getPort()));
        ManagementService.Processor<ManagementServiceImpl> processor = new ManagementService.Processor<ManagementServiceImpl>(
                new ManagementServiceImpl());
        dataReceiverServer = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        Thread thread = new Thread(new ServerThread(dataReceiverServer));
        log.info("CEP Management Thrift Server started on " + hostAndPort.getHostName() + ":"
                + hostAndPort.getPort());
        thread.start();
    } catch (TTransportException e) {
        throw new Exception("Cannot start CEP Management Thrift server on port " + hostAndPort.getPort()
                + " on host " + hostAndPort.getHostName(), e);
    }
}