Search in sources :

Example 16 with BSFManager

use of org.apache.bsf.BSFManager in project groovy by apache.

the class BSFTest method setUp.

protected void setUp() throws Exception {
    BSFManager.registerScriptingEngine("groovy", ENGINE.getName(), new String[] { "groovy", "gy" });
    manager = new BSFManager();
}
Also used : BSFManager(org.apache.bsf.BSFManager)

Example 17 with BSFManager

use of org.apache.bsf.BSFManager 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)

Example 18 with BSFManager

use of org.apache.bsf.BSFManager in project jmeter by apache.

the class BSFAssertion method getResult.

@Override
public AssertionResult getResult(SampleResult response) {
    AssertionResult result = new AssertionResult(getName());
    BSFManager mgr = null;
    try {
        mgr = getManager();
        mgr.declareBean("SampleResult", response, SampleResult.class);
        mgr.declareBean("AssertionResult", result, AssertionResult.class);
        processFileOrScript(mgr);
        result.setError(false);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script {}", e.toString());
        }
        result.setFailure(true);
        result.setError(true);
        result.setFailureMessage(e.toString());
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
    return result;
}
Also used : BSFException(org.apache.bsf.BSFException) BSFManager(org.apache.bsf.BSFManager)

Example 19 with BSFManager

use of org.apache.bsf.BSFManager in project jmeter by apache.

the class BSFPostProcessor method process.

@Override
public void process() {
    BSFManager mgr = null;
    try {
        mgr = getManager();
        processFileOrScript(mgr);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script: {}", e.toString());
        }
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
}
Also used : BSFException(org.apache.bsf.BSFException) BSFManager(org.apache.bsf.BSFManager)

Example 20 with BSFManager

use of org.apache.bsf.BSFManager in project jmeter by apache.

the class BSFListener method sampleOccurred.

@Override
public void sampleOccurred(SampleEvent event) {
    BSFManager mgr = null;
    try {
        mgr = getManager();
        if (mgr == null) {
            log.error("Problem creating BSF manager");
            return;
        }
        mgr.declareBean("sampleEvent", event, SampleEvent.class);
        SampleResult result = event.getResult();
        mgr.declareBean("sampleResult", result, SampleResult.class);
        processFileOrScript(mgr);
    } catch (BSFException e) {
        if (log.isWarnEnabled()) {
            log.warn("Problem in BSF script. {}", e.toString());
        }
    } finally {
        if (mgr != null) {
            mgr.terminate();
        }
    }
}
Also used : BSFException(org.apache.bsf.BSFException) SampleResult(org.apache.jmeter.samplers.SampleResult) BSFManager(org.apache.bsf.BSFManager)

Aggregations

BSFManager (org.apache.bsf.BSFManager)21 BSFException (org.apache.bsf.BSFException)8 Test (org.junit.Test)8 BSFEngine (org.apache.bsf.BSFEngine)3 FileInputStream (java.io.FileInputStream)2 List (java.util.List)2 Vector (java.util.Vector)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 StringTokenizer (java.util.StringTokenizer)1 LogPreservingThreadFactory (org.opennms.core.concurrent.LogPreservingThreadFactory)1 Engine (org.opennms.netmgt.config.scriptd.Engine)1 StartScript (org.opennms.netmgt.config.scriptd.StartScript)1