Search in sources :

Example 1 with StartScript

use of org.opennms.netmgt.config.scriptd.StartScript in project opennms by OpenNMS.

the class Executor method start.

public synchronized void start() {
    for (final Engine engine : m_config.getEngines()) {
        LOG.debug("Registering engine: {}", engine.getLanguage());
        String[] extensions = null;
        if (engine.getExtensions().isPresent()) {
            StringTokenizer st = new StringTokenizer(engine.getExtensions().get());
            extensions = new String[st.countTokens()];
            int j = 0;
            while (st.hasMoreTokens()) {
                extensions[j++] = st.nextToken();
            }
        }
        BSFManager.registerScriptingEngine(engine.getLanguage(), engine.getClassName(), extensions);
    }
    m_scriptManager = new BSFManager();
    m_scriptManager.registerBean("log", LOG);
    // Run all start scripts
    for (final StartScript startScript : m_config.getStartScripts()) {
        if (startScript.getContent().isPresent()) {
            try {
                m_scriptManager.exec(startScript.getLanguage(), "", 0, 0, startScript.getContent().get());
            } catch (BSFException e) {
                LOG.error("Start script failed: " + startScript, e);
            }
        } else {
            LOG.warn("Start script has no script content: " + startScript);
        }
    }
    // Start the thread pool
    m_executorService = Executors.newFixedThreadPool(1, new LogPreservingThreadFactory("Scriptd-Executor", 1));
    // started
    try {
        m_broadcastEventProcessor = new BroadcastEventProcessor(this);
    } catch (Throwable e) {
        LOG.error("Failed to setup event reader", e);
        throw new UndeclaredThrowableException(e);
    }
    LOG.debug("Scriptd executor started");
}
Also used : StringTokenizer(java.util.StringTokenizer) StartScript(org.opennms.netmgt.config.scriptd.StartScript) BSFException(org.apache.bsf.BSFException) LogPreservingThreadFactory(org.opennms.core.concurrent.LogPreservingThreadFactory) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) BSFManager(org.apache.bsf.BSFManager) Engine(org.opennms.netmgt.config.scriptd.Engine)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 StringTokenizer (java.util.StringTokenizer)1 BSFException (org.apache.bsf.BSFException)1 BSFManager (org.apache.bsf.BSFManager)1 LogPreservingThreadFactory (org.opennms.core.concurrent.LogPreservingThreadFactory)1 Engine (org.opennms.netmgt.config.scriptd.Engine)1 StartScript (org.opennms.netmgt.config.scriptd.StartScript)1