Skip to content

Commit

Permalink
fix scripts for local execution
Browse files Browse the repository at this point in the history
  • Loading branch information
jomifred committed Feb 23, 2024
1 parent 64063d3 commit 95bc4e4
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 60 deletions.
28 changes: 28 additions & 0 deletions jason-cli/src/main/java/jason/cli/agent/BaseAgent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package jason.cli.agent;

import jason.cli.JasonCommands;
import jason.cli.mas.RunningMASs;


public class BaseAgent {

public String testMasName(String masName, JasonCommands parent) {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (RunningMASs.isRunningMAS(masName)) {
if (!masName.isEmpty())
parent.println("using " + masName + " as MAS name");
} else { // revert, masName is not working for some reason
masName = "";
}
}
return masName;
}

public void testRunningMAS(String masName, JasonCommands parent) {
if (!RunningMASs.isRunningMAS(masName)) {
parent.errorMsg("no running MAS, create one with 'mas start'.");
}
}
}

12 changes: 3 additions & 9 deletions jason-cli/src/main/java/jason/cli/agent/ListAgents.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name = "list",
description = "lists running agents"
)
public class ListAgents implements Runnable {
public class ListAgents extends BaseAgent implements Runnable {

@CommandLine.ParentCommand
protected Agent parent;
Expand All @@ -21,14 +21,8 @@ public class ListAgents implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}

if (!RunningMASs.isRunningMAS(masName))
return;
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

try {
for (var ag: RunningMASs.getRTS(masName).getAgentsNames()) {
Expand Down
14 changes: 4 additions & 10 deletions jason-cli/src/main/java/jason/cli/agent/LoadIntoAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name = "load-into",
description = "loads some ASL code into a running agent"
)
public class LoadIntoAgent implements Runnable {
public class LoadIntoAgent extends BaseAgent implements Runnable {

@Parameters(paramLabel = "<agent name>", defaultValue = "",
arity = "1",
Expand All @@ -39,15 +39,9 @@ public class LoadIntoAgent implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}
if (!RunningMASs.isRunningMAS(masName)) {
parent.parent.errorMsg("no running MAS, create one with 'mas start'.");
return;
}
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

if (agName.isEmpty()) {
parent.parent.errorMsg("the name of the new agent should be informed, e.g., 'agent load-into bob'.");
return;
Expand Down
14 changes: 4 additions & 10 deletions jason-cli/src/main/java/jason/cli/agent/MindAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name = "mind",
description = "inspects the mind of an agent"
)
public class MindAgent implements Runnable {
public class MindAgent extends BaseAgent implements Runnable {

@CommandLine.Parameters(paramLabel = "<agent name>", defaultValue = "",
arity = "1",
Expand All @@ -36,15 +36,9 @@ public class MindAgent implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}
if (!RunningMASs.isRunningMAS(masName)) {
parent.parent.errorMsg("no running MAS, so, no agent to inspect.");
return;
}
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

if (agName.isEmpty()) {
parent.parent.errorMsg("the name of the agent should be informed, e.g., 'agent mind bob'.");
return;
Expand Down
13 changes: 3 additions & 10 deletions jason-cli/src/main/java/jason/cli/agent/StartAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name = "start",
description = "starts a new (empty) agent"
)
public class StartAgent implements Runnable {
public class StartAgent extends BaseAgent implements Runnable {

@Parameters(paramLabel = "<agent name>", defaultValue = "",
arity = "1",
Expand Down Expand Up @@ -49,16 +49,9 @@ public class StartAgent implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

if (!RunningMASs.isRunningMAS(masName)) {
parent.parent.errorMsg("no running MAS, create one with 'mas start'.");
return;
}
if (agName.isEmpty()) {
parent.parent.errorMsg("the name of the new agent should be informed, e.g., 'agent start bob'.");
return;
Expand Down
14 changes: 4 additions & 10 deletions jason-cli/src/main/java/jason/cli/agent/StatusAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name = "status",
description = "shows the status of an agent"
)
public class StatusAgent implements Runnable {
public class StatusAgent extends BaseAgent implements Runnable {

@CommandLine.Parameters(paramLabel = "<agent name>", defaultValue = "",
arity = "1",
Expand All @@ -27,15 +27,9 @@ public class StatusAgent implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}
if (!RunningMASs.isRunningMAS(masName)) {
parent.parent.errorMsg("no running MAS, so, no agent to inspect.");
return;
}
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

if (agName.isEmpty()) {
parent.parent.errorMsg("the name of the agent should be informed, e.g., 'agent status bob'.");
return;
Expand Down
14 changes: 4 additions & 10 deletions jason-cli/src/main/java/jason/cli/agent/StopAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
name = "stop",
description = "kills an agent"
)
public class StopAgent implements Runnable {
public class StopAgent extends BaseAgent implements Runnable {

@Parameters(paramLabel = "<agent name>", defaultValue = "",
arity = "1",
Expand All @@ -27,15 +27,9 @@ public class StopAgent implements Runnable {

@Override
public void run() {
if (masName.isEmpty()) {
masName = RunningMASs.getDefaultMASName();
if (!masName.isEmpty())
parent.parent.println("using "+masName+" as MAS name");
}
if (!RunningMASs.isRunningMAS(masName)) {
parent.parent.errorMsg("no running MAS, so, no agent to kill.");
return;
}
masName = testMasName(masName, parent.parent);
testRunningMAS(masName, parent.parent);

if (agName.isEmpty()) {
parent.parent.errorMsg("the name of the agent should be informed, e.g., 'agent stop bob'.");
return;
Expand Down
2 changes: 1 addition & 1 deletion jason-cli/src/main/java/jason/cli/mas/ListMAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void run() {
var all = RunningMASs.getAllRunningMAS();
//parent.parent.println("running MAS:");
for (var mas: all.keySet()) {
parent.parent.println(" "+mas+" @"+all.get(mas));
parent.parent.println(" "+mas+"@"+all.get(mas));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions jason-cli/src/main/java/jason/cli/mas/RunningMASs.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static RuntimeServices getRTS(String masName) {
return rt;
}
} catch (Exception e) {
//e.printStackTrace();
}

// try with list of running MAS
Expand Down

0 comments on commit 95bc4e4

Please sign in to comment.