Search in sources :

Example 6 with CachedEngine

use of com.ramussoft.common.cached.CachedEngine 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);
        }
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Journal(com.ramussoft.common.journal.Journal) InternetSyncJournal(com.ramussoft.net.common.internet.InternetSyncJournal) Engine(com.ramussoft.common.Engine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with CachedEngine

use of com.ramussoft.common.cached.CachedEngine in project ramus by Vitaliy-Yakovchuk.

the class StartCommand method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        System.setProperty("catalina.base", args[0]);
        ScriptEngineManager factory = new ScriptEngineManager();
        ScriptEngine engine = factory.getEngineByName("JavaScript");
        Properties ps = EngineFactory.getPropeties();
        String command = args[1];
        String fileName = (String) ps.get(command);
        EngineFactory engineFactory = new EngineFactory();
        engineFactory.createJournaledEngine(new DirectoryJournalFactory(null));
        final Engine engine1 = (Engine) SuperEngineFactory.createTransactionalEngine(engineFactory.journaledEngine, ((JournaledEngine) ((CachedEngine) engineFactory.journaledEngine).getSource()).getJournal());
        engine.getContext().setAttribute("engine", engine1, ScriptContext.ENGINE_SCOPE);
        engine.eval(new InputStreamReader(new FileInputStream(fileName), "UTF-8"));
        System.exit(0);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (ScriptException e) {
        e.printStackTrace();
    }
    System.exit(1);
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) SuperEngineFactory(com.ramussoft.common.journal.SuperEngineFactory) InputStreamReader(java.io.InputStreamReader) ScriptEngineManager(javax.script.ScriptEngineManager) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Properties(java.util.Properties) ScriptEngine(javax.script.ScriptEngine) FileInputStream(java.io.FileInputStream) ScriptException(javax.script.ScriptException) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) ScriptEngine(javax.script.ScriptEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine)

Aggregations

CachedEngine (com.ramussoft.common.cached.CachedEngine)7 Engine (com.ramussoft.common.Engine)6 Plugin (com.ramussoft.common.Plugin)4 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)4 IEngine (com.ramussoft.common.IEngine)3 AccessRules (com.ramussoft.common.AccessRules)2 PluginFactory (com.ramussoft.common.PluginFactory)2 FileNotFoundException (java.io.FileNotFoundException)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 LogPlugin (com.ramussoft.client.log.LogPlugin)1 AbstractPlugin (com.ramussoft.common.AbstractPlugin)1 PluginProvider (com.ramussoft.common.PluginProvider)1 DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)1 Journal (com.ramussoft.common.journal.Journal)1 Journaled (com.ramussoft.common.journal.Journaled)1 SuperEngineFactory (com.ramussoft.common.journal.SuperEngineFactory)1 EngineLogExtension (com.ramussoft.common.logger.EngineLogExtension)1 Event (com.ramussoft.common.logger.Event)1 ILog (com.ramussoft.common.logger.ILog)1