Mercurial > hg > blitz_condensed
annotate src/org/prevayler/implementation/PrevaylerCore.java @ 33:0b9265358617
Added tag 2.1.1 for changeset a77f0a9ed93c
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 12 Jun 2010 10:52:10 +0100 |
parents | a77f0a9ed93c |
children |
rev | line source |
---|---|
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
1 /* |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
2 The copyright of all source code included in this Prevayler distribution is |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
3 held by Klaus Wuestefeld, except the files that specifically state otherwise. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
4 All rights are reserved. "PREVAYLER" is a trademark of Klaus Wuestefeld. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
5 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
6 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
7 BSD License: |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
8 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
9 Redistribution and use in source and binary forms, with or without |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
10 modification, are permitted provided that the following conditions are met: |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
11 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
12 - Redistributions of source code must retain the above copyright notice, this |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
13 list of conditions and the following disclaimer. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
14 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
15 - Redistributions in binary form must reproduce the above copyright notice, |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
16 this list of conditions and the following disclaimer in the documentation |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
17 and/or other materials provided with the distribution. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
18 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
19 - Neither the name of Prevayler nor the names of its contributors may be used |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
20 to endorse or promote products derived from this software without specific |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
21 prior written permission. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
22 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
23 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
27 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
34 POSSIBILITY OF SUCH DAMAGE. |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
35 */ |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
36 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
37 package org.prevayler.implementation; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
38 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
39 import java.io.*; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
40 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
41 import java.rmi.RMISecurityManager; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
42 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
43 import org.prevayler.*; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
44 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
45 /** Provides transparent persistence for business objects. |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
46 * This applies to any deterministic system implementing the PrevalentSystem interface. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
47 * All commands to the system must be represented as objects implementing the Command interface and must be executed |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
48 * using Prevayler.executeCommand(Command). |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
49 * Take a look at the demo application included with the Prevayler distribution for examples. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
50 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
51 public class PrevaylerCore { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
52 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
53 private final PrevalentSystem system; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
54 private final SystemClock clock; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
55 private final CommandOutputStream output; |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
56 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
57 /** Returns a new Prevayler for the given PrevalentSystem. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
58 * "PrevalenceBase" shall be the directory where the snapshot and log files shall be created and read. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
59 * @param newSystem The newly started, "empty" PrevalentSystem that will be used as a starting point for every |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
60 * system startup, until the first snapshot is taken. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
61 * @param shouldReset Whether to issue resets in the underlying OOS |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
62 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
63 public PrevaylerCore(PrevalentSystem newSystem, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
64 boolean shouldReset, boolean shouldClean, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
65 int aBufferSize) |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
66 throws IOException, ClassNotFoundException { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
67 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
68 this(newSystem, "PrevalenceBase", shouldReset, shouldClean, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
69 aBufferSize); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
70 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
71 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
72 /** Returns a new Prevayler for the given PrevalentSystem. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
73 * @param newSystem The newly started, "empty" PrevalentSystem that will be used as a starting point for every |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
74 * system startup, until the first snapshot is taken. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
75 * @param directory The full path of the directory where the snapshot and log files shall be created and read. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
76 * @param shouldReset Whether to issue resets in the underlying OOS |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
77 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
78 public PrevaylerCore(PrevalentSystem newSystem, String directory, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
79 boolean shouldReset, boolean shouldClean, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
80 int aBufferSize) |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
81 throws IOException, ClassNotFoundException { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
82 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
83 newSystem.clock(new SystemClock()); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
84 CommandInputStream input = new CommandInputStream(directory); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
85 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
86 PrevalentSystem savedSystem = input.readLastSnapshot(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
87 system = (savedSystem == null) |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
88 ? newSystem |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
89 : savedSystem; |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
90 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
91 recoverCommands(input); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
92 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
93 output = input.commandOutputStream(shouldReset, shouldClean, |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
94 aBufferSize); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
95 clock = (SystemClock) system.clock(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
96 clock.resume(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
97 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
98 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
99 public PrevaylerCore(PrevalentSystem newSystem, String directory) |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
100 throws IOException, ClassNotFoundException { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
101 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
102 clock = null; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
103 output = null; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
104 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
105 newSystem.clock(new SystemClock()); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
106 CommandInputStream input = new CommandInputStream(directory); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
107 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
108 PrevalentSystem savedSystem = input.readLastSnapshot(); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
109 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
110 if (savedSystem != null) { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
111 system = savedSystem; |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
112 } else { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
113 system = newSystem; |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
114 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
115 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
116 System.out.println("System base clock: " + system.clock().time().getTime()); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
117 Serializable[] myUserData = system.getSnapshotContributions(); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
118 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
119 for (int i = 0; i < myUserData.length; i++) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
120 System.out.println(myUserData[i].toString()); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
121 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
122 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
123 debugCommands(input); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
124 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
125 |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
126 /** |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
127 Returns the underlying PrevalentSystem. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
128 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
129 public PrevalentSystem system() { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
130 return system; |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
131 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
132 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
133 /** Logs the received command for crash or shutdown recovery and executes it on the underlying PrevalentSystem. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
134 * @see system() |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
135 * @return The serializable object that was returned by the execution of command. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
136 * @throws IOException if there is trouble writing the command to the log. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
137 * @throws Exception if command.execute() throws an exception. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
138 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
139 public void logCommand(Command command) throws Exception { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
140 synchronized (this) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
141 output.writeCommand(command); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
142 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
143 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
144 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
145 public void logCommand(Command command, boolean doSync) throws Exception { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
146 synchronized (this) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
147 output.writeCommand(command, doSync); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
148 } |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
149 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
150 |
32
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
151 public void flush() throws IOException { |
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
152 synchronized(this) { |
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
153 output.flush(); |
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
154 } |
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
155 } |
a77f0a9ed93c
Add support for optimistic log batching.
Dan Creswell <dan.creswell@gmail.com>
parents:
17
diff
changeset
|
156 |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
157 /** |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
158 * This method prepares a snapshot of the system and returns it in a |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
159 * Snapshotter instance which can be used to save the snapshot to disk |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
160 * once dirty state has been sync'd to disk. If your application has no |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
161 * additional state, you can simply invoke on the Snapshotter immediately. |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
162 * @return Snapshotter to be used to save an appropriate snapshot post |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
163 * sync'ing of dirty state to disk. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
164 * @see system() |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
165 * @throws IOException if there is trouble preparing the snapshot file. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
166 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
167 public synchronized Snapshotter takeSnapshot() throws IOException { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
168 clock.pause(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
169 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
170 return output.writeSnapshot(system); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
171 } finally { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
172 clock.resume(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
173 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
174 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
175 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
176 private void debugCommands(CommandInputStream input) throws IOException, ClassNotFoundException { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
177 Command command; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
178 |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
179 while (true) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
180 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
181 command = input.readCommand(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
182 } catch (EOFException eof) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
183 break; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
184 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
185 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
186 try { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
187 System.out.println(command); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
188 System.out.println(); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
189 // command.execute(system); |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
190 } catch (Exception e) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
191 //Don't do anything at all. Commands may throw exceptions normally. |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
192 System.err.println("Command threw exception"); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
193 e.printStackTrace(System.err); |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
194 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
195 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
196 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
197 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
198 private void recoverCommands(CommandInputStream input) throws IOException, ClassNotFoundException { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
199 Command command; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
200 while (true) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
201 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
202 command = input.readCommand(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
203 } catch (EOFException eof) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
204 break; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
205 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
206 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
207 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
208 command.execute(system); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
209 } catch (Exception e) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
210 //Don't do anything at all. Commands may throw exceptions normally. |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
211 System.err.println("Command threw exception"); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
212 e.printStackTrace(System.err); |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
213 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
214 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
215 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
216 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
217 public static void main(String anArgs[]) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
218 try { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
219 System.setSecurityManager(new RMISecurityManager()); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
220 |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
221 new PrevaylerCore(new DebugSystem(), anArgs[0]); |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
222 } catch (Exception anE) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
223 System.err.println("Whoops"); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
224 anE.printStackTrace(System.err); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
225 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
226 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
227 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
228 static class DebugSystem implements org.prevayler.PrevalentSystem { |
17
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
229 |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
230 private org.prevayler.AlarmClock theClock; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
231 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
232 public void clock(org.prevayler.AlarmClock clock) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
233 theClock = clock; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
234 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
235 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
236 public org.prevayler.AlarmClock clock() { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
237 return theClock; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
238 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
239 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
240 public void add(SnapshotContributor aContributor) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
241 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
242 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
243 public void remove(SnapshotContributor aContributor) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
244 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
245 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
246 public Serializable[] getSnapshotContributions() { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
247 return new Serializable[0]; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
248 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
249 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
250 } |