jadex.micro.testcases.recfutures.AAgent 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.testcases.recfutures;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.annotation.Service;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IIntermediateFuture;
import jadex.commons.future.IntermediateFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
@Agent
@Service
@ProvidedServices(@ProvidedService(type=IAService.class))
public class AAgent implements IAService
{
@Agent
protected IInternalAccess agent;
/**
*
*/
public IFuture> methodA()
{
final Future> ret1 = new Future>();
IComponentStep step1 = new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
final Future ret2 = new Future();
ret1.setResult(ret2);
IComponentStep step2 = new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
ret2.setResult("hello");
return IFuture.DONE;
}
};
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(100, step2);
return IFuture.DONE;
}
};
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(100, step1);
return ret1;
}
/**
* Test method with intermediate future in future.
*/
public IFuture> methodB()
{
final Future> ret1 = new Future>();
IComponentStep step1 = new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
final IntermediateFuture ret2 = new IntermediateFuture();
ret1.setResult(ret2);
final int[] cnt = new int[1];
IComponentStep step2 = new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
ret2.addIntermediateResult(""+cnt[0]++);
if(cnt[0]<3)
{
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(100, this);
}
else
{
ret2.setFinished();
}
return IFuture.DONE;
}
};
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(100, step2);
return IFuture.DONE;
}
};
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(100, step1);
return ret1;
}
}