comparison src/org/dancres/blitz/txn/TimeoutCheckpointTrigger.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
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.txn;
2
3 import java.util.logging.Level;
4 import java.io.IOException;
5
6 import org.dancres.blitz.ActiveObjectRegistry;
7
8 /**
9 */
10 public class TimeoutCheckpointTrigger implements CheckpointTrigger, Runnable {
11 private Checkpointer theCheckpointer;
12
13 private int theCommandThreshold;
14
15 private Thread theCheckpointThread;
16 private boolean stopCheckpointing = false;
17 private int theLogCount = 0;
18 private long theTimeout;
19
20 TimeoutCheckpointTrigger(Checkpointer aCheckpointer,
21 int aCommandThreshold, long aTimeout) {
22 theCheckpointer = aCheckpointer;
23 theCommandThreshold = aCommandThreshold;
24 theTimeout = aTimeout;
25
26 ActiveObjectRegistry.add(this);
27 }
28
29 public void loggedCommand() {
30 synchronized (this) {
31 ++theLogCount;
32
33 if (theLogCount == theCommandThreshold) {
34 theLogCount = 0;
35 notify();
36 }
37 }
38 }
39
40 public void begin() {
41 theCheckpointThread = new Thread(this, "Checkpointer");
42 theCheckpointThread.start();
43 }
44
45 public void halt() {
46 synchronized (this) {
47 stopCheckpointing = true;
48 notify();
49 }
50
51 try {
52 theCheckpointThread.join();
53 theCheckpointThread = null;
54 } catch (InterruptedException anIE) {
55 TxnManager.theLogger.log(Level.SEVERE,
56 "Failed to wait for checkpointer",
57 anIE);
58 }
59 }
60
61 public void run() {
62 boolean timeToExit = false;
63
64 while (!timeToExit) {
65 synchronized (this) {
66 if (!stopCheckpointing) {
67 try {
68 wait(theTimeout);
69 } catch (InterruptedException anIE) {
70 TxnManager.theLogger.log(Level.INFO,
71 "Checkpointer interrupted",
72 anIE);
73 }
74 }
75
76 timeToExit = stopCheckpointing;
77 theLogCount = 0;
78 }
79
80 if (!timeToExit) {
81 try {
82 theCheckpointer.sync();
83 } catch (IOException anIOE) {
84 TxnManager.theLogger.log(Level.SEVERE,
85 "Checkpoint failed",
86 anIOE);
87 }
88 }
89 }
90 }
91
92 public boolean checkpointsDisabled() {
93 return false;
94 }
95 }