|
From: <jom...@us...> - 2015-11-11 20:16:56
|
Revision: 1853
http://sourceforge.net/p/jason/svn/1853
Author: jomifred
Date: 2015-11-11 20:16:54 +0000 (Wed, 11 Nov 2015)
Log Message:
-----------
improve sleep for agents in thread pool
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-11 19:40:48 UTC (rev 1852)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-11 20:16:54 UTC (rev 1853)
@@ -212,13 +212,15 @@
private Object sleepSync = new Object();
private int sleepTime = 50;
+ public static final int MAX_SLEEP = 1000;
+
public void sleep() {
try {
if (!getTS().getSettings().isSync()) {
logger.fine("Entering in sleep mode....");
synchronized (sleepSync) {
sleepSync.wait(sleepTime); // wait for messages
- if (sleepTime < 1000)
+ if (sleepTime < MAX_SLEEP)
sleepTime += 100;
}
}
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-11-11 19:40:48 UTC (rev 1852)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-11-11 20:16:54 UTC (rev 1853)
@@ -57,6 +57,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -597,8 +598,15 @@
@Override
public void sleep() {
//if (sleepingAgs.contains(this))
- // System.out.println("*** ops already slepping "+this);
- sleepingAgs.add(this);
+ // System.out.println("*** oops already sleeping "+this);
+ sleepingAgs.add(this);
+
+ // wake up the agent in 1 second anyway
+ Agent.getScheduler().schedule(new Runnable() {
+ public void run() {
+ wake();
+ }
+ }, MAX_SLEEP, TimeUnit.MILLISECONDS);
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-11-13 14:41:54
|
Revision: 1854
http://sourceforge.net/p/jason/svn/1854
Author: jomifred
Date: 2015-11-13 14:41:52 +0000 (Fri, 13 Nov 2015)
Log Message:
-----------
fix bug related to pool of threads and agent creation
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-11 20:16:54 UTC (rev 1853)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-13 14:41:52 UTC (rev 1854)
@@ -126,9 +126,10 @@
public void stopAg() {
running = false;
- if (myThread != null)
- myThread.interrupt();
- synchronized (syncStopRun) {
+ wake(); // so that it leaves the run loop
+ //if (myThread != null) // not necessary, the ag loop should finish since running == false
+ // myThread.interrupt();
+ synchronized (syncStopRun) { // wait the run loop to finish
masRunner.delAg(agName);
}
getTS().getAg().stopAg();
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-11-11 20:16:54 UTC (rev 1853)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-11-13 14:41:52 UTC (rev 1854)
@@ -27,6 +27,7 @@
import jason.asSemantics.Agent;
import jason.asSyntax.directives.DirectiveProcessor;
import jason.asSyntax.directives.Include;
+import jason.bb.DefaultBeliefBase;
import jason.control.ExecutionControlGUI;
import jason.infra.repl.ReplAgGUI;
import jason.jeditplugin.Config;
@@ -458,15 +459,15 @@
}
agArch.setAgName(numberedAg);
agArch.setEnvInfraTier(env);
- if (isPool && cAg > 0) {
+ if (isPool && cAg > 0 && ap.getAgArchClasses().isEmpty() && ap.getBBClass().equals(DefaultBeliefBase.class.getName())) {
// creation by cloning previous agent (which is faster -- no parsing, for instance)
+ // used if not customisations are defined
agArch.createArchs(ap.getAgArchClasses(), pag, this);
} else {
// normal creation
agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), ap.asSource.toString(), ap.getAsSetts(debug, project.getControlClass() != null), this);
}
addAg(agArch);
-
pag = agArch.getTS().getAg();
}
} catch (Exception e) {
@@ -715,8 +716,14 @@
}
}
- public void finish() {
-
+ private Boolean runningFinish = false;
+ public void finish() {
+ // avoid two threads running finish!
+ synchronized (runningFinish) {
+ if (runningFinish)
+ return;
+ runningFinish = true;
+ }
try {
// creates a thread that guarantees system.exit(0) in 5 seconds
// (the stop of agents can block)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-11-18 13:34:40
|
Revision: 1855
http://sourceforge.net/p/jason/svn/1855
Author: jomifred
Date: 2015-11-18 13:34:38 +0000 (Wed, 18 Nov 2015)
Log Message:
-----------
fix problem in concurrent execution of create_agent
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-13 14:41:52 UTC (rev 1854)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2015-11-18 13:34:38 UTC (rev 1855)
@@ -127,8 +127,8 @@
public void stopAg() {
running = false;
wake(); // so that it leaves the run loop
- //if (myThread != null) // not necessary, the ag loop should finish since running == false
- // myThread.interrupt();
+ if (myThread != null)
+ myThread.interrupt();
synchronized (syncStopRun) { // wait the run loop to finish
masRunner.delAg(agName);
}
Modified: trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2015-11-13 14:41:52 UTC (rev 1854)
+++ trunk/src/jason/infra/centralised/CentralisedRuntimeServices.java 2015-11-18 13:34:38 UTC (rev 1855)
@@ -41,18 +41,20 @@
stts = new Settings();
String nb = "";
- int n = 1;
- while (masRunner.getAg(agName+nb) != null)
- nb = "_" + (n++);
- agName = agName + nb;
+ synchronized (logger) { // to avoid problems related to concurrent executions of .create_agent
+ int n = 1;
+ while (masRunner.getAg(agName+nb) != null)
+ nb = "_" + (n++);
+ agName = agName + nb;
+
+ CentralisedAgArch agArch = newAgInstance();
+ agArch.setAgName(agName);
+ agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), agSource, stts, masRunner);
+ agArch.setEnvInfraTier(masRunner.getEnvironmentInfraTier());
+ agArch.setControlInfraTier(masRunner.getControllerInfraTier());
+ masRunner.addAg(agArch);
+ }
- CentralisedAgArch agArch = newAgInstance();
- agArch.setAgName(agName);
- agArch.createArchs(ap.getAgArchClasses(), ap.agClass.getClassName(), ap.getBBClass(), agSource, stts, masRunner);
- agArch.setEnvInfraTier(masRunner.getEnvironmentInfraTier());
- agArch.setControlInfraTier(masRunner.getControllerInfraTier());
- masRunner.addAg(agArch);
-
logger.fine("Agent " + agName + " created!");
return agName;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2015-12-03 12:09:17
|
Revision: 1858
http://sourceforge.net/p/jason/svn/1858
Author: jomifred
Date: 2015-12-03 12:09:15 +0000 (Thu, 03 Dec 2015)
Log Message:
-----------
do not create the environment if no one was specified in the .mas2j
Modified Paths:
--------------
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
trunk/src/jason/infra/centralised/StartNewAgentGUI.java
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-12-02 14:17:57 UTC (rev 1857)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2015-12-03 12:09:15 UTC (rev 1858)
@@ -418,8 +418,10 @@
}
public void createEnvironment() throws JasonException {
- logger.fine("Creating environment " + project.getEnvClass());
- env = new CentralisedEnvironment(project.getEnvClass(), this);
+ if (project.getEnvClass() != null && !project.getEnvClass().getClassName().equals(jason.environment.Environment.class.getName())) {
+ logger.fine("Creating environment " + project.getEnvClass());
+ env = new CentralisedEnvironment(project.getEnvClass(), this);
+ }
}
public void createAgs() throws JasonException {
Modified: trunk/src/jason/infra/centralised/StartNewAgentGUI.java
===================================================================
--- trunk/src/jason/infra/centralised/StartNewAgentGUI.java 2015-12-02 14:17:57 UTC (rev 1857)
+++ trunk/src/jason/infra/centralised/StartNewAgentGUI.java 2015-12-03 12:09:15 UTC (rev 1858)
@@ -110,7 +110,7 @@
public void run() {
boolean debug = RunCentralisedMAS.isDebug();
boolean fs = RunCentralisedMAS.getRunner().getControllerInfraTier() != null;
- RuntimeServicesInfraTier services = RunCentralisedMAS.getRunner().getEnvironmentInfraTier().getRuntimeServices();
+ RuntimeServicesInfraTier services = RunCentralisedMAS.getRunner().getRuntimeServices();
try {
String agClass = null;
if (ap.agClass != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <xsp...@us...> - 2016-04-11 13:21:11
|
Revision: 1896
http://sourceforge.net/p/jason/svn/1896
Author: xsplyter
Date: 2016-04-11 13:21:09 +0000 (Mon, 11 Apr 2016)
Log Message:
-----------
Reuse code Synchronous
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArch.java
trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArch.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/CentralisedAgArch.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -188,8 +188,8 @@
public boolean isRunning() {
return running;
}
-
- protected boolean reasoningCycle() {
+
+ protected boolean sense() {
TransitionSystem ts = getTS();
int i = 0;
@@ -202,7 +202,13 @@
i++;
}
- i = 0;
+ return true;
+ }
+
+ protected boolean deliberate() {
+ TransitionSystem ts = getTS();
+
+ int i = 0;
while (running && i < cyclesDeliberate) {
if (!ts.deliberate()) {
return false;
@@ -212,7 +218,13 @@
i++;
}
- i = 0;
+ return true;
+ }
+
+ protected boolean act() {
+ TransitionSystem ts = getTS();
+
+ int i = 0;
int ca = cyclesAct;
if (cyclesAct == 9999)
ca = ts.getC().getIntentions().size();
@@ -229,6 +241,12 @@
return true;
}
+ protected boolean reasoningCycle() {
+ if (!sense()) return false;
+ if (!deliberate()) return false;
+ if (!act()) return false;
+ return true;
+ }
public void run() {
TransitionSystem ts = getTS();
Modified: trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/CentralisedAgArchAsynchronous.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -151,7 +151,7 @@
/** called the the environment when the action was executed */
public void actionExecuted(ActionExec action) {
- synchronized (objSense) {
+ synchronized (objAct) {
super.actionExecuted(action);
}
}
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-11 11:37:05 UTC (rev 1895)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-11 13:21:09 UTC (rev 1896)
@@ -1013,7 +1013,7 @@
}
}
- public void sense() {
+ public boolean sense() {
int number_cycles = getCyclesSense();
int i = 0;
@@ -1023,7 +1023,7 @@
if (runWakeAfterTS) {
wake();
}
- return;
+ return false;
} else if (getTS().canSleepSense()) {
break;
}
@@ -1033,176 +1033,28 @@
if (isRunning()) {
executor.execute(this);
}
- }
-
- public void deliberate() {
- int number_cycles = getCyclesDeliberate();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- getTS().deliberate();
-
- if (getTS().canSleepDeliberate()) {
- break;
- }
-
- i++;
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return true;
}
- public void act() {
- int number_cycles = getCyclesAct();
- int i = 0;
-
- if (number_cycles == 9999) { //TODO adjust parameter for executing one deed from each intention
- //System.out.println("# Executing one deed from each intention " + getTS().getC().getIntentions().size());
-
- while (isRunning() && i < getTS().getC().getIntentions().size()) {
-
- //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
-
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- } else {
- while (isRunning() && i < number_cycles) {
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- }
+ public boolean deliberate() {
+ boolean result = super.deliberate();
if (isRunning()) {
executor.execute(this);
}
- }
-
- @Override
- public void run() {
- switch (currentStep) {
- case 0:
- sense();
- currentStep = 1;
- break;
- case 1:
- deliberate();
- currentStep = 2;
- break;
- case 2:
- act();
- currentStep = 0;
- break;
- }
- }
- }
-
- /** an agent architecture for the infra based on thread pool */
- protected final class CentralisedAgArchSynchronousScheduled_2 extends CentralisedAgArch {
- private volatile boolean runWakeAfterTS = false;
- private int currentStep = 0;
-
- @Override
- public void sleep() {
- sleepingAgs.add(this);
- }
-
- @Override
- public void wake() {
- if (sleepingAgs.remove(this)) {
- executor.execute(this);
- } else {
- runWakeAfterTS = true;
- }
- }
-
- public void sense() {
- int number_cycles = getCyclesSense();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- runWakeAfterTS = false;
- if (!getTS().sense()) { // the agent run a cycle (did not enter in sleep)
- if (runWakeAfterTS) {
- wake();
- }
- return;
- } else if (getTS().canSleepSense()) {
- break;
- }
- i++;
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return result;
}
- public void deliberate() {
- int number_cycles = getCyclesDeliberate();
- int i = 0;
-
- while (isRunning() && i < number_cycles) {
- getTS().deliberate();
-
- if (getTS().canSleepDeliberate()) {
- break;
- }
-
- i++;
- }
+ public boolean act() {
+ boolean result = super.act();
if (isRunning()) {
executor.execute(this);
}
- }
-
- public void act() {
- int number_cycles = getCyclesAct();
- int i = 0;
-
- if (number_cycles == 9999) { //TODO adjust parameter for executing one deed from each intention
- //System.out.println("# Executing one deed from each intention " + getTS().getC().getIntentions().size());
-
- while (isRunning() && i < getTS().getC().getIntentions().size()) {
-
- //System.out.println("# Executing one deed from each intention #" + i + " -> " + getTS().getC().getIntentions().size());
-
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- } else {
- while (isRunning() && i < number_cycles) {
- getTS().act();
-
- if (getTS().canSleepAct()) {
- break;
- }
-
- i++;
- }
- }
- if (isRunning()) {
- executor.execute(this);
- }
+ return result;
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jom...@us...> - 2016-04-13 21:13:00
|
Revision: 1903
http://sourceforge.net/p/jason/svn/1903
Author: jomifred
Date: 2016-04-13 21:12:58 +0000 (Wed, 13 Apr 2016)
Log Message:
-----------
fix wakeup of cent ag arch for pool
Modified Paths:
--------------
trunk/src/jason/infra/centralised/CentralisedAgArchForPool.java
trunk/src/jason/infra/centralised/RunCentralisedMAS.java
Modified: trunk/src/jason/infra/centralised/CentralisedAgArchForPool.java
===================================================================
--- trunk/src/jason/infra/centralised/CentralisedAgArchForPool.java 2016-04-13 20:47:26 UTC (rev 1902)
+++ trunk/src/jason/infra/centralised/CentralisedAgArchForPool.java 2016-04-13 21:12:58 UTC (rev 1903)
@@ -4,7 +4,6 @@
/** an agent architecture for the infra based on thread pool */
public final class CentralisedAgArchForPool extends CentralisedAgArch {
- private volatile boolean runWakeAfterTS = false;
private volatile boolean isSleeping = false;
private ExecutorService executor;
@@ -12,78 +11,43 @@
executor = e;
}
- /*
@Override
public void sleep() {
- //if (sleepingAgs.contains(this))
- // System.out.println("*** ops already slepping "+this);
- sleepingAgs.add(this);
- }*/
-
- @Override
- public void sleep() {
- //if (sleepingAgs.contains(this))
- // System.out.println("*** oops already sleeping "+this);
-// sleepingAgs.add(this);
isSleeping = true;
- // wake up the agent in 1 second anyway
-
/*Agent.getScheduler().schedule(new Runnable() {
public void run() {
wake();
}
}, MAX_SLEEP, TimeUnit.MILLISECONDS);*/
- //}, MAX_SLEEP, TimeUnit.MILLISECONDS);
}
@Override
- public synchronized void wake() {
- if (isSleeping) { //sleepingAgs.remove(this)) {
- isSleeping = false;
- /*try {
- ThreadPoolExecutor tp = (ThreadPoolExecutor)executor;
- if (tp.getQueue().contains(this)) {
- System.out.println("ops... ading ag that is already in the pool "+this);
- }
- } catch (Exception e) { }*/
- executor.execute(this);
- } else {
- runWakeAfterTS = true;
+ public void wake() {
+ synchronized (this) {
+ if (isSleeping) {
+ isSleeping = false;
+ executor.execute(this);
+ }
}
}
- /*@Override
- public void receiveMsg(final Message m) {
- executor.execute(new Runnable() {
- public void run() {
- CentralisedAgArchForPool.super.receiveMsg(m);
- }
- });
- }*/
-
-
@Override
public void run() {
int number_cycles = getCycles();
int i = 0;
while (isRunning() && i++ < number_cycles) {
- runWakeAfterTS = false;
- //if (!getTS().reasoningCycle() && !runWakeAfterTS) { // the agent run a cycle (did not enter in sleep)
- //if (!reasoningCycle()) { // the agent run a cycle (did not enter in sleep)
reasoningCycle();
- if (getTS().canSleep()) {
- sleep();
- if (runWakeAfterTS) {
- wake();
+ synchronized (this) {
+ if (getTS().canSleep()) {
+ sleep();
+ return;
+ } else if (i == number_cycles) {
+ executor.execute(this);
+ return;
}
- return;
}
}
-
- if (isRunning()) {
- executor.execute(this);
- }
}
}
Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java
===================================================================
--- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-13 20:47:26 UTC (rev 1902)
+++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2016-04-13 21:12:58 UTC (rev 1903)
@@ -840,6 +840,8 @@
cyclesAct = Integer.parseInt(project.getInfrastructure().getParameter(4));
} else if (project.getInfrastructure().getParametersArray().length > 2) {
cycles = Integer.parseInt(project.getInfrastructure().getParameter(2));
+ } else {
+ cycles = 5;
}
logger.info("Creating a thread pool with "+maxthreads+" thread(s)." + "Cycles: " + cyclesSense + ", " + cyclesDeliberate + ", " + cyclesAct + " Reasoning Cycles: " + cycles);
@@ -943,12 +945,11 @@
while (isRunning() && i < number_cycles) {
runWakeAfterTS = false;
- if (!getTS().sense()) { // the agent run a cycle (did not enter in sleep)
- if (runWakeAfterTS) {
- wake();
- }
- return;
- } else if (getTS().canSleepSense()) {
+ getTS().sense();
+ if (getTS().canSleepSense()) {
+ if (runWakeAfterTS) {
+ wake();
+ }
break;
}
i++;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|