
jadex.bdi.examples.helloworld.HelloWorldAgentCreator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-applications-bdi Show documentation
Show all versions of jadex-applications-bdi Show documentation
The Jadex BDI applications package contain
several example applications, benchmarks and
testcases using BDI agents.
The newest version!
package jadex.bdi.examples.helloworld;
import jadex.base.Starter;
import jadex.bdi.IDynamicBDIFactory;
import jadex.bdi.model.editable.IMEBelief;
import jadex.bdi.model.editable.IMECapability;
import jadex.bdi.model.editable.IMEConfiguration;
import jadex.bdi.model.editable.IMEPlan;
import jadex.bridge.IExternalAccess;
import jadex.bridge.service.RequiredServiceInfo;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.bridge.service.types.factory.SComponentFactory;
import jadex.commons.Tuple2;
import jadex.commons.future.DefaultResultListener;
import java.util.Collection;
/**
* Example that shows how an agent model can be created via the editable model api.
* This model can be registered with a name at the BDI agent factory and instances
* can be created based on this new model.
*/
public class HelloWorldAgentCreator
{
/**
* Main for starting hello world agent.
*/
public static void main(String[] args)
{
Starter.createPlatform(args).addResultListener(new DefaultResultListener()
{
public void resultAvailable(final IExternalAccess plat)
{
// Load dummy model to force loading of bdi kernel.
SComponentFactory.isLoadable(plat, "Dummy.agent.xml", null).addResultListener(new DefaultResultListener()
{
public void resultAvailable(Boolean result)
{
SServiceProvider.getService(plat.getServiceProvider(), IDynamicBDIFactory.class, RequiredServiceInfo.SCOPE_PLATFORM)
.addResultListener(new DefaultResultListener()
{
public void resultAvailable(final IDynamicBDIFactory fac)
{
fac.createAgentModel("HelloWorld", "jadex.bdi.examples.helloworld", null, null)
.addResultListener(new DefaultResultListener()
{
public void resultAvailable(IMECapability agent)
{
IMEBelief msgbelief = agent.createBeliefbase().createBelief("msg");
msgbelief.createFact("\"Welcome to editable models!\"", null);
IMEPlan helloplan = agent.createPlanbase().createPlan("hello");
helloplan.createBody("HelloWorldPlan", null);
IMEConfiguration conf = agent.createConfiguration("default");
conf.createInitialPlan("hello");
fac.registerAgentModel(agent, "helloagent.agent.xml");
SServiceProvider.getServiceUpwards(plat.getServiceProvider(), IComponentManagementService.class)
.addResultListener(new DefaultResultListener()
{
public void resultAvailable(IComponentManagementService cms)
{
cms.createComponent("hw1", "helloagent.agent.xml", null,
new DefaultResultListener>>()
{
public void resultAvailable(Collection> result)
{
System.out.println("finished.");
}
});
}
});
}
});
}
});
}
});
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy