Search in sources :

Example 1 with JournalListener

use of com.ramussoft.common.journal.event.JournalListener in project ramus by Vitaliy-Yakovchuk.

the class DirectoryJournalFactory method getJournal.

@Override
public Journal getJournal(JournaledEngine engine, long branchId) {
    if (directory == null) {
        Journal journal = new Journal(null, -1l);
        journal.setEnable(false);
        return journal;
    }
    Journal journal = journals.get(branchId);
    if (journal == null) {
        try {
            journal = new Journal(new BinaryAccessFile(new File(directory, "ramus-" + branchId + ".journal"), "rw"), branchId);
            journal.registerEngine(engine);
            journal.setEnable(true);
            journals.put(branchId, journal);
            for (JournalListener listener : getJournalListeners()) journal.addJournalListener(listener);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    return journal;
}
Also used : JournalListener(com.ramussoft.common.journal.event.JournalListener) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 2 with JournalListener

use of com.ramussoft.common.journal.event.JournalListener 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);
    }
}
Also used : DirectoryJournalFactory(com.ramussoft.common.journal.DirectoryJournalFactory) JournalListener(com.ramussoft.common.journal.event.JournalListener) Journal(com.ramussoft.common.journal.Journal) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Journaled(com.ramussoft.common.journal.Journaled) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine)

Aggregations

JournalListener (com.ramussoft.common.journal.event.JournalListener)2 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 DirectoryJournalFactory (com.ramussoft.common.journal.DirectoryJournalFactory)1 Journal (com.ramussoft.common.journal.Journal)1 Journaled (com.ramussoft.common.journal.Journaled)1 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1