Java Task
Java Task dynamically compiles and executes trusted Java code inside a task pipeline, reads and writes the execution context, and returns a boolean that decides whether child tasks should continue.
Add compact Java logic to a processing pipeline
Use Java Task when built-in tasks are almost enough, but a pipeline needs a small custom rule, context enrichment step, debug probe, or integration glue. The task receives engine and ctx, then returns true to continue downstream processing or false to stop the current branch.
The code runs inside the agent JVM with access to the runtime classpath and application services. Treat it as trusted code, keep it fast, and move large or shared logic into a normal module when it becomes long-lived.
Name the task
Set Title to the role of the snippet, for example filter low confidence events, enrich alarm context, debug upstream variables, or choose recording branch.
Add imports and helpers only when needed
Use Imports for extra Java imports and Class properties for helper methods, constants, or small bounded caches. Default imports already cover common Banalytics, IO, collection, time, network, and path APIs.
Return true or false intentionally
Java code is the generated method body. Return true when downstream child tasks should run; return false when this context should stop at the Java Task.
Configuration parameters
| Parameter | Required | Description | Default |
|---|---|---|---|
Title | Yes | Display name of the task. Use a name that identifies the custom pipeline role. | None |
Imports | Optional | Additional Java import statements compiled into the generated task class. | Empty |
Class properties | Optional | Additional class-level fields or helper methods. Use this for constants, helper functions, compiled patterns, or small bounded state shared by executions. | Empty |
Java code | Yes | Body of the generated boolean method. It receives engine and ctx, can read/write context variables, and must return true or false. | Print context and return true |
Your snippet becomes a generated Java class
Banalytics wraps configured imports, class-level helpers, and the method body into a generated class, compiles it on task start, caches it under java-cache, and calls it on each task execution.
The generated method returns a boolean. true continues the child task tree; false stops the remaining downstream tasks for the current context.
Context access
Read values from upstream tasks and write values that later tasks or actions can use.
Pipeline control
Return true for pass-through behavior, or false to filter the branch for the current execution.
In-process code
The code shares JVM resources, permissions, classpath, and failure behavior with the agent.
Generated class template
package com.banalytics.box.module.system.script.generated;
import com.banalytics.box.module.*;
import com.banalytics.box.module.events.*;
import java.io.*;
import java.util.*;
import java.time.*;
import java.net.*;
import java.nio.file.*;
{{imports}}
public class JavaTask_{{hash}} {
{{classProperties}}
public static boolean execute(BoxEngine engine, ExecutionContext ctx) throws Exception {
{{javaCode}}
}
}
Use Java for small task-pipeline decisions
Pipeline flow
Pass-through custom logic
Return true when the next child task should run. Use this for small calculations, logging, or context enrichment that should not interrupt downstream processing.
Conditional pipeline filter
Read values from ctx and return false when downstream tasks should be skipped, for example when confidence, schedule, severity, or custom state does not match the current rule.
Context data
Context enrichment
Add calculated labels, normalized event severity, selected file paths, thresholds, timestamps, or routing decisions to the execution context for later tasks or actions.
Context inspection
Inspect context variables while building a pipeline to learn what upstream tasks provide. Remove noisy debug output after tuning because the task can run very frequently.
Integration and prototyping
Lightweight integration glue
Use engine to access Banalytics services, components, or task state when a built-in task is too rigid but a full custom module would be excessive.
Custom event or data preparation
Transform upstream detector data into a shape expected by a downstream task, Java Action, SQL Action, Send Email, or external integration.
Fast prototype before a module
Validate a business rule or data transformation quickly, then move stable logic into a normal module when it becomes large, shared, or needs tests and versioned deployment.
Operational notes
Boolean return is mandatory
Java code must return a boolean. Missing or inconsistent returns will cause compilation or runtime failures.
Code changes restart the task
Changes to Imports, Class properties, or Java code restart the task and trigger recompilation.
JDK is required
The agent must run with a JDK that provides the system Java compiler, not a JRE-only runtime.
Keep code fast
Avoid blocking calls, long sleeps, heavy CPU work, unbounded loops, large memory allocations, and slow network calls. Slow code can reduce FPS, delay events, or block child tasks.
Exceptions affect processing
Exceptions thrown from the snippet are treated as processing errors and can move the task into error handling according to its restart policy.
Restrict editing rights
Java Task executes trusted code with access to the Banalytics runtime. Do not paste untrusted snippets, and restrict who can edit or start tasks that execute custom Java.