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();
}
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");
}
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;
}
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();
}
}
}
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();
}
}
}
Aggregations