Skip to content

Commit

Permalink
[contribs] Add examples related to the tutorials.
Browse files Browse the repository at this point in the history
close #671

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 11, 2017
1 parent 9ed7a6f commit 3d620d7
Show file tree
Hide file tree
Showing 16 changed files with 641 additions and 1 deletion.
108 changes: 108 additions & 0 deletions contribs/io.sarl.examples/io.sarl.examples.plugin/ADD_EXAMPLE.md
@@ -0,0 +1,108 @@
# How to add an example

Let the example having the following identifiers:
* `io-sarl-demos-myexample`
* `io_sarl_demos_myexample`
* `io.sarl.examples.myexample`


## 1. Include the example code

1. Create the folder `projects/io-sarl-demos-myexample`.
2. Copy the example's code into the created folder.


## 2. Create the wizard for importing the example

Add in the `plugin.xml` file:


<!-- ========= io-sarl-demos-myexample Example ========= -->

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.examples.myexample"
name="%io_sarl_demos_myexample_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="org.eclipse.ui.Examples/io.sarl.Examples"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_demos_myexample_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.examples.myexample"
name="%io_sarl_demos_myexample_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="io.sarl.eclipse.category.wizards/io.sarl.project.Examples"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_demos_myexample_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.emf.common.ui.examples">
<example wizardID="io.sarl.examples.myexample" pageImage="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif">
<projectDescriptor name="io-sarl-demos-basic-myexample" contentURI="contents/io-sarl-demos-myexample.zip" description="%io_sarl_demos_myexample_Description"/>
<fileToOpen location="io-sarl-demos-myexample/path/to/the/file/to/open"/>
</example>
</extension>


Replace `path/to/the/file/to/open` by the path to the file to be opened after importing the example.


## 3. Update the localized strings.

The update explained in the previous section uses two strings in the localized properties.
Add in the `OSGI-INF/bundle.properties` file:


io_sarl_demos_myexample_Name = THE NAME OF THE EXAMPLE
io_sarl_demos_myexample_Description = THE DESCRIPTION OF THE EXAMPLE



## 4. Add a quick link in the welcome pages.

In order to add a quick link to the example, you should add into the `plugin.xml` file:


<!-- adding a new quicklink for the example -->
<extension
point="org.eclipse.ui.intro.quicklinks">
<command
id="org.eclipse.ui.newWizard(newWizardId=io.sarl.examples.myexample)"
description="%io_sarl_demos_myexample__Description"
label="%io_sarl_demos_myexample__Name"
icon="platform:/plugin/org.eclipse.ui.intro.universal/themes/circles/graphics/icons/ctool/sa_onesample48.gif">
</command>
</extension>



## 5. Add the example into the welcome page

Add into the `SARL-Example-Intro.xml` file:


<group style-id="quick-links" id="quick-links">
<link style-id="content-link" label="Description of the example in the welcome page"
url="http://org.eclipse.ui.intro/execute?command=org.eclipse.ui.newWizard%28newWizardId%3Dio.sarl.examples.myexample%29"
id="io.sarl.examples.myexample">
<text>
Detailed description of the example.
</text>
</link>
</group>



## 6. Update the building script

Add into the `build.xml` file:


<zip_example name="io-sarl-demos-myexample" />


Expand Up @@ -4,6 +4,9 @@ Bundle-Name = Examples with SARL Language
SARLExamplesCategory= SARL Example
SARLExamplesProjectCategory= Examples

SARLTutorialsCategory= SARL Tutorials
SARLTutorialsProjectCategory= Tutorials

HelloworldExample_Name= A Helloworld Agent in SARL
HelloworldExample_Description= A simple agent displaying Hello on the console and dying 2sec later.

Expand All @@ -24,3 +27,12 @@ CounterExample_Description= A first agent creates two other agents, the first on

FactorialExample_Name= Two examples of factorial computation
FactorialExample_Description= The first demo introduces a single agent computing a factorial, the second one introduces two agents in interaction: the first agent asking the second to compute the factorial value of a specified integer.

io_sarl_tutorials_holonicauction_Name = Auction between holonic members
io_sarl_tutorials_holonicauction_Description = The auctioneer creates biders in its inner context, and manages the auction.

io_sarl_tutorials_pingpong_Name = Ping-Pong event exchanges
io_sarl_tutorials_pingpong_Description = Agents are exchanging events with a ping-pong interaction protocol.

io_sarl_tutorials_pingpongspace_Name = Ping-Pong event exchanges inside a specific space
io_sarl_tutorials_pingpongspace_Description = Agents are exchanging events inside a specific space with a ping-pong interaction protocol.
3 changes: 3 additions & 0 deletions contribs/io.sarl.examples/io.sarl.examples.plugin/build.xml
Expand Up @@ -23,6 +23,9 @@
<zip_example name="io-sarl-demos-basic-holarchy" />
<zip_example name="io-sarl-demos-counter" />
<zip_example name="io-sarl-demos-factorial" />
<zip_example name="io-sarl-tutorials-holonicauction" />
<zip_example name="io-sarl-tutorials-pingpong" />
<zip_example name="io-sarl-tutorials-pingpongspace" />
<!--zip_example name="name-examples" excludes="**/*._trace,.antlr-generator*.jar"/>-->
</target>

Expand Down
Expand Up @@ -98,6 +98,44 @@
</link>
</group>

<group style-id="quick-links" id="quick-links">
<link style-id="content-link" label="Auction between holonic members"
url="http://org.eclipse.ui.intro/execute?command=org.eclipse.ui.newWizard%28newWizardId%3Dio.sarl.tutorials.holonicauction%29"
id="io.sarl.tutorials.holonicauction">
<text>
This project contains the code of the official tutorial related to holonic auctions.
The auctioneer creates bidding agents into its inner context.
The bidding agents send their offers to the parent agent, i.e. the auctioneer.
The auctioneer selects the best offer.
</text>
</link>
</group>

<group style-id="quick-links" id="quick-links">
<link style-id="content-link" label="Agent interaction with Ping-Pong protocol"
url="http://org.eclipse.ui.intro/execute?command=org.eclipse.ui.newWizard%28newWizardId%3Dio.sarl.tutorials.pingpong%29"
id="io.sarl.tutorials.pingpong">
<text>
This project contains the implementation of the simple interaction protocol named "Ping-Pong".
An agent fire a ping event. The receiving agent replies with a pong event.
Then, the pong event receiver replies with a new ping event, and so on.
</text>
</link>
</group>

<group style-id="quick-links" id="quick-links">
<link style-id="content-link" label="Agent interaction inside a specific space with Ping-Pong protocol"
url="http://org.eclipse.ui.intro/execute?command=org.eclipse.ui.newWizard%28newWizardId%3Dio.sarl.tutorials.pingpongspace%29"
id="io.sarl.tutorials.pingpongspace">
<text>
This project contains the implementation of the simple interaction protocol named "Ping-Pong".
An agent fire a ping event. The receiving agent replies with a pong event.
Then, the pong event receiver replies with a new ping event, and so on.
The events are exchanged inside a specific event space.
</text>
</link>
</group>

</extensionContent>


Expand Down
107 changes: 106 additions & 1 deletion contribs/io.sarl.examples/io.sarl.examples.plugin/plugin.xml
Expand Up @@ -14,6 +14,18 @@
parentCategory="io.sarl.eclipse.category.wizards" />
</extension>

<extension point="org.eclipse.ui.newWizards">
<category id="io.sarl.Tutorials"
name="%SARLTutorialsCategory"
parentCategory="org.eclipse.ui.Examples" />
</extension>

<extension point="org.eclipse.ui.newWizards">
<category id="io.sarl.project.Tutorials"
name="%SARLTutorialsProjectCategory"
parentCategory="io.sarl.eclipse.category.wizards" />
</extension>

<!-- ========= io.sarl.demos.basic.helloworld Example ========= -->

<extension point="org.eclipse.ui.newWizards">
Expand Down Expand Up @@ -230,7 +242,100 @@
<fileToOpen location="io-sarl-demos-factorial/src/main/sarl/io/sarl/demos/factorial/basic/basicfactorial.sarl"/>
</example>
</extension>


<!-- ========= io-sarl-tutorials-holonicauction Example ========= -->

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.holonicauction"
name="%io_sarl_tutorials_holonicauction_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="org.eclipse.ui.Examples/io.sarl.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_holonicauction_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.holonicauction"
name="%io_sarl_tutorials_holonicauction_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="io.sarl.eclipse.category.wizards/io.sarl.project.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_holonicauction_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.emf.common.ui.examples">
<example wizardID="io.sarl.tutorials.holonicauction" pageImage="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif">
<projectDescriptor name="io-sarl-tutorials-holonicauction" contentURI="contents/io-sarl-tutorials-holonicauction.zip" description="%io_sarl_tutorials_holonicauction_Description"/>
<fileToOpen location="io-sarl-tutorials-holonicauction/src/main/sarl/io/sarl/examples/holonicauction/auctioneer.sarl"/>
</example>
</extension>

<!-- ========= io-sarl-tutorials-pingpong Example ========= -->

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.pingpong"
name="%io_sarl_tutorials_pingpong_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="org.eclipse.ui.Examples/io.sarl.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_pingpong_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.pingpong"
name="%io_sarl_tutorials_pingpong_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="io.sarl.eclipse.category.wizards/io.sarl.project.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_pingpong_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.emf.common.ui.examples">
<example wizardID="io.sarl.tutorials.pingpong" pageImage="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif">
<projectDescriptor name="io-sarl-tutorials-pingpong" contentURI="contents/io-sarl-tutorials-pingpong.zip" description="%io_sarl_tutorials_pingpong_Description"/>
<fileToOpen location="io-sarl-tutorials-pingpong/src/main/sarl/io/sarl/examples/pingpong/boot.sarl"/>
</example>
</extension>

<!-- ========= io-sarl-tutorials-pingpongspace Example ========= -->

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.pingpongspace"
name="%io_sarl_tutorials_pingpongspace_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="org.eclipse.ui.Examples/io.sarl.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_pingpongspace_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.ui.newWizards">
<wizard id="io.sarl.tutorials.pingpongspace"
name="%io_sarl_tutorials_pingpongspace_Name"
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard"
category="io.sarl.eclipse.category.wizards/io.sarl.project.Tutorials"
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"
project="true">
<description>%io_sarl_tutorials_pingpongspace_Description</description>
</wizard>
</extension>

<extension point="org.eclipse.emf.common.ui.examples">
<example wizardID="io.sarl.tutorials.pingpongspace" pageImage="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif">
<projectDescriptor name="io-sarl-tutorials-pingpongspace" contentURI="contents/io-sarl-tutorials-pingpongspace.zip" description="%io_sarl_tutorials_pingpongspace_Description"/>
<fileToOpen location="io-sarl-tutorials-pingpongspace/src/main/sarl/io/sarl/examples/pingpongspace/boot.sarl"/>
</example>
</extension>

<!-- ========= Intro (welcome page) Extensions ========= -->

<extension
Expand Down
@@ -0,0 +1,81 @@
package io.sarl.examples.holonicauction

import io.sarl.core.Initialize
import io.sarl.core.InnerContextAccess
import io.sarl.lang.core.Address
import io.sarl.core.Lifecycle
import io.sarl.core.Schedules
import io.sarl.core.Behaviors
import io.sarl.core.Logging

agent Auctioneer {

uses Behaviors, InnerContextAccess, Lifecycle, Schedules, Logging

var maxBid = 0f
var winner : Address
var hasBid = false
var isAuctionOpened = true

on Initialize {
info("Creating bidders")
for(i : 1..3) {
spawnInContext(typeof(Bidder), innerContext)
}

info("Propose initial price: 50")
wake(new Price(50))

in(10000) [
val waitTask = task("wait-task")
waitTask.every(10000) [
synchronized(this) {
if (!isAuctionOpened) {
info("No more action: waiting for bidder death.")
if (!hasMemberAgent) {
waitTask.cancel
killMe
}
} else {
if (!hasBid) {
info("NO MORE BID")
isAuctionOpened = false
if (winner === null) {
info("No winner")
} else {
info("The winner is " + winner
+ " with the bid of " + maxBid)
}
info("Killing the bidders")
wake(new StopAuction)
}
else {
var newPrice : float
if (winner === null) {
newPrice = 50
} else {
newPrice = maxBid
}
info("NEXT BIDDING TURN: " + newPrice)
wake(new Price(newPrice))
}
hasBid = false
}
}
]
]
}

on Bid [ isAuctionOpened ] {
info("Receiving bid: " + occurrence.value)
synchronized(this) {
hasBid = true
if (occurrence.value > maxBid) {
info(" better bid")
maxBid = occurrence.value
winner = occurrence.source
}
}
}

}

0 comments on commit 3d620d7

Please sign in to comment.