Ejemplo n.º 1
0
 private static void tryQuit() {
   if (writeCount.get() == COUNT && readCount.get() == COUNT) {
     try {
       store.close();
       System.exit(0);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 2
0
  public static void main(String[] args) throws Exception {

    PentoCallback readCallback =
        new PentoCallback<MockPentoReadResponse, Throwable>() {
          @Override
          public void callback(MockPentoReadResponse pentoReadResponse) {
            readCount.incrementAndGet();
            StringBuffer sb = new StringBuffer();
            sb.append(
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
            sb.append(
                "READ: "
                    + pentoReadResponse.getOrigin()
                    + " with confidence "
                    + pentoReadResponse.getConfidence()
                    + "\n");
            sb.append(
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
            System.out.println(sb);
            tryQuit();
          }

          @Override
          public void error(Throwable throwable) {
            readCount.incrementAndGet();
            System.out.println("FAILED READ!!! ");
            tryQuit();
          }
        };

    PentoCallback writeCallback =
        new PentoCallback<MockPentoWriteResponse, Throwable>() {
          @Override
          public void callback(MockPentoWriteResponse success) {
            writeCount.incrementAndGet();
            StringBuffer sb = new StringBuffer();
            sb.append(
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
            sb.append(
                "WRITE: "
                    + success.getOrigin()
                    + " with confidence "
                    + success.getConfidence()
                    + "\n");
            sb.append(
                ". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n");
            System.out.println(sb);
            tryQuit();
          }

          @Override
          public void error(Throwable throwable) {
            writeCount.incrementAndGet();
            System.out.println("FAILED WRITE!!! ");
            tryQuit();
          }
        };

    for (int i = 0; i < COUNT; i++) {
      long time = System.currentTimeMillis();
      final Statement stmt =
          new Statement("urn:sean#" + i, "foaf:mbox", "*****@*****.**", time, "TEST");
      store.write(
          new Pento(Arrays.asList(stmt)),
          new EmptyDistribution(),
          writeCallback,
          new EmptyContext());
      store.read(
          new SubjectQuery(stmt.getSubject()),
          new EmptyDistribution(),
          readCallback,
          new EmptyContext());
    }
  }