Search in sources :

Example 1 with CachedEngine

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

the class MemoryDatabase method createJournaledEngine.

private JournaledEngine createJournaledEngine(PluginFactory factory, PersistentFactory persistentFactory) throws ClassNotFoundException {
    if (cached) {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

            @Override
            protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
            }
        };
        CachedEngine cachedEngine = new CachedEngine(journaledEngine2);
        for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
        this.engine = cachedEngine;
        return journaledEngine2;
    } else {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
        this.engine = journaledEngine2;
        return journaledEngine2;
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) PluginFactory(com.ramussoft.common.PluginFactory) Plugin(com.ramussoft.common.Plugin)

Example 2 with CachedEngine

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

the class TcpLightClient method getEngine.

@SuppressWarnings("rawtypes")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
    tcpClientEngine = new TcpClientEngine((EngineInvocker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EngineInvocker.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return connection.invoke(method.getName(), args);
        }
    }), connection);
    List<Class> interfaces = new ArrayList<Class>();
    interfaces.add(Engine.class);
    interfaces.add(Journaled.class);
    interfaces.add(ILog.class);
    for (Plugin plugin : factory.getPlugins()) if (plugin.getFunctionalInterface() != null)
        interfaces.add(plugin.getFunctionalInterface());
    final Engine engine1 = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), tcpClientEngine);
    final Engine cachedEngine = createCachedEngine(engine1);
    final Hashtable<Method, Object> hashtable = new Hashtable<Method, Object>();
    for (Method m : Engine.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    for (Method m : Cached.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    interfaces.add(Cached.class);
    Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            Object o = hashtable.get(method);
            if (o == null)
                return tcpClientEngine.invoke(proxy, method, args);
            return method.invoke(o, args);
        }
    });
    tcpClientEngine.setEngine(engine);
    for (Plugin plugin : factory.getPlugins()) plugin.init(engine, rules);
    return engine;
}
Also used : EngineInvocker(com.ramussoft.net.common.tcp.EngineInvocker) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Engine(com.ramussoft.common.Engine) CachedEngine(com.ramussoft.common.cached.CachedEngine) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) LogPlugin(com.ramussoft.client.log.LogPlugin) Plugin(com.ramussoft.common.Plugin) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 3 with CachedEngine

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

the class SuperEngineFactory method createTransactionalEngine.

@SuppressWarnings("unchecked")
public static Object createTransactionalEngine(Engine engine, Journaled journal) {
    String[] classes = engine.getAllImplementationClasseNames();
    Class[] clazzes = new Class[classes.length];
    for (int i = 0; i < classes.length; i++) {
        try {
            clazzes[i] = Class.forName(classes[i]);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    SuperInvoker invoker = null;
    if (engine instanceof AbstractJournaledEngine) {
        AbstractJournaledEngine abstractJournaledEngine = (AbstractJournaledEngine) engine;
        invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
    } else if (engine instanceof CachedEngine) {
        Object[] objects = new Object[classes.length];
        Engine engine2 = ((CachedEngine) engine).getSource();
        AbstractJournaledEngine abstractJournaledEngine = null;
        if (engine2 instanceof AbstractJournaledEngine) {
            abstractJournaledEngine = (AbstractJournaledEngine) engine2;
            invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
        }
        for (int i = 0; i < objects.length; i++) {
            String className = classes[i];
            if (className.equals(Engine.class.getName())) {
                objects[i] = engine;
            } else if (className.equals(Journaled.class.getName())) {
                objects[i] = new UserTransactional(journal);
            } else {
                for (Plugin plugin : abstractJournaledEngine.pluginFactory.getPlugins()) {
                    Class class1 = plugin.getFunctionalInterface();
                    if (class1 != null)
                        if (class1.equals(clazzes[i])) {
                            objects[i] = plugin.createFunctionalInterfaceObject(engine, engine.getDeligate());
                        }
                }
            }
        }
        invoker = new SuperInvoker(classes, clazzes, objects);
    }
    return Proxy.newProxyInstance(SuperEngineFactory.class.getClassLoader(), clazzes, new Caller(invoker));
}
Also used : CachedEngine(com.ramussoft.common.cached.CachedEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin)

Example 4 with CachedEngine

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

the class RamusService method close.

public void close() {
    if (myThread != null)
        server.getLogins().remove(myThread);
    Engine engine = userEngineFactory.getJournaledEngine();
    if (engine instanceof CachedEngine) {
        ((CachedEngine) engine).removeBranchCache();
    }
    IEngine deligate = engine.getDeligate();
    if (deligate instanceof IEngineImpl) {
        try {
            ((IEngineImpl) deligate).getTemplate().close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    if (directoryJournalFactory != null) {
        directoryJournalFactory.close();
        delete(directoryJournalFactory.getDirectory());
    }
}
Also used : IEngineImpl(com.ramussoft.core.impl.IEngineImpl) ServerIEngineImpl(com.ramussoft.server.ServerIEngineImpl) SQLException(java.sql.SQLException) CachedEngine(com.ramussoft.common.cached.CachedEngine) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine)

Example 5 with CachedEngine

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

the class EngineFactory method createJournaledEngine.

public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
    try {
        JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
        suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        suits.add(new IDEF0PluginProvider());
        Properties ps = getPropeties();
        if (ps != null) {
            String suitNames = ps.getProperty("AdditionalSuits");
            if (suitNames != null)
                PluginFactory.loadAdditionalSuits(suitNames, suits);
            canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
        }
        suits.addAll(getAdditionalSuits());
        createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
        factory = createPluginFactory(suits);
        String prefix = "ramus_";
        impl = new ServerIEngineImpl(0, template, prefix, factory);
        accessor = impl.getAccessor();
        persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
        persistentFactory.rebuild();
        checkIfGroupsExists();
        Engine result;
        Journaled journaled;
        if (cachedData == null) {
            JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
            result = journaledEngine2;
            journaled = journaledEngine2.getJournal();
        } else {
            JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

                @Override
                protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
                }
            };
            journaled = engine.getJournal();
            CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
            for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
            result = cachedEngine;
        }
        EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
        log = new Log(result, journaled) {

            protected Event createEvent(String type, UpdateEventCallback callback) {
                String user = "admin";
                if (impl.getServerAccessRules() != null)
                    user = impl.getServerAccessRules().getUser().getLogin();
                long id = impl.nextValue("qualifiers_log_seq");
                return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
            }
        };
        log.addExtension(engineLogExtension);
        log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) UniversalPersistentFactory(com.ramussoft.core.persistent.UniversalPersistentFactory) EngineLogExtension(com.ramussoft.common.logger.EngineLogExtension) Log(com.ramussoft.common.logger.Log) ILog(com.ramussoft.common.logger.ILog) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) Properties(java.util.Properties) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) UpdateEventCallback(com.ramussoft.common.logger.UpdateEventCallback) Journaled(com.ramussoft.common.journal.Journaled) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) Event(com.ramussoft.common.logger.Event) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin) PersistentsPlugin(com.ramussoft.core.persistent.PersistentsPlugin) AbstractPlugin(com.ramussoft.common.AbstractPlugin)

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