コード例 #1
0
  protected int removeAll() {
    int count = 0;
    Index index = getIndex();
    GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).setLimit(200).build();
    GetResponse<Document> response = index.getRange(request);

    // can only delete documents in blocks of 200 so we need to iterate until they're all gone
    while (!response.getResults().isEmpty()) {
      List<String> ids = new ArrayList<String>();
      for (Document document : response) {
        ids.add(document.getId());
      }
      index.delete(ids);
      count += ids.size();
      response = index.getRange(request);
    }
    return count;
  }
コード例 #2
0
ファイル: ProtoRPCServerExample.java プロジェクト: ekaqu/LSMT
  @Test(dependsOnGroups = "example.ipc.server")
  public void clientTest() throws IOException, ServiceException, InterruptedException {
    PeerInfo client = new PeerInfo(socketAddress.getHostName(), 1234);

    ThreadPoolCallExecutor executor = new ThreadPoolCallExecutor(3, 10);

    DuplexTcpClientBootstrap bootstrap =
        new DuplexTcpClientBootstrap(
            client,
            new NioClientSocketChannelFactory(
                Executors.newCachedThreadPool(), Executors.newCachedThreadPool()),
            executor);

    bootstrap.setOption("connectTimeoutMillis", 10000);
    bootstrap.setOption("connectResponseTimeoutMillis", 10000);
    bootstrap.setOption("receiveBufferSize", 1048576);
    bootstrap.setOption("tcpNoDelay", false);

    RpcClientChannel channel = bootstrap.peerWith(socketAddress);

    // blocking calll
    DataService.BlockingInterface dataService = DataService.newBlockingStub(channel);
    RpcController controller = channel.newRpcController();

    // make request
    GetRequest request = GetRequest.newBuilder().setRow(ByteString.copyFromUtf8("row1")).build();
    final Stopwatch stopwatch = new Stopwatch().start();
    GetResponse response = dataService.getData(controller, request);
    stopwatch.stop();
    System.out.println(response.getDataList());
    System.out.printf("Request took %s milliseconds\n", stopwatch.elapsedMillis());

    // do it again since the socket is open
    stopwatch.reset().start();
    response = dataService.getData(controller, request);
    stopwatch.stop();
    System.out.println(response.getDataList());
    System.out.printf("Request took %s milliseconds\n", stopwatch.elapsedMillis());

    // non-blocking
    DataService.Stub stub = DataService.newStub(channel);
    final Object lock = new Object();
    stopwatch.reset().start();
    stub.getData(
        controller,
        request,
        new RpcCallback<GetResponse>() {
          public void run(final GetResponse parameter) {
            System.out.println("Non-Blocking Callback");
            System.out.println(parameter.getDataList());

            stopwatch.stop();
            System.out.printf("Request took %s milliseconds\n", stopwatch.elapsedMillis());
            synchronized (lock) {
              lock.notify();
            }
          }
        });
    synchronized (lock) {
      lock.wait();
    }
  }