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

jadex.micro.testcases.blocking.BlockAgent 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.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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy