9.47.5 Java Agent Example
The sample workflow is a simple real time workflow that contains a pulse agent that periodically sends pulses of data into the Java agent, where the Java codes will debug the input and route it back out to the Analysis agent.
To generate a Java development project to run this workflow, please refer to 1. Java Agent Setup Guide. For more information on how to utilize the Java Function Blocks, refer to 2. Java Function Blocks and Java Functions, refer to 3. Java General Functions. The code used in the example workflow is shown below:
HelloworldAgent.java
package com.mediationzone.java_agent; import com.digitalroute.mz.java.agents.RealtimeAgent; import com.digitalroute.mz.java.agents.api.AgentEnv; import com.digitalroute.mz.java.agents.api.ConfigDefinition; import com.digitalroute.mz.java.agents.UDRInterface; import java.util.Map; public class HelloworldAgent implements RealtimeAgent { @Override public void configure(ConfigDefinition cfg) { cfg.defineOutput(byte[].class, UDRInterface.class); //cfg.defineOutput(Your_UDR.class); //cfg.defineOutput("routename", Your_UDR.class); } @Override public void deinitialize(AgentEnv env) throws Exception { } @Override public void init(AgentEnv env, Map<String,String> userdata) throws Exception { } @Override public void consume(UDRInterface input, AgentEnv env) throws Exception { // try { // env.debug(input); // // Your_UDR newUdr = env.createUDR(Your_UDR.class); // // Your_UDR udr = (Your_UDR) input; // } catch (Exception e) { // throw new RuntimeException(e); // } // env.debug("Hello World"); env.route(input); } @Override public void consume(byte[] input, AgentEnv env) throws Exception { env.debug("Hello World"); env.route(input); } @Override public Object getMIM(String mimName) { return null; } }
Next: