Bouncefile and Bounce (pattern 1)
Bouncefile is a regular system file thread that picks up a file and routes it to Bounce. This is a Java thread that invokes a piece of Java code to process the message and reply. It then gets routed back to Bouncefile with results appended to an output file.
See the Samples Walkthrough video for a more detailed depiction of message flow.
This Bounce.ini shows how it is configured:
[DRIVER]
DRIVERTYPE = class # A class type or application type driver
CLASS = com/infor/cloverleaf/javadriver/samples/cloverleafmessagebounce/Bounce
# The class loaded for method calls that start/stop things
RUNMETHOD = doMsg # all classes that override FromCloverleafLink must set RUNMETHOD to doMsg
RUNARG = # Run method user argument
STARTMETHOD = doStart
DELAY = 0 # Delay for Java debugger attach in seconds
WRTOKMETHOD = isWriteOk # Called when engine main checks to see if ok to wrt message……
In this example:
- The CLASS entry shows where the Java code is located that processes the message from the system engine in Bounce.
- The
DRIVERTYPE (=class)
indicates that thedoStart()
method in the class returns. ADRIVERTYPE (=application)
indicates the method does not return.
Additionally, the Bounce sample demonstrates the WRTOKMETHOD
field in the .ini file. In the Java source code the matching isWriteOk
method writes a log entry and returns true.
This is a segment of the Java code in Bounce.java, which splits the incoming message and builds many reply messages.
package com.infor.cloverleaf.javadriver.samples.cloverleafmessagebounce;
...
public class Bounce extends FromCloverleafLink {
private static final Logger logger = Logger.getLogger(Bounce.class.getName());
private boolean firstRun = true;
@Override
public List<ToCloverleafMessage> processMessageFromCloverleaf(FromCloverleafMessage fromCloverleafMessage) throws BadDataException, RetryException {
try{
if (fromCloverleafMessage.getDriverControl().contains(ToCloverleafLink.DRIVERCONTROL_CALLBACKUNIQUE)){
List<ToCloverleafMessage> response = new ArrayList<ToCloverleafMessage>(1);
response.add(new ToCloverleafMessage(null,fromCloverleafMessage.getDriverControl(),MessageTypeEnum.DATA, "CALLBACKJAVA",null,"bouncing back unique- " + fromCloverleafMessage.getMessage()));
logger.fine("bouncing back a " + ToCloverleafLink.DRIVERCONTROL_CALLBACKUNIQUE + " message");
return response;
}else if (fromCloverleafMessage.getDriverControl().contains(ToCloverleafLink.DRIVERCONTROL_CALLBACKREGISTERED)){
List<ToCloverleafMessage> response = new ArrayList<ToCloverleafMessage>(1);
response.add(new ToCloverleafMessage(null,fromCloverleafMessage.getDriverControl(),MessageTypeEnum.DATA, "CALLBACKJAVA",null,"bouncing back registered- " + fromCloverleafMessage.getMessage()));
logger.fine("bouncing back a " + ToCloverleafLink.DRIVERCONTROL_CALLBACKREGISTERED + " message");
return response;
}else if (fromCloverleafMessage.getDriverControl().contains("MYCALLBACK")){
List<ToCloverleafMessage> response = new ArrayList<ToCloverleafMessage>(1);
response.add(new ToCloverleafMessage(null,fromCloverleafMessage.getDriverControl(),MessageTypeEnum.DATA, "MYCALLBACK",null,"forwarding custom callback message- " + fromCloverleafMessage.getMessage()));
logger.fine("forwarding a MYCALLBACK message");
return response;
}else{
// FILE message
String request = fromCloverleafMessage.getMessage();
String[] requestFields = request.split(" ", 2);
int numberOfMessages = Integer.parseInt(requestFields[0]);
List<ToCloverleafMessage> response = new ArrayList<ToCloverleafMessage>(numberOfMessages);
for (int i=0; i<numberOfMessages; i++){
response.add(new ToCloverleafMessage(null, null, MessageTypeEnum.DATA, "FILE", null, "bounce " + i + " " + requestFields[1]));
}
// test exception for use in debugger to verify retry/baddata exceptions
boolean retry=false;
boolean baddata=false;
boolean ignore=false;
if(retry) throw new RetryException("test retry exception");
if(baddata) throw new BadDataException("test bad data exception");
if(ignore) throw new IgnorableException("test ignorable exception");
logger.fine("bouncing back " + numberOfMessages + " FILE message(s)");
return response;
}
}catch (RetryException e){
// just rethrow these ones
throw e;
}catch (IgnorableException e){
// just rethrow these ones
throw e;
}catch (Exception e){
// we'll assume any exception (BadData or otherwise) here is due to bad data since this is a very simple procedure
throw new BadDataException("caught exception in processMessageFromCloverleaf: " + e.getLocalizedMessage(), e);
}
}
This sample code:
- Defines a class is
defined that extends
FromCloverleafLink.
- Overrides the
processMessageFromCloverleaf()
method, which has a parameter,FromCloverleafMessage
, that represents the message object from the system engine in this thread. - Calls
getMessage()
to get the String representation of the message. - Formulates a list of
ToCloverleafMessage
objects as a reply back into the engine. - Optionally throws
RetryException
to make the system engine resend the message. - Optionally throws
IgnorableException
to indicate to ignore the error and treat the message as sent successfully. - Optionally throws
BadDataException
to indicate an error and routes the message to the error database. - Does "fine" level logging, which by default does not show up in system logs. See Logging in Java Driver for how to configure the logger to show fine level logging in the log files.
This sample splits the incoming message and builds many reply messages. For example, if the input message (a file dropped at the Bouncefile thread) has this content:
The number at the start of this line indicates how many messages the bouncejava thread should bounce back.
Then, the reply messages back to the Bouncefile thread is appended to the output file.