jadex.micro.testcases.semiautomatic.remoteservice.ScenarioAgent 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.remoteservice;
import java.util.ArrayList;
import java.util.List;
import jadex.bridge.IExternalAccess;
import jadex.bridge.IInternalAccess;
import jadex.bridge.IResourceIdentifier;
import jadex.bridge.component.IExecutionFeature;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.component.IRequiredServicesFeature;
import jadex.bridge.service.types.library.ILibraryService;
import jadex.commons.future.DefaultResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
import jadex.micro.annotation.Agent;
import jadex.micro.annotation.AgentBody;
/**
* Just for starting the scenario.
*/
@Agent
public class ScenarioAgent
{
@Agent
protected IInternalAccess agent;
/**
* Execute the body.
*/
@AgentBody
public IFuture executeBody()
{
// ILibraryService ls = SServiceProvider.getLocalService(agent, ILibraryService.class, RequiredServiceInfo.SCOPE_PLATFORM);
// System.out.println("ls:"+ls);
IFuture fut = agent.getComponentFeature(IRequiredServicesFeature.class).searchService(ILibraryService.class, RequiredServiceInfo.SCOPE_PLATFORM);
// IFuture fut = agent.getComponentFeature(IRequiredServicesFeature.class).searchService(ILibraryService.class);
fut.addResultListener(new DefaultResultListener()
{
public void resultAvailable(ILibraryService libservice)
{
// libservice.getURLStrings().addResultListener(createResultListener(new DefaultResultListener()
libservice.getAllResourceIdentifiers().addResultListener(agent.getComponentFeature(IExecutionFeature.class)
.createResultListener(new DefaultResultListener>()
{
public void resultAvailable(List result)
{
List libs = (List)result;
List libpaths = new ArrayList();
for(IResourceIdentifier rid: libs)
{
String lib = rid.getLocalIdentifier().getUri().toString();
if(lib.startsWith("file:")) // Hack!!! excludes systemcprid.
{
libpaths.add(lib);
}
}
StartScenario.startScenario(libpaths.toArray(new String[libpaths.size()])).addResultListener(
agent.getComponentFeature(IExecutionFeature.class).createResultListener(new DefaultResultListener()
{
public void resultAvailable(IExternalAccess[] platforms)
{
System.out.println("Killing platforms");
for(int i=0; i(); // never kill?!
}
}