Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Commit 7d4c292

Browse files
committed
use new jacamo
1 parent d9202f3 commit 7d4c292

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ repositories {
2929
}
3030

3131
dependencies {
32-
compile 'org.jacamo:jacamo:0.8-SNAPSHOT'
32+
compile group: 'org.jacamo' , name: 'jacamo' , version: '0.8-SNAPSHOT' , changing: true , transitive: true
33+
3334
compile 'javax.xml.bind:jaxb-api:+'
3435
compile 'com.sun.xml.bind:jaxb-core:+'
3536
compile 'com.sun.xml.bind:jaxb-impl:+'

src/java/jacamo/web/JCMRest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
import org.glassfish.jersey.server.ResourceConfig;
2828

2929
import jacamo.infra.JaCaMoLauncher;
30+
import jacamo.infra.JaCaMoRuntimeServices;
3031
import jacamo.platform.DefaultPlatformImpl;
32+
import jason.asSemantics.Agent;
3133
import jason.mas2j.AgentParameters;
3234
import jason.mas2j.ClassParameters;
35+
import jason.runtime.Settings;
3336

3437

3538
public class JCMRest extends DefaultPlatformImpl {
@@ -60,6 +63,8 @@ static public String getZKHost() {
6063

6164
@Override
6265
public void init(String[] args) throws Exception {
66+
67+
// adds RestAgArch in the configuration of all agents in the project
6368
List<AgentParameters> lags = new ArrayList<>();
6469
for (AgentParameters ap: project.getAgents()) {
6570
if (ap.getNbInstances() > 0) {
@@ -110,6 +115,18 @@ public void init(String[] args) throws Exception {
110115
}
111116
}
112117

118+
// replace createAgent service (to add RestAgArch)
119+
((JaCaMoLauncher)JaCaMoLauncher.getRunner()).setRuntimeServives(new JaCaMoRuntimeServices(JaCaMoLauncher.getRunner()) {
120+
@Override
121+
public String createAgent(String agName, String agSource, String agClass, List<String> archClasses, ClassParameters bbPars, Settings stts, Agent father) throws Exception {
122+
if (archClasses == null)
123+
archClasses = new ArrayList<>();
124+
if (!archClasses.contains(RestAgArch.class.getName()))
125+
archClasses.add(RestAgArch.class.getName());
126+
return super.createAgent(agName, agSource, agClass, archClasses, bbPars, stts, father);
127+
}
128+
});
129+
113130
this.runner = (JaCaMoLauncher)JaCaMoLauncher.getRunner();
114131
}
115132

src/java/jacamo/web/RestAgArch.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void stop() {
7171

7272
RuntimeServices singRTS = null;
7373

74-
// place DSF services based on ZK
74+
// place DF services based on ZK
7575
@Override
7676
public RuntimeServices getRuntimeServices() {
7777
if (singRTS == null) {
@@ -95,9 +95,8 @@ public void dfSubscribe(String agName, String service, String type) {
9595
}
9696
@Override
9797
public String createAgent(String agName, String agSource, String agClass, List<String> archClasses, ClassParameters bbPars, Settings stts, Agent father) throws Exception {
98-
String r = super.createAgent(agName, agSource, agClass, archClasses, bbPars, stts, father);
99-
archClasses.add(RestAgArch.class.getName());
100-
return r;
98+
// delegate the to RTS defined in JaCaMo Launcher
99+
return masRunner.getRuntimeServices().createAgent(agName, agSource, agClass, archClasses, bbPars, stts, father);
101100
}
102101
};
103102
} else {

src/java/jacamo/web/RestImpl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.logging.LogRecord;
1212
import java.util.logging.StreamHandler;
1313

14+
import javax.inject.Singleton;
1415
import javax.ws.rs.Consumes;
1516
import javax.ws.rs.DELETE;
1617
import javax.ws.rs.DefaultValue;
@@ -22,14 +23,13 @@
2223
import javax.ws.rs.Produces;
2324
import javax.ws.rs.QueryParam;
2425
import javax.ws.rs.core.MediaType;
25-
import javax.ws.rs.core.Response;
2626

27+
import org.glassfish.jersey.internal.inject.AbstractBinder;
2728
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
2829
import org.glassfish.jersey.media.multipart.FormDataParam;
2930
import org.w3c.dom.Document;
3031

3132
import jacamo.infra.JaCaMoLauncher;
32-
import jacamo.platform.DefaultPlatformImpl;
3333
import jason.ReceiverNotFoundException;
3434
import jason.asSemantics.Agent;
3535
import jason.asSemantics.IntendedMeans;
@@ -47,8 +47,14 @@
4747
import jason.util.asl2html;
4848

4949

50+
@Singleton
5051
@Path("/")
51-
public class RestImpl extends DefaultPlatformImpl {
52+
public class RestImpl extends AbstractBinder {
53+
54+
@Override
55+
protected void configure() {
56+
bind(new RestImpl()).to(RestImpl.class);
57+
}
5258

5359
// HTML interface
5460

@@ -120,10 +126,10 @@ public String getNewAgentForm() {
120126
@Produces(MediaType.TEXT_HTML)
121127
public String createNewAgent(@FormParam("name") String agName) {
122128
try {
123-
List<String> archs = new ArrayList<>();
124-
archs.add(RestAgArch.class.getName());
125-
String name = JaCaMoLauncher.getRunner().getRuntimeServices().createAgent(agName, null, null, archs, null, null, null);
129+
String name = JaCaMoLauncher.getRunner().getRuntimeServices().createAgent(agName, null, null, null, null, null, null);
126130
JaCaMoLauncher.getRunner().getRuntimeServices().startAgent(name);
131+
// set some source for the agent
132+
JaCaMoLauncher.getRunner().getAg(name).getTS().getAg().setASLSrc("no-inicial.asl");
127133
return "<head><meta http-equiv=\"refresh\" content=\"2; URL='/agents/"+name+"/all'\" /></head>ok for "+name;
128134
} catch (Exception e) {
129135
e.printStackTrace();

0 commit comments

Comments
 (0)