All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jadex.micro.quickstart.TimeUserAgent Maven / Gradle / Ivy

Go to download

The Jadex micro applications package contains several example applications, benchmarks and testcases using micro agents.

There is a newer version: 4.0.267
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy