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:servidor.Servidor.java

/**
 * @param args the command line arguments
 */// w ww.j a  va 2s . co  m
public static void main(String[] args) {
    // TODO code application logic here
    try {
        // TODO code application logic here
        TServerSocket serverTransport = new TServerSocket(8585);
        servicioPartioningMemory.Processor processor = new servicioPartioningMemory.Processor(new Algorithm());
        TServer server = new TThreadPoolServer(
                new TThreadPoolServer.Args(serverTransport).processor(processor));
        System.out.println("iniciando servidor en el puerto 8585");
        server.serve();

    } catch (TTransportException ex) {
        ex.printStackTrace();
    }
}

From source file:simpleircthrift.Server.Server.java

public static void main(String[] args) throws Exception {
    BasicConfigurator.configure();/*from   w ww.j av a 2  s .co  m*/

    final MessageDistributor messageDistributor = new MessageDistributor();
    new Thread(messageDistributor).start();
    TProcessorFactory processFactory = new TProcessorFactory(null) {
        @Override
        public TProcessor getProcessor(TTransport trans) {
            messageDistributor.addClient(new MessageServiceClient(trans, MessageDistributor.MaxClientNumber));
            return new MessageService.Processor(messageDistributor);
        }
    };
    Scanner sc = new Scanner(System.in);
    System.out.print("Input port: ");
    int port = sc.nextInt();
    TServerTransport serverTransport = new TServerSocket(port);
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport);
    serverArgs.processorFactory(processFactory);
    TServer server = new TThreadPoolServer(serverArgs);
    MyLog.info("Server started");
    server.serve();
}

From source file:sinchana.IOHandler.java

License:Open Source License

synchronized void startServer() throws TTransportException, InterruptedException {
    if (tServer == null || !tServer.isServing()) {
        Thread thread = new Thread(new Runnable() {

            @Override/* ww w . j av  a2  s  . c o m*/
            public void run() {
                try {
                    DHTServer.Processor processor = new DHTServer.Processor(new ThriftServerImpl(server));
                    int localPortId = Integer.parseInt(thisNode.getAddress().split(":")[1]);
                    TServerTransport serverTransport = new TServerSocket(localPortId);
                    tServer = new TThreadPoolServer(
                            new TThreadPoolServer.Args(serverTransport).processor(processor));
                    Logger.log(thisNode, Logger.LogLevel.LEVEL_INFO, Logger.LogClass.CLASS_THRIFT_SERVER, 1,
                            "Starting the server on port " + localPortId);
                    tServer.serve();
                    Logger.log(thisNode, Logger.LogLevel.LEVEL_INFO, Logger.LogClass.CLASS_THRIFT_SERVER, 1,
                            "Server is shutting down...");
                } catch (TTransportException ex) {
                    tTransportException = ex;
                }
            }
        });
        thread.start();
        while (tTransportException == null && (tServer == null || !tServer.isServing())) {
            Thread.sleep(100);
        }
        if (tTransportException != null) {
            throw tTransportException;
        }
    }
    running = true;
    for (int i = 0; i < SinchanaDHT.NUMBER_OF_OUTPUT_MESSAGE_QUEUE_THREADS; i++) {
        new Thread(outputMessageQueueProcessor).start();
    }
}

From source file:tachyon.master.TachyonMaster.java

License:Apache License

private void setup() throws IOException, TTransportException {
    login();//from   www  . j  ava2s .  c  o  m
    if (mZookeeperMode) {
        mEditLogProcessor.stop();
    }
    mMasterInfo.init();

    mWebServer = new UIWebServer("Tachyon Master Server",
            new InetSocketAddress(NetworkUtils.getFqdnHost(mMasterAddress), mWebPort), mMasterInfo,
            mTachyonConf);

    mMasterServiceHandler = new MasterServiceHandler(mMasterInfo);
    MasterService.Processor<MasterServiceHandler> masterServiceProcessor = new MasterService.Processor<MasterServiceHandler>(
            mMasterServiceHandler);

    mMasterServiceServer = new TThreadPoolServer(new TThreadPoolServer.Args(mServerTServerSocket)
            .maxWorkerThreads(mMaxWorkerThreads).minWorkerThreads(mMinWorkerThreads)
            .processor(masterServiceProcessor).transportFactory(new TFramedTransport.Factory())
            .protocolFactory(new TBinaryProtocol.Factory(true, true)));

    mIsStarted = true;
}

From source file:tachyon.security.authentication.AuthenticationUtilsTest.java

License:Apache License

private void startServerThread() throws Exception {
    // create args and use them to build a Thrift TServer
    TTransportFactory tTransportFactory = AuthenticationUtils.getServerTransportFactory(mTachyonConf);

    mServer = new TThreadPoolServer(new TThreadPoolServer.Args(mServerTSocket).maxWorkerThreads(2)
            .minWorkerThreads(1).processor(null).transportFactory(tTransportFactory)
            .protocolFactory(new TBinaryProtocol.Factory(true, true)));

    // start the server in a new thread
    Thread serverThread = new Thread(new Runnable() {
        @Override//w w w  .j  a va2 s .  c o m
        public void run() {
            mServer.serve();
        }
    });

    serverThread.start();

    // ensure server is running, and break if it does not start serving in 2 seconds.
    int count = 40;
    while (!mServer.isServing() && serverThread.isAlive()) {
        if (count <= 0) {
            throw new RuntimeException("TThreadPoolServer does not start serving");
        }
        Thread.sleep(50);
        count--;
    }
}

From source file:tachyon.worker.block.BlockWorker.java

License:Apache License

/**
 * Helper method to create a {@link org.apache.thrift.server.TThreadPoolServer} for handling
 * incoming RPC requests./*w w w. j  a  va  2  s . c o m*/
 *
 * @return a thrift server
 */
private TThreadPoolServer createThriftServer() {
    int minWorkerThreads = mTachyonConf.getInt(Constants.WORKER_MIN_WORKER_THREADS);
    int maxWorkerThreads = mTachyonConf.getInt(Constants.WORKER_MAX_WORKER_THREADS);
    WorkerService.Processor<BlockServiceHandler> processor = new WorkerService.Processor<BlockServiceHandler>(
            mServiceHandler);
    return new TThreadPoolServer(new TThreadPoolServer.Args(mThriftServerSocket)
            .minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads).processor(processor)
            .transportFactory(new TFramedTransport.Factory())
            .protocolFactory(new TBinaryProtocol.Factory(true, true)));
}

From source file:tachyon.worker.TachyonWorker.java

License:Apache License

/**
 * @param masterAddress The TachyonMaster's address.
 * @param workerAddress This TachyonWorker's address.
 * @param dataPort This TachyonWorker's data server's port
 * @param minWorkerThreads The min number of worker threads used in TThreadPoolServer
 * @param maxWorkerThreads The max number of worker threads used in TThreadPoolServer
 * @param tachyonConf The {@link TachyonConf} instance for configuration properties
 */// ww  w  .  j a  v  a 2  s .  co m
private TachyonWorker(InetSocketAddress masterAddress, InetSocketAddress workerAddress, int dataPort,
        int minWorkerThreads, int maxWorkerThreads, TachyonConf tachyonConf) {
    TachyonConf.assertValidPort(masterAddress, tachyonConf);
    TachyonConf.assertValidPort(workerAddress, tachyonConf);
    TachyonConf.assertValidPort(dataPort, tachyonConf);

    mTachyonConf = tachyonConf;

    mMasterAddress = masterAddress;

    mWorkerStorage = new WorkerStorage(mMasterAddress, mExecutorService, mTachyonConf);

    mWorkerServiceHandler = new WorkerServiceHandler(mWorkerStorage);

    // Extract the port from the generated socket.
    // When running tests, its great to use port '0' so the system will figure out what port to use
    // (any random free port).
    // In a production or any real deployment setup, port '0' should not be used as it will make
    // deployment more complicated.
    InetSocketAddress dataAddress = new InetSocketAddress(workerAddress.getHostName(), dataPort);
    BlocksLocker blockLocker = new BlocksLocker(mWorkerStorage, Users.DATASERVER_USER_ID);
    mDataServer = DataServer.Factory.createDataServer(dataAddress, blockLocker, mTachyonConf);
    mDataPort = mDataServer.getPort();

    mHeartbeatThread = new Thread(this);
    try {
        LOG.info("Tachyon Worker version " + Version.VERSION + " tries to start @ " + workerAddress);
        WorkerService.Processor<WorkerServiceHandler> processor = new WorkerService.Processor<WorkerServiceHandler>(
                mWorkerServiceHandler);

        mServerTServerSocket = new TServerSocket(workerAddress);
        mPort = NetworkUtils.getPort(mServerTServerSocket);

        mServer = new TThreadPoolServer(new TThreadPoolServer.Args(mServerTServerSocket)
                .minWorkerThreads(minWorkerThreads).maxWorkerThreads(maxWorkerThreads).processor(processor)
                .transportFactory(new TFramedTransport.Factory())
                .protocolFactory(new TBinaryProtocol.Factory(true, true)));
    } catch (TTransportException e) {
        LOG.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
    mWorkerAddress = new NetAddress(workerAddress.getAddress().getCanonicalHostName(), mPort, mDataPort);
    mWorkerStorage.initialize(mWorkerAddress);
}

From source file:tech.aroma.application.service.server.TcpServer.java

License:Apache License

public static void main(String[] args) throws TTransportException, SocketException {
    Injector injector = Guice.createInjector(new AromaServicesProvider(),
            new ModuleApplicationServiceOperations(), new ModuleApplicationService(),
            new ModuleCassandraDataRepositories(), new ModuleCassandraDevCluster());

    ApplicationService.Iface applicationService = injector.getInstance(ApplicationService.Iface.class);
    ApplicationService.Processor processor = new ApplicationService.Processor<>(applicationService);

    TServerSocket socket = new TServerSocket(PORT);
    socket.getServerSocket().setSoTimeout((int) SECONDS.toMillis(30));

    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(socket)
            .protocolFactory(new TBinaryProtocol.Factory()).processor(processor).requestTimeout(60)
            .requestTimeoutUnit(SECONDS).minWorkerThreads(5).maxWorkerThreads(100);

    LOG.info("Starting Application Service at port {}", PORT);

    TThreadPoolServer server = new TThreadPoolServer(serverArgs);
    server.serve();//ww  w . j a  va 2s . co m
    server.stop();
}

From source file:tech.aroma.authentication.service.server.TcpServer.java

License:Apache License

public static void main(String[] args) throws TTransportException, SocketException {
    int port = getPortFromArgs(args);

    Injector injector = Guice.createInjector(new ModuleAuthenticationOperations(),
            new ModuleAuthenticationService(), new ModuleCassandraDataRepositories(),
            new ModuleCassandraDevCluster());

    AuthenticationService.Iface authenticationService = injector.getInstance(AuthenticationService.Iface.class);
    AuthenticationService.Processor processor = new AuthenticationService.Processor<>(authenticationService);

    TServerSocket socket = new TServerSocket(port);
    socket.getServerSocket().setSoTimeout((int) SECONDS.toMillis(30));

    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(socket)
            .protocolFactory(new TBinaryProtocol.Factory()).processor(processor).requestTimeout(60)
            .requestTimeoutUnit(SECONDS).minWorkerThreads(5).maxWorkerThreads(100);

    LOG.info("Starting Authentication Service at port {}", port);

    TThreadPoolServer server = new TThreadPoolServer(serverArgs);
    server.serve();//from ww  w .  jav a2  s .  c  o  m
    server.stop();
}

From source file:tech.aroma.service.server.TcpServer.java

License:Apache License

public static void main(String[] args) throws TTransportException, SocketException {
    Injector injector = Guice.createInjector(new ModuleAromaService(), new ModuleCassandraDataRepositories(),
            new ModuleCassandraDevCluster(), new ModuleEncryptionMaterialsDev(), new RestOfDependencies());

    AromaService.Iface aromaService = injector.getInstance(AromaService.Iface.class);
    AromaService.Processor processor = new AromaService.Processor<>(aromaService);

    TServerSocket socket = new TServerSocket(PORT);
    socket.getServerSocket().setSoTimeout((int) SECONDS.toMillis(30));

    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(socket)
            .protocolFactory(new TBinaryProtocol.Factory()).processor(processor).requestTimeout(60)
            .requestTimeoutUnit(SECONDS).minWorkerThreads(5).maxWorkerThreads(100);

    LOG.info("Starting Aroma Service at port {}", PORT);

    TThreadPoolServer server = new TThreadPoolServer(serverArgs);
    server.serve();/* www .  j  a va2s  .  c o  m*/
    server.stop();
}