Skip to content

Commit

Permalink
Fixed restoring session after Ramus crashed, closed #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-Yakovchuk committed Nov 11, 2015
1 parent 15ec475 commit 846fcd1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 16 additions & 1 deletion common/src/main/java/com/ramussoft/common/journal/Journal.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@

public class Journal implements Journaled {

public static final RedoCallback TRUE_REDO_CALLBACK = new RedoCallback() {
@Override
public boolean execute(Command command) {
return true;
}
};
protected BinaryAccessFile accessFile;

private static Hashtable<Class<? extends Command>, Integer> commandsTypes;
Expand Down Expand Up @@ -164,12 +170,17 @@ public void registerEngine(JournaledEngine engine) {
}

public Command redo() {
return redo(TRUE_REDO_CALLBACK);
}

public Command redo(RedoCallback callback) {
Command command = null;
long index = getPointer();
try {
command = readNext();
IEngine engine = command.getEngine().deligate;
command.redo(engine);
if(callback.execute(command))
command.redo(engine);

JournalEvent event = new JournalEvent(this, command, index);
afterRedo(event);
Expand Down Expand Up @@ -469,4 +480,8 @@ public void setLock(boolean lock) {
public long getBranch() {
return branch;
}

public interface RedoCallback {
boolean execute(Command command);
}
}
14 changes: 13 additions & 1 deletion local-client/src/main/java/com/ramussoft/local/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,23 @@ protected FileIEngineImpl createFileIEngine(PluginFactory factory)
if (journals.length == 0)
return false;
boolean exist = false;
Journal.RedoCallback redoCallback = new Journal.RedoCallback() {

boolean hadStartUserTransaction;

@Override
public boolean execute(Command command) {
if (command instanceof StartUserTransactionCommand) {
hadStartUserTransaction = true;
}
return hadStartUserTransaction;
}
};
for (Journal journal : journals) {
try {
Command command = null;
while (journal.canRedo()) {
command = journal.redo();
command = journal.redo(redoCallback);
}
if ((journal.getPointer() == 0l)
|| (command instanceof StopUndoPointCommand)) {
Expand Down

0 comments on commit 846fcd1

Please sign in to comment.