jadex.micro.examples.ping.EchoAgent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-micro Show documentation
Show all versions of jadex-applications-micro Show documentation
The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.
package jadex.micro.examples.ping;
import java.util.HashMap;
import java.util.Map;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IMessageFeature;
import jadex.bridge.fipa.SFipa;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.types.message.MessageType;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.Implementation;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
/**
* Sends back the same message it received.
*/
@Agent
@ProvidedServices(@ProvidedService(type=IEchoService.class,
implementation=@Implementation(expression="$pojoagent")))
@Service
public class EchoAgent implements IEchoService
{
/** The micro agent class. */
@Agent
protected IInternalAccess agent;
/**
* Send same message back to the sender.
* @param msg The message.
* @param mt The message type.
*/
public void messageArrived(Map msg, MessageType mt)
{
Map reply = new HashMap(msg);
IComponentIdentifier sender = (IComponentIdentifier)msg.get(SFipa.SENDER);
reply.put(SFipa.SENDER, agent.getComponentIdentifier());
reply.put(SFipa.RECEIVERS, new IComponentIdentifier[]{sender});
agent.getComponentFeature(IMessageFeature.class).sendMessage(reply, mt);
}
}