use of org.apache.commons.jexl2.JexlEngine in project opennms by OpenNMS.
the class IpInterfaceScan method isIpMatching.
protected static boolean isIpMatching(final InetAddress ip, final String expr) {
try {
JexlEngine parser = new JexlEngine();
Expression e = parser.createExpression(generateExpr(expr));
final Map<String, Object> context = new HashMap<String, Object>();
context.put("iplike", IPLike.class);
context.put("ipaddr", ip.getHostAddress());
Boolean out = (Boolean) e.evaluate(new MapContext(context));
return out;
} catch (Exception e) {
LOG.error("Can't process rule '{}' while checking IP {}.", expr, ip, e);
return false;
}
}
use of org.apache.commons.jexl2.JexlEngine in project jmeter by apache.
the class Jexl2Function method threadFinished.
@Override
public void threadFinished() {
JexlEngine engine = threadLocalJexl.get();
if (engine != null) {
engine.clearCache();
threadLocalJexl.remove();
}
}
use of org.apache.commons.jexl2.JexlEngine in project jmeter by apache.
the class Jexl2Function method getJexlEngine.
/**
* Get JexlEngine from ThreadLocal
* @return JexlEngine
*/
private static JexlEngine getJexlEngine() {
JexlEngine engine = threadLocalJexl.get();
if (engine == null) {
engine = new JexlEngine();
engine.setCache(512);
engine.setLenient(false);
engine.setSilent(false);
threadLocalJexl.set(engine);
}
return engine;
}
use of org.apache.commons.jexl2.JexlEngine in project jmeter by apache.
the class Jexl3Function method getJexlEngine.
/**
* Get JexlEngine from ThreadLocal
* @return JexlEngine
*/
private static JexlEngine getJexlEngine() {
JexlEngine engine = threadLocalJexl.get();
if (engine == null) {
engine = new JexlBuilder().cache(512).silent(true).strict(true).debug(false).create();
threadLocalJexl.set(engine);
}
return engine;
}
use of org.apache.commons.jexl2.JexlEngine in project newts by OpenNMS.
the class ResultDescriptor method expression.
public ResultDescriptor expression(String label, String expression) {
final JexlEngine je = new JexlEngine();
final Expression expr = je.createExpression(expression);
final String[] labels = getLabels().toArray(new String[0]);
CalculationFunction evaluate = new CalculationFunction() {
private static final long serialVersionUID = -3328049421398096252L;
@Override
public double apply(double... ds) {
JexlContext jc = new MapContext();
for (int i = 0; i < labels.length; i++) {
jc.set(labels[i], ds[i]);
}
return ((Number) expr.evaluate(jc)).doubleValue();
}
};
return calculate(label, evaluate, labels);
}
Aggregations