jadex.micro.testcases.DependendServicesAgent 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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IComponentIdentifier;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.bridge.service.types.monitoring.IMonitoringEvent;
import jadex.bridge.service.types.monitoring.IMonitoringService.PublishEventLevel;
import jadex.commons.SUtil;
import jadex.commons.future.CollectionResultListener;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IResultListener;
import jadex.commons.future.IntermediateDefaultResultListener;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.AgentCreated;
import jadex.micro.annotation.Component;
import jadex.micro.annotation.ComponentType;
import jadex.micro.annotation.ComponentTypes;
import jadex.micro.annotation.Configuration;
import jadex.micro.annotation.Configurations;
import jadex.micro.annotation.Description;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;
/**
* Starts two agents a and b
* a has service sa
* b has service sb
* init of service sb searches for sa and uses the service
*
* (problem is that component a has finished its init but must execute the service call for sb)
*/
@Description("Test if services of (earlier) sibling components can be found and used.")
@Results(@Result(name="testresults", clazz=Testcase.class))
@ComponentTypes({
@ComponentType(name="a", clazz=AAgent.class),
@ComponentType(name="b", clazz=BAgent.class)
})
@Configurations(@Configuration(name="def", components={
@Component(type="a"),
@Component(type="b")
}))
@Agent
public class DependendServicesAgent
{
@Agent
protected IInternalAccess agent;
/**
* Init code.
*/
@AgentCreated
public IFuture agentCreated()
{
final Future ret = new Future();
getChildrenAccesses().addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new ExceptionDelegationResultListener, Void>(ret)
{
public void customResultAvailable(Collection result)
{
IExternalAccess[] childs = (IExternalAccess[])result.toArray(new IExternalAccess[0]);
System.out.println("childs: "+SUtil.arrayToString(childs));
final CollectionResultListener> lis = new CollectionResultListener>(childs.length, true,
agent.getComponentFeature(IExecutionFeature.class).createResultListener(new IResultListener>>()
{
public void resultAvailable(Collection> result)
{
System.out.println("fini: "+result);
List tests = new ArrayList();
// Collection col = (Collection)result;
for(Iterator> it=result.iterator(); it.hasNext(); )
{
Collection tmp = (Collection)it.next();
tests.addAll(tmp);
}
agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("testresults", new Testcase(tests.size(), (TestReport[])tests.toArray(new TestReport[tests.size()])));
agent.killComponent();
}
public void exceptionOccurred(Exception exception)
{
agent.killComponent(exception);
}
}));
for(int i=0; i()
{
public void intermediateResultAvailable(IMonitoringEvent result)
{
child.getResults().addResultListener(agent.getComponentFeature(IExecutionFeature.class).createResultListener(new IResultListener