CallbackJava/Bounce (pattern 3.b Registered Callback)
CallbackJava
and MyCallback
, along with Bounce, demonstrate pattern 3.b.
CallbackJava
is a Java thread that
sends a message into the system engine. It then processes the reply using registered
callback pattern 3.b, and another form of manual callback.
This sample shows the use of a registered callback. This is different from unique callback. If the thread that initiated the request and registered the callback is restarted before the reply comes back from another thread, then the handling of that reply is not lost. The unique callback does not guarantee this behavior.
See the Samples "Walkthrough" video for a more detailed depiction of message flow.
CallbackJava
is a Java thread that
runs its Java application independently. In this example, CallMeBack.java does not start a Tomcat. In its doStart()
method:
- Instantiates two
anonymous classes that implement the
CallbackInterface
interface. - Registers the two
instances as callbacks under the names
red
andblue
, respectively. - Goes into a loop to
periodically wake up and send a message into the system engine with registered
callbacks
red
andblue
. These are based on an index that is incremented in each iteration of the loop. These messages are routed to the Bounce thread, which then bounces it back as a reply to the messages.In the same loop, it also:
- Sends a message using the unique callback, whose usage is already covered in a previous sample.
- Sends a message
(3.c) to show that the users can have a custom or manual callback in
another thread,
MyCallback
.
- It also demonstrates
TIMEMETHOD
in the .ini. The time delay forTIMEMETHOD
is specified in the NetConfig GUI. Every time that time delay expires (or the Advanced Scheduling algorithm, if enabled, fires an event), the corresponding method is called (doTimeEvent
, in this case). This sample method logs the event. There is a commented out field SECONDS which can override the time delay specified in NetConfig.
[DRIVER]
DRIVERTYPE = application # application means that the doStart method is not expected to return, so a separate thread is created to run it forever
CLASS = com/infor/cloverleaf/javadriver/samples/callback/CallMeBack # The class loaded for method calls that start/stop things
STARTMETHOD = doStart # Test that it calls it
STARTARG = # No arg required
STOPMETHOD = doStop # Do java clean up
STOPARG = # No arg required
RUNMETHOD = doReply # All classes that override ToCloverleafLink and expect reply messages from Cloverleaf into java must set this to doReply
RUNARG = # Run method user argument
TIMEMETHOD = doTimeEvent # method that runs every so often as configured in NetConfig
TIMEMETHODARG = myTimerArg # time method user argument
#SECONDS = 10 # uncomment this to override the time interval for TIMEMETHOD specified in NetConfig
Bounce is a Java thread shared with a previous sample that bounces
back the messages coming from CallbackJava
as their
replies. It selectively passes messages onto another thread, MyCallback
. This demonstrates that you can design your own custom, or
manual, callback behavior in another thread, MyCallback
.
From the API’s perspective, this scenario does not involve any of the callbacks that are mentioned above. Messages are sent to the engine without waiting for the reply, pattern 3.c.