Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.intergral.deep.agent.tracepoint.evaluator;
package com.intergral.deep.agent.api.plugin;

import com.intergral.deep.agent.api.plugin.IEvaluator;
import java.util.Map;

/**
* This allows for common handling for object to boolean expressions.
*/
public abstract class AbstractEvaluator implements IEvaluator {

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2023 Intergral GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.intergral.deep.agent.api.plugin;

import java.util.Map;

/**
* This type allows the evaluator to be loaded only if it is needed. ie. if we have no watches or conditions there is no need for an
* evaluator.
*/
public class LazyEvaluator extends AbstractEvaluator {

private static final Exception NO_EVALUATOR_EXCEPTION = new RuntimeException(
"No evaluator available.");
private final IEvaluatorLoader loader;
private IEvaluator evaluator;

public LazyEvaluator(final IEvaluatorLoader loader) {
this.loader = loader;
}

private IEvaluator load() {
if (this.evaluator == null) {
try {
this.evaluator = this.loader.load();
} catch (Exception e) {
this.evaluator = new AbstractEvaluator() {
@Override
public Object evaluateExpression(final String expression, final Map<String, Object> values) throws Throwable {
throw NO_EVALUATOR_EXCEPTION;
}
};
}
}
return this.evaluator;
}

@Override
public Object evaluateExpression(final String expression, final Map<String, Object> values) throws Throwable {
return load().evaluateExpression(expression, values);
}

public interface IEvaluatorLoader {

IEvaluator load();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package com.intergral.deep.agent.tracepoint.cf;

import com.intergral.deep.agent.tracepoint.evaluator.AbstractEvaluator;
import com.intergral.deep.agent.api.plugin.AbstractEvaluator;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.intergral.deep.agent.tracepoint.evaluator;

import com.intergral.deep.agent.api.plugin.AbstractEvaluator;
import com.intergral.deep.agent.api.plugin.IEvaluator;
import java.lang.reflect.Method;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.intergral.deep.agent.Utils;
import com.intergral.deep.agent.api.plugin.IEvaluator;
import com.intergral.deep.agent.api.plugin.LazyEvaluator;
import com.intergral.deep.agent.push.PushService;
import com.intergral.deep.agent.settings.Settings;
import com.intergral.deep.agent.tracepoint.TracepointConfigService;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static void callBackCF(final List<String> bpIds,
final int lineNo,
final Map<String, Object> variables) {
try {
final IEvaluator evaluator = CFUtils.findCfEval(variables);
final IEvaluator evaluator = new LazyEvaluator(() -> CFUtils.findCfEval(variables));
commonCallback(bpIds, filename, lineNo, variables, evaluator, CFFrameProcessor::new);
} catch (Throwable t) {
LOGGER.debug("Unable to process tracepoint {}:{}", filename, lineNo, t);
Expand All @@ -109,7 +110,7 @@ public static void callBack(final List<String> bpIds,
final int lineNo,
final Map<String, Object> variables) {
try {
final IEvaluator evaluator = EvaluatorService.createEvaluator();
final IEvaluator evaluator = new LazyEvaluator(EvaluatorService::createEvaluator);
commonCallback(bpIds, filename, lineNo, variables, evaluator, FrameProcessor::new);
} catch (Throwable t) {
LOGGER.debug("Unable to process tracepoint {}:{}", filename, lineNo, t);
Expand Down