jadex.micro.tutorial.ChatE5Agent 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.tutorial;
import java.util.Map;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.clock.IClockService;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentArgument;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.Argument;
import jadex.micro.annotation.Arguments;
import jadex.micro.annotation.Binding;
import jadex.micro.annotation.Description;
import jadex.micro.annotation.Implementation;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
import jadex.micro.annotation.RequiredService;
import jadex.micro.annotation.RequiredServices;
/**
* Chat micro agent with a .
*/
@Description("This agent provides a basic chat service.")
@Agent
@ProvidedServices(@ProvidedService(type=IChatService.class,
implementation=@Implementation(value=ChatServiceD5.class)))
@RequiredServices({
@RequiredService(name="clockservice", type=IClockService.class,
binding=@Binding(scope=Binding.SCOPE_PLATFORM)),
@RequiredService(name="chatservices", type=IChatService.class, multiple=true,
binding=@Binding(dynamic=true, scope=Binding.SCOPE_GLOBAL)),
@RequiredService(name="regservice", type=IRegistryServiceE3.class)
})
@Arguments({
@Argument(name="nickname", clazz=String.class, defaultvalue="\"Willi\""),
@Argument(name="partner", clazz=String.class)
})
public class ChatE5Agent
{
/** The agent. */
@Agent
protected IInternalAccess agent;
/** The nickname. */
@AgentArgument
protected String nickname;
/** The partner's nickname. */
@AgentArgument
protected String partner;
/**
* Execute the functional body of the agent.
* Is only called once.
*/
@AgentBody
public void executeBody()
{
IFuture regservice = agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredService("regservice");
regservice.addResultListener(new DefaultResultListener()
{
public void resultAvailable(final IRegistryServiceE3 rs)
{
rs.register(agent.getComponentIdentifier(), nickname);
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(10000, new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
rs.getChatters().addResultListener(new DefaultResultListener