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

jadex.micro.testcases.subresults.ResultProducerAgent 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.testcases.subresults;

import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.component.IExecutionFeature;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;

@Agent
@Results(@Result(name="res", clazz=int.class))
public class ResultProducerAgent
{
	@Agent
	protected IInternalAccess agent;
	
	/**
	 * 
	 */
	@AgentBody
	public void body()
	{
		final long delay = 1000;
		final int[] cnt = new int[1];
		agent.getComponentFeature(IExecutionFeature.class).waitForDelay(delay, new IComponentStep()
		{
			public IFuture execute(IInternalAccess ia)
			{
				agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("res", Integer.valueOf(cnt[0]));
				if(cnt[0]++<5)
				{
					agent.getComponentFeature(IExecutionFeature.class).waitForDelay(delay, this);
				}
				else
				{
					agent.killComponent();
				}
				return IFuture.DONE;
			}
		});
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy