コード例 #1
0
ファイル: E103Test.java プロジェクト: nishant1286/prevayler
  private void runTest(TransactionWithQuery<Root, Entity> createEntityTransaction)
      throws Exception {

    // Create or load existing prevalence layer from journal and/or snapshot.
    String dataPath = "target/PrevalenceBase_" + System.currentTimeMillis();
    Prevayler<Root> prevayler = PrevaylerFactory.createPrevayler(new Root(), dataPath);

    try {
      final Entity entity = prevayler.execute(createEntityTransaction);
      final long timestampWhenInitiallyCreated = entity.getCreated();

      // close and reopen prevalence so the journal is replayed
      prevayler.close();
      prevayler = PrevaylerFactory.createPrevayler(new Root(), dataPath);

      long timestampAfterRestart =
          prevayler.execute(
              new Query<Root, Long>() {
                public Long query(Root prevalentSystem, Date executionTime) throws Exception {
                  return prevalentSystem.getEntities().get(entity.getIdentity()).getCreated();
                }
              });

      assertEquals(
          "timestamp should not have changed",
          timestampWhenInitiallyCreated,
          timestampAfterRestart);

    } finally {
      prevayler.close();
    }
  }
コード例 #2
0
ファイル: Service.java プロジェクト: Ribeiro/prevayler
 public void open() throws Exception {
   prevayler = PrevaylerFactory.createPrevayler(new Root(), "PrevalenceBase");
   if (prevayler.prevalentSystem().getCreated() == null) {
     prevayler.execute(new InitializeServiceTransaction());
     prevayler.takeSnapshot();
   }
 }
コード例 #3
0
 @Override
 public void run() {
   while (!terminated) {
     try {
       sleep(MINUTES * snapshotPeriodMinutes);
     } catch (InterruptedException e) {
     }
     try {
       if (journalFilesExist()) {
         prevayler.takeSnapshot();
         cleanupJournalFiles();
       }
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
 }
コード例 #4
0
ファイル: Service.java プロジェクト: Ribeiro/prevayler
 public void close() throws Exception {
   prevayler.close();
 }
コード例 #5
0
 public void snapshot() throws IOException {
   prevayler.takeSnapshot();
   cleanupJournalFiles();
 }