diff src/org/dancres/blitz/notify/SeqNumInterval.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/dancres/blitz/notify/SeqNumInterval.java	Sat Mar 21 11:00:06 2009 +0000
@@ -0,0 +1,56 @@
+package org.dancres.blitz.notify;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import java.util.logging.Level;
+
+import org.dancres.blitz.txn.TxnState;
+import org.dancres.blitz.txn.TxnOp;
+
+import org.dancres.blitz.disk.DiskTxn;
+
+import org.dancres.blitz.oid.OID;
+
+import org.dancres.blitz.meta.RegistryFactory;
+import org.dancres.blitz.meta.Registry;
+
+/**
+   Log action which restores a snapshotted sequence number to an event
+   generator.  Rather than save an update to disk for each event we generate,
+   we log a single change record after a fixed number of events have been
+   dispatched.  In this way, we reduce I/O's and can still keep the
+   EventGenerator sequence number up-to-date.  Note that in the case of
+   restore from log, a <code>RemoteEventListener</code> will likely see a
+   slightly bigger jump than it might expect - that's okay.  Note also that
+   such restarts will "eat up" a few sequence numbers (i.e. they will never
+   be used on a RemoteEvent) - that's okay too.
+ */
+class SeqNumInterval implements TxnOp {
+    private OID theOID;
+    private long theSeqNum;
+
+    SeqNumInterval(OID aOID, long aSeqNum) {
+        theOID = aOID;
+        theSeqNum = aSeqNum;
+    }
+
+    public void commit(TxnState aState) throws IOException {
+        // Nothing to do, we're just recording state
+    }
+
+    public void abort(TxnState aState) throws IOException {
+        // Nothing to do, we're just recording state
+    }
+
+    public void restore(TxnState aState) throws IOException {
+        EventQueue.theLogger.log(Level.FINE, "Patching notify reg" +
+                                 theOID + ", " + theSeqNum);
+
+        EventGeneratorFactory.get().recover(theOID, theSeqNum);
+    }
+
+    public String toString() {
+        return " SN : " + theOID + " : " + theSeqNum;
+    }
+}