jadex.micro.testcases.blocking.BlockAgent 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.blocking;
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.micro.annotation.Agent;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
/**
* An agent that provides the blocking service.
*/
@Agent
@Service
@ProvidedServices(@ProvidedService(type=IBlockService.class))
public class BlockAgent implements IBlockService
{
//-------- attributes --------
/** The agent. */
@Agent
protected IInternalAccess agent;
//-------- IBlockingService interface --------
/**
* Block until the given time has passed.
*/
public IFuture block(long millis)
{
Future ret = new Future();
if(millis>0)
{
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(millis).get();
ret.setResult(null);
}
else
{
// do not set result at all and block forever
ret.get();
}
return ret;
}
}