jadex.micro.testcases.semiautomatic.DynamicServiceAgent 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.semiautomatic;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IComponentStep;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.BasicService;
import jadex.bridge.service.component.BasicServiceInvocationHandler;
import jadex.bridge.service.component.IProvidedServicesFeature;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
/**
* An agent that dynamically adds services at runtime.
*/
@Agent
public class DynamicServiceAgent
{
/** The internal access. */
@Agent
protected IInternalAccess agent;
/**
* Perform the agents actions.
*/
@AgentBody
public IFuture executeBody()
{
final Future ret = new Future();
IComponentStep addservice = new IComponentStep()
{
public IFuture execute(IInternalAccess ia)
{
agent.getComponentFeature(IProvidedServicesFeature.class).addService("dummyservice", IDummyService.class, new DummyService(agent.getComponentIdentifier()), BasicServiceInvocationHandler.PROXYTYPE_DIRECT);
agent.getComponentFeature(IExecutionFeature.class).waitForDelay(3000, this);
return IFuture.DONE;
}
};
addservice.execute(agent);
return ret; // never kill?!
}
public class DummyService extends BasicService implements IDummyService
{
public DummyService(IComponentIdentifier providerid)
{
super(providerid, IDummyService.class, null);
}
public String toString()
{
return getServiceIdentifier().getServiceName();
}
}
// @Service
// public class DummyService2 implements IDummyService
// {
// }
public interface IDummyService
{
public String toString();
}
}