Snippets

Sebastian Sardina FAQ for using SARL + SWI/JPL Prolog + Maven

Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 Yes, use something like `TimeUnit.SECONDS.sleep(5)`
 
 
+## Intialize behavior in agents do not terminate! 
+
+The `Initialize` behavior handler in agents is a bit special, because it is the code ran when an agent is born. As such, its execution is more synchronous than other behavior rules.
+
+
+1. Any event emitted within an `Initialize`, will not be processed until `Initialize` finishes. So your agent initialization should not depend and wait on any other event being processed, as they won't!
+2. When spawning an agent in `Initialize`, the spawn instructions will not return until all the `Initialize` behaviors of the spawned agent have been executed fully. 
+
+
+```
+import io.sarl.core.Initialize
+import io.sarl.core.Logging
+import io.sarl.core.Lifecycle
+
+agent Agent1 {
+	uses Logging, Lifecycle
+
+	var agent_name = "agent1"
+
+	on Initialize {
+		info(agent_name + " spawned")
+		info(agent_name + " spawning Agent2")
+		spawn(Agent2)
+		info(agent_name + " end")
+	}
+}
+
+agent Agent2 {
+	uses Logging
+
+	var agent_name = "agent2"
+	
+	on Initialize {
+		info(agent_name + " spawned")
+		info(agent_name + " sleeping")
+		Thread.sleep(5000)
+		info(agent_name + " woke up")
+		info(agent_name + " end")
+	}
+
+	on Initialize {
+		info(agent_name + " init2")
+		info(agent_name + " init2 end")
+	}
+}
+```
+
+The result will be:
+
+```
+Launching the agent: Agent1
+agent1 spawned
+agent1 spawning Agent2
+agent2 spawned
+agent2 init2
+agent2 sleeping
+agent2 init2 end
+agent2 woke up
+agent2 end
+agent1 end
+```
+
+
+
+
+
+
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 This is the case for exampe if you want a synchronization (lock) among all instances of the skill: the lock should be managed by the resource itself, not by the skill. 
 
 
+## Can I make SARL wait in the execution on some thread?
 
+Yes, use something like `TimeUnit.SECONDS.sleep(5)`
 
 
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 See the [Issue Codes](https://github.com/sarl/sarl/blob/master/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java) for a complete list of what can be supressed.
 
 
+## I cannot define a static field in an agent tye declaration (agent, skill, behavior), why?
+
+This is a design choice given that our entities are _agents_ and as such they should not "share" data unless done explicitly in an agent-oriented manner, for example via resources or communication channels.  
+Having static fields in agents or skills would break the "independency" of agents.
+
+It is most probable that such static data can be seen as a _resource_ outside the skill or agent, and as such it should be managed outside it (for example within a class). 
+This is the case for exampe if you want a synchronization (lock) among all instances of the skill: the lock should be managed by the resource itself, not by the skill. 
+
+
+
 
 
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
 2. Your `PATH` environemnt variable points to the directory where `java` and `javac` of the JDK where installed.
 3. Your `JAVA_HOME` points to the directory where the JDK was installed. Alternative, you will need to specify it in your `pom.xm`; see [here](http://roufid.com/no-compiler-is-provided-in-this-environment/) .
 
------------------------
-# SARL
 
 
 
+-----------------------
+# SARL
+
 ### SARL is similar to Java but has different syntax in many places, how come?
 
 Because it uses and builts on [XTEND](https://www.eclipse.org/xtend/documentation/203_xtend_expressions.html) framework.
 	... 
 	}
 
+## SARL is giving lots of WARNINGS at compile time, how can I avoid them?
+
+You can use `@SupressWarning(..)` annotations in the entities you do not want to be warned. For example, a typical warning SARL will give is lack of synchronization for variables that can be accessed/edited concurrently:
+
+    [WARNING] The field noToSpawn should be synchronized for avoiding value inconsistency due to parallel execution. [/home/ssardina/git/soft/agents/MASSIM/AgentsInCity/sarl-agtcity-base.git/src/main/sarl/au/edu/rmit/agtgrp/agtcity/sarl/agents/dummy/BootMultiSWIAgents.sarl:70]
+
+To get rid of such warnings, assuming you are aware of the potentiall issue and have planned for it, you can do:
+
+    @SuppressWarnings("potential_field_synchronization_problem")
+    agent BootMultiSWIAgents {
+    ..
+    }
+
+See the [Issue Codes](https://github.com/sarl/sarl/blob/master/main/coreplugins/io.sarl.lang/src/io/sarl/lang/validation/IssueCodes.java) for a complete list of what can be supressed.
+
+
+
+
Updated by Sebastian Sardina

File SARL-FAQ.markdown Modified

  • Ignore whitespace
  • Hide word diff
-# FAQ for using SARL + SWI Prolog
+# FAQ for using SARL + SWI Prolog + Maven
 
 This is a collection of questions/issues that arose from my teaching of Agent Oriented Programming, where I have assessments in [SARL](http://www.sarl.io/) and [SWI Prolog](http://www.swi-prolog.org/), all packaged with [Apache Maven](https://maven.apache.org/).
 
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.