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.carbon.identity.entitlement.internal.EntitlementServiceComponent.java

License:Open Source License

private void startThriftEntitlementService() throws Exception {
    try {//from  ww  w .  j ava  2 s . c  o  m
        //read identity.xml
        IdentityUtil.populateProperties();
        //if thrift based EntitlementService is enabled.
        String thriftEnabled = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_ENABLE_THRIFT_SERVICE);

        if (thriftEnabled != null && Boolean.parseBoolean(thriftEnabled)) {

            TSSLTransportFactory.TSSLTransportParameters transportParam = new TSSLTransportFactory.TSSLTransportParameters();

            //read the keystore and password used for ssl communication from config
            String keystorePath = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_LOCATION);
            String keystorePassword = IdentityUtil.getProperty(ThriftConfigConstants.PARAM_KEYSTORE_PASSWORD);

            //set it in parameters
            transportParam.setKeyStore(keystorePath, keystorePassword);
            //int receivePort = 10395;
            int receivePort = readThriftReceivePort();
            //int clientTimeOut = 10000;
            int clientTimeOut = Integer
                    .parseInt(IdentityUtil.getProperty(ThriftConfigConstants.PARAM_CLIENT_TIMEOUT));
            //String ifAddress = "localhost";
            TServerSocket serverTransport = TSSLTransportFactory.getServerSocket(receivePort, clientTimeOut,
                    getHostAddress(readThriftHostName()), transportParam);

            EntitlementService.Processor processor = new EntitlementService.Processor(
                    new ThriftEntitlementServiceImpl());

            //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);

            if (log.isDebugEnabled()) {
                log.debug("Started thrift entitlement 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.identity.thrift.authentication.TCPThriftAuthenticationService.java

License:Open Source License

public void start() throws TTransportException, UnknownHostException {
    InetAddress inetAddress = InetAddress.getByName(hostName);

    TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
    params.setKeyStore(keyStore, keyStorePassword);

    TServerSocket serverTransport;//from  w  ww.  jav  a2 s . c  om

    serverTransport = TSSLTransportFactory.getServerSocket(port, clientTimeout, inetAddress, params);

    AuthenticatorService.Processor<AuthenticatorServiceImpl> processor = new AuthenticatorService.Processor<AuthenticatorServiceImpl>(
            new AuthenticatorServiceImpl(thriftAuthenticatorService));
    authenticationServer = new TThreadPoolServer(
            new TThreadPoolServer.Args(serverTransport).processor(processor));
    Thread thread = new Thread(new ServerRunnable(authenticationServer));
    if (log.isDebugEnabled()) {
        log.debug("Thrift Authentication Service started at ssl://" + hostName + ":" + port);
    }
    thread.start();
}

From source file:pat_irc.IRCServer.java

public static void run_server(IRCService.Processor processor) {
    try {/*from   www.  j a v  a 2 s.c  om*/
        TServerTransport serverTransport = new TServerSocket(9090);
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Starting IRC server...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:puma.central.pdp.CentralPUMAPDP.java

License:Apache License

public static void main(String[] args) {
    // initialize log4j
    BasicConfigurator.configure();//from w w  w.j av  a  2  s . c  o  m

    CommandLineParser parser = new BasicParser();
    Options options = new Options();
    options.addOption("ph", "policy-home", true,
            "The folder where to find the policy file given with the given policy id. "
                    + "For default operation, this folder should contain the central PUMA policy (called "
                    + CENTRAL_PUMA_POLICY_FILENAME + ")");
    options.addOption("pid", "policy-id", true,
            "The id of the policy to be evaluated on decision requests. Default value: " + GLOBAL_PUMA_POLICY_ID
                    + ")");
    options.addOption("s", "log-disabled", true, "Verbose mode (true/false)");
    String policyHome = "";
    String policyId = "";

    // read command line
    try {
        CommandLine line = parser.parse(options, args);
        if (line.hasOption("help")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Simple PDP Test", options);
            return;
        }
        if (line.hasOption("policy-home")) {
            policyHome = line.getOptionValue("policy-home");
        } else {
            logger.log(Level.WARNING, "Incorrect arguments given.");
            return;
        }
        if (line.hasOption("log-disabled") && Boolean.parseBoolean(line.getOptionValue("log-disabled"))) {
            logger.log(Level.INFO, "Now switching to silent mode");
            LogManager.getLogManager().getLogger("").setLevel(Level.WARNING);
            //LogManager.getLogManager().reset();
        }
        if (line.hasOption("policy-id")) {
            policyId = line.getOptionValue("policy-id");
        } else {
            logger.log(Level.INFO, "Using default policy id: " + GLOBAL_PUMA_POLICY_ID);
            policyId = GLOBAL_PUMA_POLICY_ID;
        }
    } catch (ParseException e) {
        logger.log(Level.WARNING, "Incorrect arguments given.", e);
        return;
    }

    //
    // STARTUP THE RMI SERVER
    //      
    // if (System.getSecurityManager() == null) {
    // System.setSecurityManager(new SecurityManager());
    // }
    final CentralPUMAPDP pdp;
    try {
        pdp = new CentralPUMAPDP(policyHome, policyId);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "FAILED to set up the CentralPUMAPDP. Quitting.", e);
        return;
    }

    try {
        Registry registry;
        try {
            registry = LocateRegistry.createRegistry(RMI_REGISITRY_PORT);
            logger.info("Created new RMI registry");
        } catch (RemoteException e) {
            // MDC: I hope this means the registry already existed.
            registry = LocateRegistry.getRegistry(RMI_REGISITRY_PORT);
            logger.info("Reusing existing RMI registry");
        }
        CentralPUMAPDPRemote stub = (CentralPUMAPDPRemote) UnicastRemoteObject.exportObject(pdp, 0);
        registry.bind(CENTRAL_PUMA_PDP_RMI_NAME, stub);
        logger.info(
                "Central PUMA PDP up and running (available using RMI with name \"central-puma-pdp\" on RMI registry port "
                        + RMI_REGISITRY_PORT + ")");
        Thread.sleep(100); // MDC: vroeger eindigde de Thread om n of andere reden, dit lijkt te werken...
    } catch (Exception e) {
        logger.log(Level.SEVERE, "FAILED to set up PDP as RMI server", e);
    }

    //
    // STARTUP THE THRIFT PEP SERVER
    //
    //logger.log(Level.INFO, "Not setting up the Thrift server");

    // set up server
    //      PEPServer handler = new PEPServer(new CentralPUMAPEP(pdp));
    //      RemotePEPService.Processor<PEPServer> processor = new RemotePEPService.Processor<PEPServer>(handler);
    //      TServerTransport serverTransport;
    //      try {
    //         serverTransport = new TServerSocket(THRIFT_PEP_PORT);
    //      } catch (TTransportException e) {
    //         e.printStackTrace();
    //         return;
    //      }
    //      TServer server = new TSimpleServer(new TServer.Args(serverTransport).processor(processor));
    //      System.out.println("Setting up the Thrift PEP server on port " + THRIFT_PEP_PORT);
    //      server.serve();
    //
    // STARTUP THE THRIFT PEP SERVER
    //
    //logger.log(Level.INFO, "Not setting up the Thrift server");

    // set up server
    // do this in another thread not to block the main thread
    new Thread(new Runnable() {
        @Override
        public void run() {
            RemotePDPService.Processor<CentralPUMAPDP> pdpProcessor = new RemotePDPService.Processor<CentralPUMAPDP>(
                    pdp);
            TServerTransport pdpServerTransport;
            try {
                pdpServerTransport = new TServerSocket(THRIFT_PDP_PORT);
            } catch (TTransportException e) {
                e.printStackTrace();
                return;
            }
            TServer pdpServer = new TThreadPoolServer(
                    new TThreadPoolServer.Args(pdpServerTransport).processor(pdpProcessor));
            logger.info("Setting up the Thrift PDP server on port " + THRIFT_PDP_PORT);
            pdpServer.serve();
        }
    }).start();
}

From source file:qa.qcri.nadeef.service.NadeefService.java

License:Open Source License

@Override
protected void startUp() throws Exception {
    Bootstrap.start();/*  w  w w . j av a2 s .c  om*/
    int port = NadeefConfiguration.getServerPort();

    NadeefServiceHandler handler = new NadeefServiceHandler();
    TNadeefService.Processor processor = new TNadeefService.Processor(handler);
    TServerTransport serverTransport = new TServerSocket(port);
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
    tracer.info("Starting NADEEF server @ " + port);
    server.serve();
}

From source file:qa.qcri.qnoise.external.QNoiseThriftHandler.java

License:MIT License

public static void main(String[] args) {
    try {//from  w ww.  j  a  v  a2 s.co  m
        QNoiseThriftHandler handler = new QNoiseThriftHandler();
        TQnoise.Processor processor = new TQnoise.Processor(handler);
        TServerTransport serverTransport = null;
        serverTransport = new TServerSocket(port);
        server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("Let's make some noises...");
        server.serve();
    } catch (TTransportException e) {
        e.printStackTrace();
    }
}

From source file:scribe_server.Util.java

public static TServer getServer(String host, int port, Scribe.Iface handler) throws TTransportException {
    System.out.println("Setting up...");
    InetSocketAddress bindAddr = new InetSocketAddress(host, port);
    scribe.thrift.Scribe.Processor processor = new scribe.thrift.Scribe.Processor(handler);
    TServerTransport transport = new TServerSocket(bindAddr);
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(transport);
    serverArgs.processor(processor);/*from  w  ww .j av a2s  .com*/
    //serverArgs.minWorkerThreads(5);
    serverArgs.maxWorkerThreads(8);
    serverArgs.transportFactory(new TFramedTransport.Factory());
    serverArgs.protocolFactory(new TBinaryProtocol.Factory(false, false));
    return new TThreadPoolServer(serverArgs);
}

From source file:Server.Implementations.ThreadPoolServer.java

public ThreadPoolServer(int port) {
    super(port);// w w  w.j a v a  2  s. c o m
    server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
}

From source file:server.IrcServer.java

public static void handle(ChatService.Processor processor) {
    try {//from   w ww . j ava 2  s .  co m
        TServerTransport serverTransport = new TServerSocket(9090);
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Server.ServerGraph.java

public static void simple(Graph.Processor processor) {
    try {/*from w w  w .  j  av  a 2  s.  c o m*/
        TServerTransport serverTransport = new TServerSocket(9090);
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("funcionou");
        System.out.println("Starting the simple server...");
        server.serve();
    } catch (Exception e) {
    }
}