jadex.micro.quickstart.TimeUserAgent 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.quickstart;
import jadex.base.PlatformConfiguration;
import jadex.base.Starter;
import jadex.bridge.service.IService;
import jadex.commons.future.ISubscriptionIntermediateFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentService;
import jadex.micro.annotation.Binding;
import jadex.micro.annotation.RequiredService;
import jadex.micro.annotation.RequiredServices;
/**
* Simple agent that uses globally available time services.
*/
@Agent
@RequiredServices(@RequiredService(name="timeservices", type=ITimeService.class, multiple=true,
binding=@Binding(scope=Binding.SCOPE_GLOBAL)))
public class TimeUserAgent
{
/**
* The time services are searched and added at agent startup.
*/
@AgentService(isquery=true)
public void addTimeService(ITimeService timeservice)
{
ISubscriptionIntermediateFuture subscription = timeservice.subscribe();
while(subscription.hasNextIntermediateResult())
{
String time = subscription.getNextIntermediateResult();
String platform = ((IService)timeservice).getServiceIdentifier().getProviderId().getPlatformName();
System.out.println("New time received from "+platform+" at "+timeservice.getLocation()+": "+time);
}
}
/**
* Start a Jadex platform and the TimeUserAgent.
*/
public static void main(String[] args)
{
PlatformConfiguration config = PlatformConfiguration.getMinimalRelayAwareness();
config.addComponent(TimeUserAgent.class.getName()+".class");
Starter.createPlatform(config).get();
}
}