jadex.micro.testcases.multiinvoke.UserAgent 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.multiinvoke;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import jadex.base.test.TestReport;
import jadex.base.test.Testcase;
import jadex.bridge.IInternalAccess;
import jadex.bridge.component.IArgumentsResultsFeature;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.commons.future.CounterResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.commons.future.IIntermediateFuture;
import jadex.commons.future.IIntermediateResultListener;
import jadex.commons.future.IResultListener;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
import jadex.micro.annotation.Binding;
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.RequiredService;
import jadex.micro.annotation.RequiredServices;
import jadex.micro.annotation.Result;
import jadex.micro.annotation.Results;
/**
* Agent that uses a multiplexed service.
*/
@RequiredServices(@RequiredService(name="ms", type=IExampleService.class, multiple=true,
multiplextype=IMultiplexExampleService.class, binding=@Binding(dynamic=true)))
@Results(@Result(name="testresults", clazz=Testcase.class))
@Agent
@ComponentTypes(@ComponentType(name="provider", filename="ProviderAgent.class"))
@Configurations(@Configuration(name="def", components=@Component(type="provider", number="5")))
public class UserAgent
{
@Agent
protected IInternalAccess agent;
/**
* The agent body.
*/
@AgentBody
public IFuture body()
{
final Future ret = new Future();
IFuture fut = agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredService("ms");
fut.addResultListener(new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(IMultiplexExampleService ser)
{
final int cmpcnt = 5;
final int rescnt = 5;
final int testcnt = 10;
final List reports = new ArrayList();
CounterResultListener endlis = new CounterResultListener(testcnt, new IResultListener()
{
public void resultAvailable(Void result)
{
// System.out.println("countlis: "+agent.getComponentFeature(IExecutionFeature.class).isComponentThread());
agent.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("testresults", new Testcase(testcnt, reports.toArray(new TestReport[reports.size()])));
ret.setResult(null);
}
public void exceptionOccurred(Exception exception)
{
resultAvailable(null);
}
});
// indirect intermediate future version
TestReport tr = new TestReport("#1a", "Test indirect intermediate future version.");
reports.add(tr);
ser.getItem1().addResultListener(new CustomIntermediateResultListener>(tr, cmpcnt, endlis));
tr = new TestReport("#1b", "Test indirect intermediate future version.");
reports.add(tr);
ser.getItems1(rescnt).addResultListener(new CustomIntermediateResultListener>(tr, cmpcnt, endlis));
// indirect future version
tr = new TestReport("#2a", "Test indirect future version.");
reports.add(tr);
ser.getItem2().addResultListener(new CustomResultListener>>(tr, cmpcnt, endlis));
tr = new TestReport("#2b", "Test indirect future version.");
reports.add(tr);
ser.getItems2(rescnt).addResultListener(new CustomResultListener>>(tr, cmpcnt, endlis));
// flattened intermediate future version
tr = new TestReport("#3a", "Test flattened intermediate future version.");
reports.add(tr);
ser.getItem3().addResultListener(new CustomIntermediateResultListener(tr, cmpcnt, endlis));
tr = new TestReport("#3b", "Test flattened intermediate future version.");
reports.add(tr);
ser.getItems3(rescnt).addResultListener(new CustomIntermediateResultListener(tr, cmpcnt*rescnt, endlis));
// flattened future version
tr = new TestReport("#4a", "Test flattened future version.");
reports.add(tr);
ser.getItem4().addResultListener(new CustomResultListener>(tr, cmpcnt, endlis));
tr = new TestReport("#4b", "Test flattened future version.");
reports.add(tr);
ser.getItems4(rescnt).addResultListener(new CustomResultListener>(tr, cmpcnt*rescnt, endlis));
// sequential multiplexer
List