Skip to main content
Version: 5.1.1 (Unmaintained)

Listener

The Listener interface receives run-level and descriptor execution callbacks. Actions invoke onBeforeExecution(Descriptor) and onAfterExecution(Descriptor) around their own execution boundary. The runner invokes run-level and discovery callbacks.

import org.paramixel.api.Listener;

Callbacks​

MethodDescription
initialize(Configuration configuration)Invoked once before the run begins; allows listeners to configure themselves
onRunStarted()Invoked once before run discovery begins
onDiscoveryStarted()Invoked after onRunStarted(), before the discovery phase
onDiscoveryCompleted(Descriptor root)Invoked after discovery creates the descriptor tree
onBeforeExecution(Descriptor descriptor)Invoked by an action immediately before its execution logic runs
onAfterExecution(Descriptor descriptor)Invoked by an action after its descriptor reaches a terminal status
onRunCompleted(Result result)Invoked once after the run completes

All methods have default no-op implementations. Implement only the callbacks you need.

Default listener chain​

Listener listener = Listener.defaultListener();
Listener listener = Listener.defaultListener(configuration);

The default listener chain includes:

ComponentDescription
StatusListenerPrints status updates to the console with ANSI support
SummaryListenerPrints a tree summary of the run result
Report listener (optional)Writes a report file when paramixel.report.file is configured; format determined by file extension

The report listener is selected based on the paramixel.report.file extension:

ExtensionListenerFormat
.jsonJsonReportListenerJSON with tree hierarchy
.xmlXmlReportListenerXML with tree hierarchy
.html / .htmHtmlReportListenerSelf-contained HTML
OtherReportListenerPlain text tree summary

When paramixel.report.file is unset, the chain includes only StatusListener and SummaryListener. The chain is wrapped in SafeListener to prevent listener exceptions from affecting the run.

StatusListener and SummaryListener respect the paramixel.listener.exclude configuration key, which controls which output sections are suppressed.

Custom listener​

Listener customListener = new Listener() {
@Override
public void onRunStarted() {
System.out.println("Run started");
}

@Override
public void onDiscoveryCompleted(Descriptor root) {
System.out.println("Discovered " + root.children().size() + " root actions");
}

@Override
public void onAfterExecution(Descriptor descriptor) {
var meta = descriptor.metadata();
if (!meta.status().isPassed()) {
System.out.println(" FAILED: " + meta.name());
}
}

@Override
public void onRunCompleted(Result result) {
System.out.println("Run completed: " + result.status().name());
}
};

Runner runner = Runner.builder()
.listener(customListener)
.build();

Callback lifecycle​

The callbacks occur in this order:

initialize(configuration)
onRunStarted()
onDiscoveryStarted()
onDiscoveryCompleted(root)
[for each descriptor execution:]
onBeforeExecution(descriptor)
onAfterExecution(descriptor)
onRunCompleted(result)

See also​