[CVS nanning] removed CheckpointPrevayler

Jon Tirsen <[email protected]> Sun, 10 Aug 2003 11:27:20 -0500
Newsgroups gmane.comp.java.nanning.devel
Message-ID <200308101627.h7AGRKr11584__26557.1537697271$1060532509@codehaus.org>
Commit in nanning/src/frameworks/prevayler/src on MAIN

main/org/codehaus/nanning/prevayler/CheckpointPrevayler.java -106 1.1 removed

test/org/codehaus/nanning/prevayler/CheckpointPrevaylerTest.java -51 1.1 removed

-157

2 removed files

removed CheckpointPrevayler

----------

nanning/src/frameworks/prevayler/src/main/org/codehaus/nanning/prevayler

CheckpointPrevayler.java removed after 1.1

diff -N CheckpointPrevayler.java
--- CheckpointPrevayler.java 4 Jul 2003 10:53:58 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,106 +0,0 @@

-package org.codehaus.nanning.prevayler;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.prevayler.Prevayler;
-import org.prevayler.Transaction;
-import org.prevayler.foundation.FileManager;
-import org.prevayler.implementation.TransactionSubscriber;
-import org.prevayler.implementation.log.TransactionLogger;
-
-public class CheckpointPrevayler implements Prevayler {
- private Object prevalentSystem;
- private long systemVersion = 0;
- private CheckPointTransactionLogger publisher;
- private File directory;
- private TransactionSubscriber subscriber;
-
-
- public CheckpointPrevayler(Object newPrevalentSystem, String prevalenceBase) throws IOException, ClassNotFoundException {
- directory = FileManager.produceDirectory(prevalenceBase);
- systemVersion = latestVersion();
- prevalentSystem = newPrevalentSystem;
-
- publisher = new CheckPointTransactionLogger(prevalenceBase);
- subscriber = new TransactionSubscriber() {
- public synchronized void receive(Transaction transaction) {
- systemVersion++;
- transaction.executeOn(prevalentSystem);
- }
- };
-
- publisher.addSubscriber(subscriber, systemVersion + 1);
- }
-
-
- /** Returns the underlying prevalent system.
- */
- public Object prevalentSystem() {
- return prevalentSystem;
- }
-
-
- /** Publishes transaction and executes it on the underlying prevalentSystem(). If a Logger is used as the publisher (default), this method will only return after transaction has been written to disk.
- */
- public void execute(Transaction transaction) {
- publisher.publish(transaction);
- }
-
-
- private long latestVersion() throws IOException {
- String[] fileNames = directory.list();
- if (fileNames == null) {
- throw new IOException("Error reading file list from directory " + directory);
- }
-
- long result = 0;
- for (int i = 0; i < fileNames.length; i++) {
- long candidate = version(fileNames[i]);
- if (candidate > result) result = candidate;
- }
- return result;
- }
-
- private long version(String fileName) {
- if (!fileName.endsWith("." + suffix())) return -1;
- return Long.parseLong(fileName.substring(0, fileName.indexOf("." + suffix()))); // "00000.snapshot" becomes "00000".
- }
-
- private String suffix() {
- return "transactionLog";
- }
-
- public void checkpoint() {
- synchronized (subscriber) {
- publisher.startNewCheckpointFile();
- }
- }
-
- private class CheckPointTransactionLogger extends TransactionLogger {
- public CheckPointTransactionLogger(String prevalenceBase) throws ClassNotFoundException, IOException {
- super(prevalenceBase);
- }
-
- protected Transaction transactionFromLogEntry(Object entry) {
- if (entry instanceof Transaction) {
- return (Transaction) entry;
- }
-
- prevalentSystem = entry;
- return new Transaction() {
- public void executeOn(Object prevalentSystem) {
- }
- };
- }
-
- public void startNewCheckpointFile() {
- createNewOutputLog();
- }
-
- protected void createNewOutputLog() {
- super.createNewOutputLog();
- outputToLog(prevalentSystem);
- }
- }
-}

----------

nanning/src/frameworks/prevayler/src/test/org/codehaus/nanning/prevayler

CheckpointPrevaylerTest.java removed after 1.1

diff -N CheckpointPrevaylerTest.java
--- CheckpointPrevaylerTest.java 4 Jul 2003 10:53:58 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,51 +0,0 @@

-package org.codehaus.nanning.prevayler;
-
-import java.io.IOException;
-import java.io.File;
-
-import junit.framework.TestCase;
-import org.codehaus.nanning.prevayler.CheckpointPrevayler;
-
-public class CheckpointPrevaylerTest extends TestCase {
-
- public void testSelfResolvment() throws ClassNotFoundException, IOException {
-
- String prevalenceBase = "prevalence" + System.currentTimeMillis();
- CheckpointPrevayler prevayler = new CheckpointPrevayler(new TestSystem(), prevalenceBase);
- TestSystem system = (TestSystem) prevayler.prevalentSystem();
- prevayler.execute(new TestTransaction(system.list1));
- prevayler.execute(new TestTransaction(system.list2));
-
- prevayler = new CheckpointPrevayler(new TestSystem(), prevalenceBase);
- system = (TestSystem) prevayler.prevalentSystem();
-
- assertEquals(1, system.list1.size());
- assertEquals(1, system.list2.size());
- }
-
- public void testCheckPoint() throws ClassNotFoundException, IOException {
-
- File prevalenceBase = new File("prevalence" + System.currentTimeMillis());
- CheckpointPrevayler prevayler = new CheckpointPrevayler(new TestSystem(), prevalenceBase.getAbsolutePath());
- TestSystem system = (TestSystem) prevayler.prevalentSystem();
-
- prevayler.execute(new TestTransaction(system.list2));
- system.list1.add("1");
-
- assertEquals(1, prevalenceBase.listFiles().length);
-
- prevayler.checkpoint();
-
- assertEquals(2, prevalenceBase.listFiles().length);
-
- prevayler = new CheckpointPrevayler(new TestSystem(), prevalenceBase.getAbsolutePath());
- system = (TestSystem) prevayler.prevalentSystem();
-
- assertEquals(1, system.list1.size());
- assertEquals(2, prevalenceBase.listFiles().length);
-
- prevayler.execute(new TestTransaction(system.list2));
- assertEquals(3, prevalenceBase.listFiles().length);
- assertEquals(2, system.list2.size());
- }
-}