Callback
From Indus Communities
The CallBack coordination style differs from the Master Worker style with respect to only one aspect, i.e., the block of business logic written in a CallBack method call is executed only if the result of the callback method call is non erroneous.
Syntax:
Callback(agent | component.methodName(param_list); variable of
method’s return type)
{
// business logic
}
where,
- agent and component are instances of type Agent and Component
Unlike the Broadcast, Blackboard/Agenda or Parallel Pipe styles of coordination, using Callback does not identify the responder's role and id since invoking a single, and not multiple or arrays of, agent or component instances is possible in Callback.
public Agent CallbackAgent
{
public void setValue(int x);
public int getValue();
public void incrValue();
}
Definition file : CallbackAgent.indus
public class CallbackClass implements CallbackAgent
{
Context{
setServantType("USER");
}
public int m_value = 0;
public int getValue()
{
return m_value;
}
public void setValue(int v)
{
m_value = v;
}
public void incrValue()
{
m_value++;
}
public static void main(String [] args)
{
try
{
CallbackClass m = newType CallbackClass("cb1");
int value = 0;
Callback(m.getValue();value)
{
System.out.println("value = " + value);
}
Callback(m.setValue(100);) {}
Callback(m.getValue();value)
{
System.out.println("value = " + value);
}
Callback(m.incrValue();) {}
Callback(m.getValue();value)
{
System.out.println("value = " + value);
}
Callback(m.incrValue();) {}
Callback(m.getValue();value)
{
System.out.println("value = " + value);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Implementation file : CallbackClass.indus
