jadex.micro.tutorial.ChatD1Agent 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.Collection;
import java.util.Iterator;
import jadex.bridge.IInternalAccess;
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.AgentBody;
import jadex.micro.annotation.AgentFeature;
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 provides a basic chat service.
*/
@Description("This agent provides a basic chat service.")
@Agent
@ProvidedServices(@ProvidedService(type=IChatService.class,
implementation=@Implementation(ChatServiceD1.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_PLATFORM))
})
public class ChatD1Agent
{
/** The underlying micro agent. */
@Agent
protected IInternalAccess agent;
/** The required services feature. */
@AgentFeature
protected IRequiredServicesFeature requiredServicesFeature;
/**
* Execute the functional body of the agent.
* Is only called once.
*/
@AgentBody
public void executeBody()
{
IFuture> chatservices = requiredServicesFeature.getRequiredServices("chatservices");
chatservices.addResultListener(new DefaultResultListener>()
{
public void resultAvailable(Collection result)
{
for(Iterator it=result.iterator(); it.hasNext(); )
{
IChatService cs = it.next();
cs.message(agent.getComponentIdentifier().getName(), "Hello");
}
}
});
}
}