Mercurial > hg > blitz_stable
annotate src/org/prevayler/implementation/PrevaylerCore.java @ 32:243c74d599bf
Update ignores
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 12 Jun 2010 10:41:47 +0100 |
parents | 4580bb12db30 |
children | a77f0a9ed93c |
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. |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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 |
18
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; |
18
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; |
18
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 |
18
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 |
18
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 |
18
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 } |
18
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 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
151 /** |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
152 * 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
|
153 * 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
|
154 * 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
|
155 * additional state, you can simply invoke on the Snapshotter immediately. |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
156 * @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
|
157 * sync'ing of dirty state to disk. |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
158 * @see system() |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
159 * @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
|
160 */ |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
161 public synchronized Snapshotter takeSnapshot() throws IOException { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
162 clock.pause(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
163 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
164 return output.writeSnapshot(system); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
165 } finally { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
166 clock.resume(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
167 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
168 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
169 |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
170 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
|
171 Command command; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
172 |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
173 while (true) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
174 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
175 command = input.readCommand(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
176 } catch (EOFException eof) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
177 break; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
178 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
179 |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
180 try { |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
181 System.out.println(command); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
182 System.out.println(); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
183 // command.execute(system); |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
184 } catch (Exception e) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
185 //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
|
186 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
|
187 e.printStackTrace(System.err); |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
188 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
189 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
190 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
191 |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
192 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
|
193 Command command; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
194 while (true) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
195 try { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
196 command = input.readCommand(); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
197 } catch (EOFException eof) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
198 break; |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
199 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
200 |
18
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.execute(system); |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
203 } catch (Exception e) { |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
204 //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
|
205 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
|
206 e.printStackTrace(System.err); |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
207 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
208 } |
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
209 } |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
210 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
211 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
|
212 try { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
213 System.setSecurityManager(new RMISecurityManager()); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
214 |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
215 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
|
216 } catch (Exception anE) { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
217 System.err.println("Whoops"); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
218 anE.printStackTrace(System.err); |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
219 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
220 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
221 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
222 static class DebugSystem implements org.prevayler.PrevalentSystem { |
18
4580bb12db30
Separate command execution from command logging.
Dan Creswell <dan.creswell@gmail.com>
parents:
0
diff
changeset
|
223 |
0
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
224 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
|
225 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
226 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
|
227 theClock = clock; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
228 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
229 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
230 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
|
231 return theClock; |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
232 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
233 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
234 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
|
235 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
236 |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
237 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
|
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 Serializable[] getSnapshotContributions() { |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
241 return new Serializable[0]; |
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 } |
3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
Dan Creswell <dan.creswell@gmail.com>
parents:
diff
changeset
|
244 } |