jadex.micro.testcases.tracing.ProviderAgent 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.tracing;
import jadex.bridge.IInternalAccess;
import jadex.bridge.ServiceCall;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.annotation.Service;
import jadex.bridge.service.search.SServiceProvider;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.Implementation;
import jadex.micro.annotation.ProvidedService;
import jadex.micro.annotation.ProvidedServices;
/**
*
*/
@Agent
@ProvidedServices(@ProvidedService(type=ITestService.class, implementation=@Implementation(expression="$pojoagent")))
@Service
public class ProviderAgent implements ITestService
{
@Agent
protected IInternalAccess agent;
/**
* Call a method that must use a secure
* transport under the hood.
*/
public IFuture method(final String msg)
{
final Future ret = new Future();
ServiceCall sc = ServiceCall.getCurrentInvocation();
System.out.println("Called method1: "+msg+" "+sc+" "+Thread.currentThread());
SServiceProvider.getService(agent, ITestService.class, RequiredServiceInfo.SCOPE_LOCAL)
.addResultListener(new ExceptionDelegationResultListener(ret)
{
public void customResultAvailable(ITestService ts)
{
System.out.println("Called method1 after search: "+ServiceCall.getCurrentInvocation()+" "+Thread.currentThread());
ts.method2(msg).addResultListener(new DelegationResultListener(ret)
{
public void customResultAvailable(Void result)
{
ServiceCall sc = ServiceCall.getCurrentInvocation();
System.out.println("Called service: "+msg+" "+sc+" "+Thread.currentThread());
ret.setResult(null);
}
});
}
});
return ret;
}
/**
* Call a method that must use a secure
* transport under the hood.
*/
public IFuture method2(String msg)
{
ServiceCall sc = ServiceCall.getCurrentInvocation();
System.out.println("Called method2: "+msg+" "+sc+" "+Thread.currentThread());
return IFuture.DONE;
}
}