Skip to content

Commit

Permalink
rename interface RunTimeServices
Browse files Browse the repository at this point in the history
  • Loading branch information
jomifred committed Apr 11, 2024
1 parent 8d4f93d commit c9f1b4b
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 21 deletions.
2 changes: 1 addition & 1 deletion jason-cli/src/main/java/jason/cli/agent/ListAgents.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void run() {
try {
var rts = RunningMASs.getRTS(masName);
if (rts != null) {
for (var ag : rts.getAgentsNames()) {
for (var ag : rts.getAgentsName()) {
parent.parent.println(" " + ag);
}
}
Expand Down
2 changes: 1 addition & 1 deletion jason-cli/src/main/java/jason/cli/agent/LoadIntoAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static String getCode(String sourceFile, List<String> allParameters) {
}

// load code in the script, enclosed by { }
if (allParameters.size()>0) {
if (!allParameters.isEmpty()) {
var last = allParameters.get( allParameters.size()-1).trim();
if (last.startsWith("{")) {
code.append(last.substring(1, last.length() - 1).trim());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void windowClosing(WindowEvent e) {
@SuppressWarnings("unchecked")
void setListOfAgsFromInfra() {
try {
Set<String> ags = new TreeSet<String>(getExecutionControlInfraTier().getRuntimeServices().getAgentsNames());
Set<String> ags = new TreeSet<String>(getExecutionControlInfraTier().getRuntimeServices().getAgentsName());
for (String ag: ags) { //getExecutionControlInfraTier().getRuntimeServices().getAgentsNames()) {
listModel.addElement(ag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void stop() {
*/
protected void updateNumberOfAgents() {
try {
setNbAgs(getEnvironmentInfraTier().getRuntimeServices().getAgentsNames().size());
setNbAgs(getEnvironmentInfraTier().getRuntimeServices().getAgentsName().size());
} catch (RemoteException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.ControllerException;
import jason.JasonException;
import jason.architecture.AgArch;
import jason.mas2j.AgentParameters;
import jason.mas2j.ClassParameters;
import jason.runtime.RuntimeServices;
Expand Down Expand Up @@ -75,7 +73,7 @@ public void startAgent(String agName) {
// nothing to do, the jade create new agent is enough
}

public Collection<String> getAgentsNames() {
public Collection<String> getAgentsName() {
// TODO: make a cache list and update it when a new agent enters the system
if (jadeAgent == null) return null;
try {
Expand Down Expand Up @@ -114,7 +112,7 @@ public Collection<String> getAgentsNames() {

public int getAgentsQty() {
try {
return getAgentsNames().size();
return getAgentsName().size();
} catch (Exception e) {
logger.log(Level.SEVERE, "Error getting agents qty", e);
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public String getNewAgentName(String baseName) {
}


public Collection<String> getAgentsNames() {
public Collection<String> getAgentsName() {
return masRunner.getAgs().keySet().stream().toList();
}

public int getAgentsQty() {
return getAgentsNames().size();
return getAgentsName().size();
}

public void stopMAS(int deadline, boolean stopJVM, int exitValue) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected void initComponents() {
// Fields
Vector<String> agNames = null;
try {
agNames = new Vector<String>(services.getAgentsNames());
agNames = new Vector<String>(services.getAgentsName());
} catch (RemoteException e) {
agNames = new Vector<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void receiveMsg(Message m) {
}

public void broadcast(Message m) throws Exception {
for (String agName: RuntimeServicesFactory.get().getAgentsNames()) {
for (String agName: RuntimeServicesFactory.get().getAgentsName()) {
if (!agName.equals(this.getAgName())) {
Message newm = m.clone();
newm.setReceiver(agName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package jason.infra.local;

import jason.JasonException;
import jason.asSemantics.Agent;
import jason.asSyntax.NumberTermImpl;
import jason.asSyntax.Pred;
import jason.asSyntax.Trigger;
import jason.asSemantics.*;
import jason.asSyntax.*;
import jason.mas2j.AgentParameters;
import jason.mas2j.ClassParameters;
import jason.pl.PlanLibrary;
import jason.runtime.RuntimeServicesFactory;
import jason.runtime.Settings;
import jason.runtime.SourcePath;
import jason.stdlib.print_unifier;

import java.io.StringReader;
import java.util.ArrayList;
Expand Down Expand Up @@ -197,5 +196,48 @@ public String loadASL(String agName, String code, String sourceId, boolean repla
throw new RuntimeException(e);
}
}

@Override
public String runAsAgent(String agName, String code) {
try {
LocalAgArch agArch = masRunner.getAg(agName);
if (agArch == null)
return "no agent named "+agName;

code = code.trim();
if (code.endsWith("."))
code = code.substring(0,code.length()-1);
while (code.endsWith(";"))
code = code.substring(0,code.length()-1);

code += "; "+ print_unifier.class.getName();
PlanBody lCmd = ASSyntax.parsePlanBody(code);

// parent.parent.println(lCmd.getBodyNext()+" -- "+lCmd.getBodyNext().getBodyType().getClass().getName());
var te = ASSyntax.parseTrigger("+!run_repl_expr");
var i = new Intention();
var plan = new Plan(null,te,null,lCmd);
i.push(new IntendedMeans(
new Option(
plan,
new Unifier()),
te));

agArch.getTS().getC().addRunningIntention(i);

// parent.parent.println("------" + ag.getTS().getAg().getPL().getAsTxt(false));
// parent.parent.println("------" + ag.getTS().getC().getRunningIntentions());
// parent.parent.println("------" + ag.getTS().getAg().getPL().getCandidatePlans(
// ASSyntax.parseTrigger("+!a")
// ));

agArch.getTS().getAgArch().wake();


} catch (Exception e) {
return "Error parsing "+code+"\n"+e;
}
return "ok";
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Set;

import jason.JasonException;
import jason.architecture.AgArch;
import jason.asSemantics.Agent;
import jason.mas2j.ClassParameters;

Expand Down Expand Up @@ -45,8 +44,8 @@ public void clone(Agent source, List<String> archClasses, String agName) throws
delegate.clone(source, archClasses, agName);
}

public Collection<String> getAgentsNames() throws RemoteException {
return delegate.getAgentsNames();
public Collection<String> getAgentsName() throws RemoteException {
return delegate.getAgentsName();
}

public int getAgentsQty() throws RemoteException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ default public void clone(Agent source, List<String> archClasses, String agName)
public boolean killAgent(String agName, String byAg, int deadline) throws RemoteException;

/** Returns a set of all agents' name */
public Collection<String> getAgentsNames() throws RemoteException;
public Collection<String> getAgentsName() throws RemoteException;

/** Gets the number of agents in the MAS. */
public int getAgentsQty() throws RemoteException;
Expand All @@ -81,6 +81,9 @@ default public void clone(Agent source, List<String> archClasses, String agName)
/** loads some ASL code into some agent, if replace is true, the previous plans from the sourceID will be removed */
default public String loadASL(String agName, String code, String sourceId, boolean replace) throws RemoteException { return "not implemented"; }

/** agent agName executes the code (in a new intention) */
//public String runAsAgent(String agName, String code);

/** Stops all MAS (the agents, the environment, the controller, ...) */
public void stopMAS(int deadline, boolean stopJVM, int exitValue) throws RemoteException, Exception;
default public void stopMAS() throws Exception { stopMAS(0, true, 0); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Excep
checkArguments(args);
ListTerm ln = new ListTermImpl();
ListTerm tail = ln;
for (String a: RuntimeServicesFactory.get().getAgentsNames()) {
for (String a: RuntimeServicesFactory.get().getAgentsName()) {
tail = tail.append(new Atom(a));
}
return un.unifies(args[0], ln);
Expand Down

0 comments on commit c9f1b4b

Please sign in to comment.