Skip to content

Commit 3f1382c

Browse files
committed
Merge remote-tracking branch 'origin/fix/85-message-engine-slowed' into develop
2 parents 59a964b + 852be9d commit 3f1382c

File tree

63 files changed

+1479
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1479
-431
lines changed

CHANGELOG.md

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,68 @@ This file lists modifications introduced by each version.
44

55
## [Unreleased]
66

7+
### MessageEngine modifications
8+
9+
[[issue 85]][issue: #85] [[issue 83]][issue: #83]
10+
11+
Some changes have been applied in an effort to simplify, clarify and speed-up the *message engine* system.
12+
13+
* `MessageEngine` is now an interface
14+
* A `reset()` method has been added.
15+
* It does not handle delays anymore.
16+
17+
18+
* The former `MessageEngine` has been renamed to `DefaultMessageEngine`.
19+
20+
`io.jbotsim.core.MessageEngine` -> `io.jbotsim.core.DefaultMessageEngine`
21+
22+
* It does not handle delays (see `DelayMessageEngine`)
23+
* It speeds-up former check on link existence
24+
25+
* A specific `DelayMessageEngine` has been re-created in `jbotsim-core`/`io.jbotsim.core`.
26+
27+
* It handles instantaneous delays better than the former `MessageEngine` used to.
28+
* It also handles general delays better than the former `MessageEngine` used to.
29+
* A new `DelayMessageEngine.disableLinksContinuityChecks()` method has been added.
30+
31+
This method prevents the system from checking the existence of the link each step while it is delayed.
32+
The check still remains at the end of the sending round and before the delivery round.
33+
This speeds message processing up when you send a lot of delayed messages in a static environment.
34+
* `AsyncMessageEngine` and `RandomMessageEngine` implementations have been modified to benefit from the new
35+
`DelayMessageEngine` capabilities.
36+
37+
* `RandomMessageEngine` has been renamed into `RandomDelayMessageEngine`
38+
39+
`jbotsim-extras-common`/`io.jbotsim.contrib.messaging.RandomMessageEngine` -> `io.jbotsim.contrib.messaging.RandomDelayMessageEngine`
40+
41+
42+
* Test classes and examples have been added to showcase all MessageEngines behaviors
43+
44+
If you used to inherit from `MessageEngine`, you have several options:
45+
* inherit from `DefaultMessageEngine` (no delay feature)
46+
* inherit from `DelayMessageEngine` (has delay feature)
47+
* actually implement the `MessageEngine` interface
48+
49+
50+
### Node class modifications
51+
52+
**New symbols in Node:**
53+
* `Node.hasNeighbor(Node)`, `Node.hasInNeighbor(Node)`, `Node.hasOutNeighbor(Node)` have been created [[issue 85]][issue: #85]
54+
55+
These methods allow you to directly test the presence of the provided `Node` in the neighborhood of the object
56+
on which they are called. Please see documentation for details.
57+
58+
**Modifications in Node:**
59+
* `Node.getOutNeighbors()` has been improved, avoiding unnecessary copies [[issue 85]][issue: #85]
60+
61+
### Message class modifications
62+
63+
**New symbol in Message:**
64+
65+
* `Message.isRetryModeEnabled()` accessor has been created [[issue 85]][issue: #85]
66+
67+
[issue: #85]: https://github.com/jbotsim/JBotSim/issues/85
68+
769
### ClockManager class modifications
870

971
**Bug fixes in ClockManager:**
@@ -47,14 +109,6 @@ This file lists modifications introduced by each version.
47109

48110
[issue: #83]: https://github.com/jbotsim/JBotSim/issues/83
49111

50-
### MessageEngine class modification
51-
52-
**Symbol modifications in MessageEngine:**
53-
54-
* The `MessageEngine.reset()` method has been added [[issue 83]][issue: #83]
55-
56-
This method properly discards any message handled by the MessageEngine.
57-
58112
### TikzTopologySerializer class modifications
59113

60114
[[issue 80]][issue: #80]

apps/examples/src/main/java/examples/fancy/canadairs/Main.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package examples.fancy.canadairs;
22

3-
import io.jbotsim.core.Link;
4-
import io.jbotsim.core.Node;
5-
import io.jbotsim.core.Topology;
6-
import io.jbotsim.core.LinkResolver;
3+
import io.jbotsim.core.*;
74
import io.jbotsim.ui.JViewer;
85

9-
import io.jbotsim.core.Color;
10-
116
/**
127
* Created by acasteig on 22/03/15.
138
*/
@@ -36,7 +31,9 @@ public static void createMap(Topology topology){
3631
public static void main(String[] args) {
3732
topology = new Topology(800,600);
3833
topology.setLinkResolver(new Main());
39-
topology.getMessageEngine().setDelay(10);
34+
DelayMessageEngine messageEngine = new DelayMessageEngine(topology);
35+
messageEngine.setDelay(10);
36+
topology.setMessageEngine(messageEngine);
4037
createMap(topology);
4138
topology.setTimeUnit(30);
4239
topology.setDefaultNodeModel(Fire.class);

apps/examples/src/main/java/examples/features/async/AsyncExampleFIFO.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

apps/examples/src/main/java/examples/features/async/AsyncExampleGrid.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

apps/examples/src/main/java/examples/features/async/Readme.md

Whitespace-only changes.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2008 - 2020, Arnaud Casteigts and the JBotSim contributors <contact@jbotsim.io>
3+
*
4+
*
5+
* This file is part of JBotSim.
6+
*
7+
* JBotSim is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* JBotSim is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with JBotSim. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
package examples.features.messaging;
23+
24+
import io.jbotsim.core.Message;
25+
import io.jbotsim.core.Node;
26+
import io.jbotsim.core.Topology;
27+
import io.jbotsim.ui.JViewer;
28+
import io.jbotsim.contrib.messaging.AsyncMessageEngine;
29+
import io.jbotsim.gen.basic.TopologyGenerators;
30+
31+
32+
public class AsyncMessageEngineFIFOExampleMain extends Node {
33+
34+
static int msg = 0;
35+
36+
@Override
37+
public void onSelection() {
38+
int nbMsg = 50;
39+
for(int i = 0; i < nbMsg; i++)
40+
sendMessage();
41+
}
42+
43+
protected void sendMessage() {
44+
MessageContent content = new MessageContent();
45+
sendAll(new Message(content));
46+
System.out.println("["+ getID() + " - " + content.messageNumber + "] emitted at " + content.sendTime);
47+
msg++;
48+
}
49+
50+
@Override
51+
public void onMessage(Message message) {
52+
MessageContent messageContent = (MessageContent)message.getContent();
53+
int currentTime = getTime();
54+
int deliveryDuration = (currentTime - messageContent.sendTime);
55+
int messageNumber = messageContent.messageNumber;
56+
System.out.println("["+ messageNumber +"] received at " + currentTime + ", deliveryDuration = " + deliveryDuration + " rounds");
57+
}
58+
59+
public static void main(String[] args) {
60+
Topology tp = new Topology();
61+
tp.setTimeUnit(20);
62+
AsyncMessageEngine messageEngine = new AsyncMessageEngine(tp);
63+
messageEngine.setAverageDuration(20);
64+
// messageEngine.setDebug(true);
65+
tp.setMessageEngine(messageEngine);
66+
tp.setDefaultNodeModel(AsyncMessageEngineFIFOExampleMain.class);
67+
TopologyGenerators.generateLine(tp, 2);
68+
new JViewer(tp);
69+
tp.start();
70+
}
71+
72+
private class MessageContent {
73+
int messageNumber = msg;
74+
int sendTime = getTime();
75+
}
76+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2008 - 2020, Arnaud Casteigts and the JBotSim contributors <contact@jbotsim.io>
3+
*
4+
*
5+
* This file is part of JBotSim.
6+
*
7+
* JBotSim is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* JBotSim is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with JBotSim. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
package examples.features.messaging;
23+
24+
import io.jbotsim.contrib.messaging.AsyncMessageEngine;
25+
import io.jbotsim.core.MessageEngine;
26+
import io.jbotsim.core.Topology;
27+
import io.jbotsim.gen.basic.TopologyGenerators;
28+
import io.jbotsim.ui.JViewer;
29+
30+
public class AsyncMessageEngineNonFIFOExampleMain {
31+
32+
33+
public static void main(String[] args) {
34+
final Topology tp = new Topology();
35+
tp.setTimeUnit(10);
36+
tp.setDefaultNodeModel(GridMessagingNode.class);
37+
TopologyGenerators.generateGrid(tp, 10,10);
38+
new JViewer(tp);
39+
40+
MessageEngine messageEngine = new AsyncMessageEngine(tp, 10, AsyncMessageEngine.Type.NONFIFO);
41+
tp.setMessageEngine(messageEngine);
42+
43+
tp.start();
44+
}
45+
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2008 - 2019, Arnaud Casteigts and the JBotSim contributors <contact@jbotsim.io>
3+
*
4+
*
5+
* This file is part of JBotSim.
6+
*
7+
* JBotSim is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* JBotSim is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with JBotSim. If not, see <https://www.gnu.org/licenses/>.
19+
*
20+
*/
21+
22+
package examples.features.messaging;
23+
24+
import io.jbotsim.core.DelayMessageEngine;
25+
import io.jbotsim.core.Topology;
26+
import io.jbotsim.gen.basic.TopologyGenerators;
27+
import io.jbotsim.ui.JViewer;
28+
29+
30+
public class DelayMessageEngineExampleMain {
31+
32+
public static void main(String[] args) {
33+
Topology tp = new Topology();
34+
tp.setTimeUnit(10);
35+
tp.setDefaultNodeModel(GridMessagingNode.class);
36+
TopologyGenerators.generateGrid(tp, 10,10);
37+
new JViewer(tp);
38+
39+
DelayMessageEngine messageEngine = new DelayMessageEngine(tp);
40+
messageEngine.setDelay(10);
41+
messageEngine.setDebug(false);
42+
tp.setMessageEngine(messageEngine);
43+
44+
tp.start();
45+
}
46+
}

0 commit comments

Comments
 (0)