Java 类org.apache.thrift.server.TSimpleServer 实例源码

项目:algorithm.annotation    文件:SimpleBackendServer.java   
public void startServer() {
    try {
        logger.info("TSimpleServer start ....");

        // TMultiplexedProcessor
        TMultiplexedProcessor processor = new TMultiplexedProcessor();
        processor.registerProcessor("Algorithm", 
                new AlgorithmService.Processor<>(new AlgorithmServiceImpl()));

        TServerSocket serverTransport = new TServerSocket(SERVER_PORT);
        TServer.Args args = new TServer.Args(serverTransport);
        args.processor(processor);
        args.protocolFactory(new TBinaryProtocol.Factory());
        // args.protocolFactory(new TJSONProtocol.Factory());
        TServer server = new TSimpleServer(args);
        server.serve();
        } catch (Exception e) {
        logger.error("Server start error!!!");
        e.printStackTrace();
    }
}
项目:Blitz-2015    文件:ReferenceMain.java   
public void startServer2() throws Exception
{
    AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer);
    TServerTransport serverTransport = new TServerSocket(9090);
    TServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).processor(processor));

    ServerRunner serverRunner = new ServerRunner(server);
    Thread serverThread = new Thread(serverRunner);

    serverThread.start();
    logger.info("Started binary interface");

    joinMethods.add(() -> {
        try {
            serverThread.join();
        } catch (InterruptedException ignored) {
        }
    });
}
项目:providence    文件:RPCThriftSocketTest.java   
@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;
        }
    };
}
项目:providence    文件:SocketClientHandlerTest.java   
@BeforeClass
public static void setUpServer() throws Exception {
    Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);

    port = findFreePort();
    impl = Mockito.mock(Iface.class);

    TServerSocket transport = new TServerSocket(port);
    server = new TSimpleServer(
            new TServer.Args(transport)
                    .protocolFactory(new TBinaryProtocol.Factory())
                    .processor(new Processor<>(impl)));
    executor = Executors.newSingleThreadExecutor();
    executor.submit(server::serve);
    serializer = new BinarySerializer();
    address = new InetSocketAddress("localhost", port);
}
项目:ezbake-common-java    文件:ThriftUtils.java   
private static TServer startSimpleServer(final TServerTransport transport, final TProcessor processor,
        Properties properties) throws Exception {

    TServer.AbstractServerArgs<?> serverArgs;
    if (properties == null) {
        serverArgs = new TServer.Args(transport).processor(processor);
    } else {
        serverArgs = ThriftUtils.getServerArgs(transport, properties).processor(processor);
    }

    final TServer server = new TSimpleServer(serverArgs);
    new Thread(new Runnable() {

        @Override
        public void run() {
            server.serve();
        }
    }).start();
    return server;
}
项目:pinpoint    文件:SyncEchoTestServer.java   
public static SyncEchoTestServer<TSimpleServer> simpleServer(final TestEnvironment environment)
        throws TTransportException {
    TSimpleServer server = new TSimpleServer(new TSimpleServer.Args(new TServerSocket(environment.getPort()))
            .processor(getProcessor()).inputProtocolFactory(environment.getProtocolFactory())
            .outputProtocolFactory(environment.getProtocolFactory()));
    return new SyncEchoTestServer<TSimpleServer>(server, environment) {
        @Override
        public SyncEchoTestClient getSynchronousClient() throws TTransportException {
            return new SyncEchoTestClient.Client(environment);
        }

        @Override
        public AsyncEchoTestClient getAsynchronousClient() throws IOException {
            return new AsyncEchoTestClient.Client(environment);
        }
    };
}
项目:wmr-backend    文件:ThriftServer.java   
public int run(String[] args) throws Exception
{
    Configuration conf = getConf();
    int port = conf.getInt("wmr.server.bind.port", 50100);

    SubmissionDatabase.connect(conf);

    JobServiceHandler service = new JobServiceHandler(new Configuration());
    JobService.Processor processor = new JobService.Processor(service);
    TServerTransport transport = new TServerSocket(port);
    TServer server = new TSimpleServer(new Args(transport).processor(processor));

    server.serve();

    return 0;
}
项目:CadalWorkspace    文件:TestTSaslTransports.java   
@Override
public void startServer(final TProcessor processor, final TProtocolFactory protoFactory) throws Exception {
  serverThread = new Thread() {
    public void run() {
      try {
        // Transport
        TServerSocket socket = new TServerSocket(PORT);

        TTransportFactory factory = new TSaslServerTransport.Factory(
          WRAPPED_MECHANISM, SERVICE, HOST, WRAPPED_PROPS,
          new TestSaslCallbackHandler(PASSWORD));
        server = new TSimpleServer(new Args(socket).processor(processor).transportFactory(factory).protocolFactory(protoFactory));

        // Run it
        LOGGER.debug("Starting the server on port {}", PORT);
        server.serve();
      } catch (Exception e) {
        e.printStackTrace();
        fail();
      }
    }
  };
  serverThread.start();
  Thread.sleep(1000);
}
项目:CadalWorkspace    文件:TestTSaslTransports.java   
@Override
public void startServer(final TProcessor processor, final TProtocolFactory protoFactory) throws Exception {
  serverThread = new Thread() {
    public void run() {
      try {
        // Transport
        TServerSocket socket = new TServerSocket(PORT);

        TTransportFactory factory = new TSaslServerTransport.Factory(
          WRAPPED_MECHANISM, SERVICE, HOST, WRAPPED_PROPS,
          new TestSaslCallbackHandler(PASSWORD));
        server = new TSimpleServer(new Args(socket).processor(processor).transportFactory(factory).protocolFactory(protoFactory));

        // Run it
        LOGGER.debug("Starting the server on port {}", PORT);
        server.serve();
      } catch (Exception e) {
        e.printStackTrace();
        fail();
      }
    }
  };
  serverThread.start();
  Thread.sleep(1000);
}
项目:drift    文件:TestApacheThriftMethodInvoker.java   
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
项目:drift    文件:TestDriftNettyMethodInvoker.java   
private static int testProcessor(TProcessor processor, List<ToIntFunction<HostAndPort>> clients)
        throws Exception
{
    try (TServerSocket serverTransport = new TServerSocket(0)) {
        TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
        TTransportFactory transportFactory = new TFramedTransport.Factory();
        TServer server = new TSimpleServer(new Args(serverTransport)
                .protocolFactory(protocolFactory)
                .transportFactory(transportFactory)
                .processor(processor));

        Thread serverThread = new Thread(server::serve);
        try {
            serverThread.start();

            int localPort = serverTransport.getServerSocket().getLocalPort();
            HostAndPort address = HostAndPort.fromParts("localhost", localPort);

            int sum = 0;
            for (ToIntFunction<HostAndPort> client : clients) {
                sum += client.applyAsInt(address);
            }
            return sum;
        }
        finally {
            server.stop();
            serverThread.interrupt();
        }
    }
}
项目:rpc-comparison    文件:SecureAskerServer.java   
private void secure(Asker.Processor processor) {
    try {
   /*
   * Use TSSLTransportParameters to setup the required SSL parameters. In this example
   * we are setting the keystore and the keystore password. Other things like algorithms,
   * cipher suites, client auth etc can be set.
   */
        TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters();
        // The Keystore contains the private key
        params.setKeyStore(keyStore, keyPass, null, null);

  /*
   * Use any of the TSSLTransportFactory to get a server transport with the appropriate
   * SSL configuration. You can use the default settings if properties are set in the command line.
   * Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
   *
   * Note: You need not explicitly call open(). The underlying server socket is bound on return
   * from the factory class.
   */
        TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(port, 0, null, params);
        TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

        // Use this for a multi threaded server
        // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

        System.out.println("Starting the secure server...");
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:osquery-java    文件:PluginManager.java   
/**
 * Start extension by communicating with osquery core and starting thrift
 * server
 * 
 * @param name
 *            name of extension
 * @param version
 *            version of extension
 * @param sdkVersion
 *            version of the osquery SDK used to build this extension
 * @param minSdkVersion
 *            minimum version of the osquery SDK that you can use
 * @throws IOException
 * @throws ExtensionException
 */
public void startExtension(String name, String version, String sdkVersion, String minSdkVersion)
        throws IOException, ExtensionException {
    ExtensionManager.Client client = new ClientManager(EXTENSION_SOCKET).getClient();
    InternalExtensionInfo info = new InternalExtensionInfo(name, version, sdkVersion, minSdkVersion);
    try {
        ExtensionStatus status = client.registerExtension(info, registry);
        if (status.getCode() == 0) {
            this.uuid = status.uuid;
            Processor<PluginManager> processor = new Processor<PluginManager>(this);
            String serverSocketPath = EXTENSION_SOCKET + "." + String.valueOf(uuid);
            File socketFile = new File(serverSocketPath);
            if (socketFile.exists()) {
                socketFile.delete();
            }
            AFUNIXServerSocket socket = AFUNIXServerSocket.bindOn(new AFUNIXSocketAddress(socketFile));
            socketFile.setExecutable(true, false);
            socketFile.setWritable(true, false);
            socketFile.setReadable(true, false);
            TServerSocket transport = new TServerSocket(socket);
            TTransportFactory transportFactory = new TTransportFactory();
            TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();
            TServer server = new TSimpleServer(new Args(transport).processor(processor)
                    .transportFactory(transportFactory).protocolFactory(protocolFactory));

            // Run it
            System.out.println("Starting the server...");
            server.serve();
        } else {
            throw new ExtensionException(1, status.getMessage(), uuid);
        }
    } catch (TException e) {
        throw new ExtensionException(1, "Could not connect to socket", uuid);
    }
}
项目:ikasoa    文件:SimpleThriftServerImpl.java   
protected void initServer(TServerTransport serverTransport) {
    ThriftServerConfiguration configuration = getThriftServerConfiguration();
    server = new TSimpleServer(configuration.getServerArgsAspect().TServerArgsAspect(
            new TServer.Args(serverTransport).transportFactory(configuration.getTransportFactory())
                    .protocolFactory(configuration.getProtocolFactory()).processor(getProcessor())));
    if (configuration.getServerEventHandler() != null)
        server.setServerEventHandler(configuration.getServerEventHandler());
}
项目:Blitz-2015    文件:AnalyticsTest.java   
@Before
public void spawnServer() throws TException
{
    mockedServer = Mockito.mock(AwesomeService.Iface.class);
    Mockito.when(mockedServer.getData(Mockito.any(Request.class))).thenReturn(new Response());

    AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(mockedServer);
    TServerTransport serverTransport = new TServerSocket(SERVER_PORT);
    final TServer server = new TSimpleServer(new TSimpleServer.Args(serverTransport).processor(processor));

    serverRunner = new ServerRunner(server);
    serverThread = new Thread(serverRunner);
    serverThread.setDaemon(true);
    serverThread.start();
}
项目:haogrgr-projects    文件:ServerMain.java   
public static void secure(Calculator.Processor<CalculatorHandler> processor) throws Exception {
    /*
     * Use TSSLTransportParameters to setup the required SSL parameters. In this
     * example we are setting the keystore and the keystore password. Other things
     * like algorithms, cipher suites, client auth etc can be set.
     */
    TSSLTransportParameters params = new TSSLTransportParameters();
    // The Keystore contains the private key
    params.setKeyStore("../../lib/java/test/.keystore", "thrift", null, null);

    /*
     * Use any of the TSSLTransportFactory to get a server transport with the
     * appropriate SSL configuration. You can use the default settings if properties
     * are set in the command line. Ex: -Djavax.net.ssl.keyStore=.keystore and
     * -Djavax.net.ssl.keyStorePassword=thrift
     * 
     * Note: You need not explicitly call open(). The underlying server socket is
     * bound on return from the factory class.
     */
    TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
    TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

    // Use this for a multi threaded server
    // TServer server = new TThreadPoolServer(new
    // TThreadPoolServer.Args(serverTransport).processor(processor));

    System.out.println("Starting the secure server...");
    server.serve();
}
项目:thrift-load-balancer    文件:Server.java   
public static void simplePrimaryServer (LoadBalancerInvoker.Processor processor, int portNum) {
  try {
    TServerTransport serverTransport = new TServerSocket (portNum);
    TServer server = new TSimpleServer (new Args (serverTransport).processor (processor));

    System.out.println ("Starting the simple server...");
    server.serve ();
  } catch (Exception e) {
    e.printStackTrace ();
  }
}
项目:thrift-load-balancer    文件:Server.java   
public static void simpleSecondaryServer (LoadBalancer.Processor processor, int portNum) {
  try {
    TServerTransport serverTransport = new TServerSocket (portNum);
    TServer server = new TSimpleServer (new Args (serverTransport).processor (processor));

    System.out.println ("Starting the simple server...");
    server.serve ();
  } catch (Exception e) {
    e.printStackTrace ();
  }
}
项目:xio    文件:Configurator.java   
public void run() {
  log.info("Starting up!");
  try {
    serverTransport = new TServerSocket(bindAddress);
    server = new TSimpleServer(new Args(serverTransport).processor(processor));
    server.serve(); // blocks until stop() is called.
    // timer and timer task should be stopped at this point
    writeToStorage();
  } catch (TTransportException e) {
    log.error("Couldn't start Configurator {}", this, e);
  }
}
项目:ThriftBook    文件:HelloServer.java   
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new helloSvc.Processor<>(new MessageHandler());
    TServer server =
            new TSimpleServer(
                    new TSimpleServer.Args(trans_svr)
                            .processor(proc)
            );
    System.out.println("[Server] waiting for connections");
    server.serve();
}
项目:ThriftBook    文件:HelloServer.java   
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new helloSvc.Processor<>(new MessageHandler());
    TSimpleServer server = 
        new TSimpleServer(
            new TSimpleServer.Args(trans_svr)
                .processor(proc)
        );
    System.out.println("[Server] waiting for connections");
    server.serve();
}
项目:thrift-tutorial    文件:ExampleServer.java   
private static void startEchoServer(int port) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TSimpleServer.Args simpleServerArgs = new TSimpleServer.Args(transport);
    EchoServiceImpl serviceImpl = new EchoServiceImpl();
    EchoService.Processor<EchoService.Iface> processor = new EchoService.Processor<EchoService.Iface>(serviceImpl);
    simpleServerArgs.processor(processor);
    TSimpleServer simpleServer = new TSimpleServer(simpleServerArgs);
    System.out.println("Start echo service.");
    simpleServer.serve();
}
项目:thrift-tutorial    文件:ExampleServer.java   
private static void startDownloadServer(int port) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TSimpleServer.Args simpleServerArgs = new TSimpleServer.Args(transport);
    DownloadServiceImpl serviceImpl = new DownloadServiceImpl();
    DownloadService.Processor<DownloadService.Iface> processor = new DownloadService.Processor<DownloadService.Iface>(serviceImpl);
    simpleServerArgs.processor(processor);
    TSimpleServer simpleServer = new TSimpleServer(simpleServerArgs);
    System.out.println("Start download service.");
    simpleServer.serve();
}
项目:thrift-tutorial    文件:ExampleServer.java   
private static void startUploadServer(int port) throws TTransportException {
    TServerTransport transport = new TServerSocket(port);
    TSimpleServer.Args simpleServerArgs = new TSimpleServer.Args(transport);
    UploadServiceImpl serviceImpl = new UploadServiceImpl();
    UploadService.Processor<UploadService.Iface> processor = new UploadService.Processor<UploadService.Iface>(serviceImpl);
    simpleServerArgs.processor(processor);
    TSimpleServer simpleServer = new TSimpleServer(simpleServerArgs);
    System.out.println("Start upload service.");
    simpleServer.serve();
}
项目:XCOM    文件:XCOM_server.java   
public static void simple(PacketService.Processor processor) {
    try {
    TServerTransport serverTransport = new TServerSocket(9888);
    server = new TSimpleServer(new Args(serverTransport).processor(processor));

  // Use this for a multithreaded server
  // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

    System.out.println("Starting the outbound server...");
    server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:CadalWorkspace    文件:JavaServer.java   
public static void simple(Calculator.Processor processor) {
  try {
    TServerTransport serverTransport = new TServerSocket(9090);
    TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

    // Use this for a multithreaded server
    // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

    System.out.println("Starting the simple server...");
    server.serve();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
项目:CadalWorkspace    文件:JavaServer.java   
public static void secure(Calculator.Processor processor) {
  try {
    /*
     * Use TSSLTransportParameters to setup the required SSL parameters. In this example
     * we are setting the keystore and the keystore password. Other things like algorithms,
     * cipher suites, client auth etc can be set. 
     */
    TSSLTransportParameters params = new TSSLTransportParameters();
    // The Keystore contains the private key
    params.setKeyStore("../../lib/java/test/.keystore", "thrift", null, null);

    /*
     * Use any of the TSSLTransportFactory to get a server transport with the appropriate
     * SSL configuration. You can use the default settings if properties are set in the command line.
     * Ex: -Djavax.net.ssl.keyStore=.keystore and -Djavax.net.ssl.keyStorePassword=thrift
     * 
     * Note: You need not explicitly call open(). The underlying server socket is bound on return
     * from the factory class. 
     */
    TServerTransport serverTransport = TSSLTransportFactory.getServerSocket(9091, 0, null, params);
    TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

    // Use this for a multi threaded server
    // TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));

    System.out.println("Starting the secure server...");
    server.serve();
  } catch (Exception e) {
    e.printStackTrace();
  }
}
项目:rebar    文件:AbstractThriftServer.java   
/**
 * 
 */
protected AbstractThriftServer(int port, AbstractAccumuloClient aac, TProcessor processor) throws RebarException {
  try {
    this.aac = aac;
    this.serverXport = new TServerSocket(port);
    this.args = new Args(this.serverXport);
    this.args.processor(processor);
    this.server = new TSimpleServer(this.args);
  } catch (TTransportException e) {
    throw new RebarException(e);
  }
}
项目:ThriftBook    文件:SimpleServer.java   
public static void main(String[] args) throws TTransportException {
    TServerSocket trans_svr = new TServerSocket(9090);
    TProcessor proc = new SocialLookup.Processor<>(new SocialLookupHandler());
    TServer server = new TSimpleServer(new TSimpleServer.Args(trans_svr).processor(proc));
    server.serve();
}
项目:pinpoint    文件:ThriftSimpleServerIT.java   
@Override
protected EchoTestServer<TSimpleServer> createEchoServer(TestEnvironment environment) throws TTransportException {
    return SyncEchoTestServerFactory.simpleServer(environment);
}