use of com.ramussoft.common.journal.Journal in project ramus by Vitaliy-Yakovchuk.
the class Runner method recoverySession.
public boolean recoverySession(final String sessionPath, final File sourceFile) {
Window rFrame = new Window(null);
String recovering = GlobalResourcesManager.getString("File.Recovering");
rFrame.add(new Label(MessageFormat.format(recovering, ((sourceFile == null) ? GlobalResourcesManager.getString("Session.NoName") : sourceFile.getName()))));
rFrame.pack();
rFrame.setLocationRelativeTo(null);
rFrame.setVisible(true);
final String s = sessionPath + File.separator + "source.rms";
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
initAdditionalPluginSuits(ps);
return ps;
}
@Override
protected File getFile() {
File file = new File(s);
if (file.exists())
return file;
return null;
}
protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
return new FileIEngineImpl(0, template, factory, sessionPath);
}
};
final Engine engine = database.getEngine(null);
DirectoryJournalFactory factory = database.getJournalFactory();
Journal[] journals = factory.loadJournals(database.getJournaledEngine());
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(redoCallback);
}
if ((journal.getPointer() == 0l) || (command instanceof StopUndoPointCommand)) {
rFrame.setVisible(false);
continue;
} else
exist = true;
if (!(command instanceof EndUserTransactionCommand))
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
while (journal.canUndo()) {
if (journal.undo() instanceof StartUserTransactionCommand)
break;
}
}
}
if (!exist) {
try {
((FileIEngineImpl) engine.getDeligate()).close();
for (Journal journal : journals) journal.close();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
((FileIEngineImpl) engine.getDeligate()).recoveryStreams();
engine.setPluginProperty(CORE, "Changed", Boolean.TRUE);
engine.setActiveBranch(-1l);
final AccessRules accessor = database.getAccessRules(null);
rFrame.setVisible(false);
Runnable runnable = new Runnable() {
@Override
public void run() {
SplashScreen screen = new SplashScreen() {
/**
*/
private static final long serialVersionUID = -2727237354089088151L;
@Override
protected String getImageName() {
return Runner.this.getSplashImageName();
}
};
screen.setLocationRelativeTo(null);
screen.setVisible(true);
final JFrame frame = openInNewWindows(engine, accessor, sourceFile, true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
String recovered = GlobalResourcesManager.getString("File.Recovered");
frame.setTitle(frame.getTitle() + " " + recovered);
}
});
screen.setVisible(false);
}
};
recoveredCount++;
Thread thread = new Thread(runnable);
thread.start();
return true;
}
use of com.ramussoft.common.journal.Journal in project ramus by Vitaliy-Yakovchuk.
the class InternetSyncJournal method undo.
public void undo(byte[] data) {
try {
accessFile.seek(0);
accessFile.write(data);
} catch (Exception e) {
throw new RuntimeException(e);
}
Journal journal = new Journal(accessFile, -1l) {
@Override
protected JournaledEngine getEngine(int engineId) {
return InternetSyncJournal.this.getEngine(engineId);
}
};
journal.undoUserTransaction();
}
use of com.ramussoft.common.journal.Journal in project ramus by Vitaliy-Yakovchuk.
the class LightClient method getEngine.
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
try {
Journal journal = new Journal(null, -1l);
journal.setEnable(false);
final JournaledEngine journaledEngine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(null), accessor);
Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Engine.class, Journaled.class }, new InvocationHandler() {
private Journaled journaled = new Journaled() {
boolean started = false;
@Override
public void undoUserTransaction() {
}
@Override
public void startUserTransaction() {
started = true;
}
@Override
public void setNoUndoPoint() {
}
@Override
public void setEnable(boolean b) {
}
@Override
public void rollbackUserTransaction() {
started = false;
}
@Override
public void removeJournalListener(JournalListener listener) {
}
@Override
public void redoUserTransaction() {
}
@Override
public boolean isUserTransactionStarted() {
return started;
}
@Override
public boolean isEnable() {
return false;
}
@Override
public JournalListener[] getJournalListeners() {
return new JournalListener[] {};
}
@Override
public void commitUserTransaction() {
started = false;
}
@Override
public void close() {
}
@Override
public boolean canUndo() {
return false;
}
@Override
public boolean canRedo() {
return false;
}
@Override
public void addJournalListener(JournalListener listener) {
}
@Override
public long getBranch() {
return -1l;
}
};
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getDeclaringClass().equals(Journaled.class))
return method.invoke(journaled, args);
return method.invoke(journaledEngine, args);
}
});
return engine;
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.journal.Journal in project ramus by Vitaliy-Yakovchuk.
the class InternetSyncJournal method redo.
public void redo(byte[] bs) {
try {
accessFile.seek(0);
accessFile.write(bs);
accessFile.seek(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
Journal journal = new Journal(accessFile, -1l) {
@Override
protected JournaledEngine getEngine(int engineId) {
return InternetSyncJournal.this.getEngine(engineId);
}
};
journal.redoUserTransaction();
}
use of com.ramussoft.common.journal.Journal in project ramus by Vitaliy-Yakovchuk.
the class ClientServiceImpl method replaceElements.
@Override
public byte[] replaceElements(Element[] oldElements, Element newElement) {
Journal journal;
Engine engine = server.getEngine();
if (engine instanceof JournaledEngine) {
journal = ((JournaledEngine) engine).getJournal();
} else {
journal = ((JournaledEngine) ((CachedEngine) engine).getSource()).getJournal();
}
synchronized (server) {
try {
journal.startUserTransaction();
server.getEngine().replaceElements(oldElements, newElement);
journal.commitUserTransaction();
byte[] remove = server.getCalls().remove(Thread.currentThread());
journal.undoUserTransaction();
return remove;
} catch (Exception e) {
server.getCalls().remove(Thread.currentThread());
journal.rollbackUserTransaction();
throw new RuntimeException(e);
}
}
}
Aggregations