Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update politics, fix bugs, #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/fr/labri/starnet/SimulationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public SimulationFactory setPolicyAdapterFactory(String path) throws JDOMExcepti
public SimulationFactory setPolicyAdapterFactory(String path, String namespace) throws JDOMException, IOException {
ClassLoader cl = new AutoQualifiedClassLoader(DEFAULT_NAMESPACE);
if(!DEFAULT_NAMESPACE.equals(namespace))
cl = new AutoQualifiedClassLoader(namespace);
cl = new AutoQualifiedClassLoader(namespace, cl);

final TimedAutomataFactory<INode> timaFactory = new TimedAutomataFactory<>(TimedAutomataFactory.getReflectNodeBuilder(cl, INode.class));
timaFactory.loadXML(getClass().getResourceAsStream(path));
timaFactory.loadXML(getClass().getResourceAsStream(path)).get(0).compile();

_policyAdapterFactory = new PolicyAdapterFactory() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public static class InitEnv extends ActionAdapter<INode> {
public Map<String, Object> storage;

@Override
public void preAction(INode context, String key) {
public void postAction(INode context, String key) {
System.out.println("InitEnv");
storage = context.getStorage();
storage.put(CommonVar.DATA_SET, new DataSet());
storage.put(CommonVar.HELLO_SET, new HelloSet());
Expand All @@ -29,6 +30,7 @@ public static class SaveMailBox extends ActionAdapter<INode> {

@Override
public void postAction(INode context, String key) {
System.out.println("SaveMailBox");
storage = context.getStorage();
Message[] r = context.receive();
Deque<Message> stack = new ArrayDeque<Message>(Arrays.asList(r));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ public class DataActions {
public static class AddToDataSet extends ITimedAutomata.ActionAdapter<INode> {
@Override
public void postAction(INode context, String key) {
System.out.println("AddToDataSet");
Utils.addToSet(context.getStorage(), CommonVar.DATA_SET, CommonVar.CURRENT_MESSAGE);
}
}

public static class AddToForwardedSet extends ITimedAutomata.ActionAdapter<INode> {
@Override
public void postAction(INode context, String key) {
System.out.println("AddToForwardSet");
Utils.addToSet(context.getStorage(), CommonVar.FORWARDED_MESSAGE_SET, CommonVar.CURRENT_MESSAGE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class HelloActions {
public static class AddToHelloSet extends ActionAdapter<INode> {
@Override
public void postAction(INode context, String key) {
System.out.println("AddToHelloSet");
Utils.addToSet(context.getStorage(), CommonVar.HELLO_SET, CommonVar.CURRENT_MESSAGE);
}
}
Expand All @@ -30,6 +31,7 @@ public void postAction(INode context, String key) {
public static class SendHello extends ActionAdapter<INode> {
@Override
public void postAction(INode context, String key) {
System.out.println("SendHello");
context.send(context.newMessage().create(Message.Type.HELLO));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class IsEmpty extends PredicateAdapter<INode> {
public IsEmpty() {}
@Override
public boolean isValid(INode context, String key) {
System.out.println("IsEmpty");
return isEmpty(context.getStorage(),CommonVar.HELLO_SET);
}
}
Expand All @@ -24,6 +25,7 @@ public static class IsNotEmpty extends PredicateAdapter<INode> {
public IsNotEmpty() {}
@Override
public boolean isValid(INode context, String key) {
System.out.println("IsNotEmpty");
return !isEmpty(context.getStorage(),CommonVar.HELLO_SET);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MailBoxGuards {
static public boolean popIfTypeAndSetCurrent(Map<String,Object> storage, Message.Type type) {
@SuppressWarnings("unchecked")
Deque<Message> mailbox = (Deque<Message>) storage.get(CommonVar.SAVED_MAILBOX);
if(mailbox.peek().getType()==type){
if(!mailbox.isEmpty() && mailbox.peek().getType()==type){
storage.put(CommonVar.CURRENT_MESSAGE, mailbox.pop());
return true;
}
Expand All @@ -24,6 +24,7 @@ public static class PopAndIsHelloMsg extends PredicateAdapter<INode> {
public PopAndIsHelloMsg() {}
@Override
public boolean isValid(INode context, String key) {
System.out.println("IsHello");
return popIfTypeAndSetCurrent(context.getStorage(), Message.Type.HELLO);
}
}
Expand All @@ -32,6 +33,7 @@ public static class PopAndIsDataMsg extends PredicateAdapter<INode> {
public PopAndIsDataMsg() {}
@Override
public boolean isValid(INode context, String key) {
System.out.println("IsData");
return popIfTypeAndSetCurrent(context.getStorage(), Message.Type.DATA);
}
}
Expand All @@ -48,6 +50,7 @@ public static class IsEmpty extends PredicateAdapter<INode> {
public IsEmpty() {}
@Override
public boolean isValid(INode context, String key) {
System.out.println("MailBoxIsEmpty");
return Utils.isEmpty(context.getStorage(),CommonVar.SAVED_MAILBOX);
}
}
Expand All @@ -56,7 +59,8 @@ public static class IsNotEmpty extends PredicateAdapter<INode> {
public IsNotEmpty() {}
@Override
public boolean isValid(INode context, String key) {
return !Utils.isEmpty(context.getStorage(),CommonVar.SAVED_MAILBOX);
System.out.println("MailBoxIsNotEmpty");
return !Utils.isEmpty(context.getStorage(), CommonVar.SAVED_MAILBOX);
}
}
}
69 changes: 0 additions & 69 deletions src/main/java/fr/labri/starnet/policies/push/GossipPush.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class ShouldForwardMsg extends PredicateAdapter<INode> {
DataSet data_set;
@Override
public boolean isValid(INode context, String key) {
System.out.println("ShouldForwardMsg");
storage= context.getStorage();
Message msg = (Message) storage.get(CommonVar.CURRENT_MESSAGE);
data_set=(DataSet) storage.get(CommonVar.DATA_SET);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fr/labri/starnet/policies/rbop/RBOP.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</state>
<state name="update_rng" urgent="true">
<action type="RBOPActions$UpdateRng"/>
<path guard="RBOPActions$isRngEmpty" to="end" />
<path guard="RBOPActions$True" to="end" />
<path guard="BasicGuards$True" to="forward_now" />
</state>
<state name="forward_now" urgent="true">
Expand Down
27 changes: 10 additions & 17 deletions src/main/resources/fr/labri/starnet/policies/push/GossipPush.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<timedautomata name="GossipPush" xmlns="http://se.labri.fr/tima"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://se.labri.fr/tima http://www.labri.fr/~fmoranda/xsd/tima.xsd">
<timedautomata name="GossipPush" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.labri.fr/~fmoranda/xsd/tima.xsd">

<state name="init" initial="true" urgent="true" >
<action type="BasicActions$InitEnv"/>
<spawn name="heart_beat" />
<spawn name="clean_beat" />
<path guard="BasicGuards$True" to="mailbox" timeout="10"/>
<timeout to="pop_mailbox"/>
<path guard="BasicGuards$True" to="wait_next_any_msg"/>
</state>

<state name="mailbox" urgent="true" action="BasicActions$SaveMailBox" >
<path guard="MailBoxGuards$MailBoxIsNotEmpty" to="pop_mailbox" />
<path guard="BasicGuards$True" to="wait_next_any_msg" />

<state name="wait_next_any_msg">
<path guard="MailBoxGuards$IsNotEmpty" to="mailbox" />
</state>

<state name="pop_mailbox" urgent="true" >
<state name="mailbox" urgent="true" action="BasicActions$SaveMailBox" >
<path guard="MailBoxGuards$PopAndIsHelloMsg" to="add_to_hello_set" />
<path guard="MailBoxGuards$PopAndIsDataMsg" to="add_to_data_set" />
<path guard="BasicGuards$True" to="wait_next_any_msg" />
</state>

<state name="wait_next_any_msg" urgent="false">
<path guard="BasicGuards$True" to="mailbox" />
</state>

<state name="add_to_hello_set" action="HelloActions$AddToHelloSet"
urgent="true">
<path guard="BasicGuards$True" to="pop_mailbox" />
<path guard="BasicGuards$True" to="mailbox" />
</state>

<state name="add_to_data_set" action="DataActions$AddToDataSet"
Expand All @@ -39,12 +32,12 @@

<state name="broadcast_data_msg" urgent="true" action="GossipPushActions$DecreaseTTL">
<path guard="GossipPushGuards$ShouldForwardMsg" to="forward_msg_now" />
<path guard="BasicGuards$True" to="pop_mailbox" />
<path guard="BasicGuards$True" to="mailbox" />
</state>

<state name="forward_msg_now" action="GossipPushActions$ForwardMsgToRandomNeighbors"
urgent="true">
<path guard="BasicGuards$True" to="pop_mailbox" />
<path guard="BasicGuards$True" to="mailbox" />
</state>

<timedautomata name="heart_beat">
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/fr/labri/starnet/TestSimuDav.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package fr.labri.starnet;

import java.io.IOException;

import org.jdom2.JDOMException;

import fr.labri.starnet.models.FailureModel;
import fr.labri.starnet.models.RandomSend;
import fr.labri.starnet.ui.SimpleUI;

public class TestSimuDav {

public static void main(String[] args) throws JDOMException, IOException {
SimulationFactory factory = new SimulationFactory().add(new FailureModel()).add(new RandomSend());
factory.setPolicyAdapterFactory("fr.labri.starnet.policies.push.GossipPush");
Simulation simu = factory.createSimulation();
SimpleUI.createDefaultLayout(simu).setVisible(true);
simu.start();
}

}
2 changes: 1 addition & 1 deletion src/test/java/fr/labri/tima/TestViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestViewer {
public static void main(String[] args) throws JDOMException, IOException {

SimpleNodeFactory<String> factory = new SimpleNodeFactory<String>();
List<TimedAutomata<String>> autos = new TimedAutomataFactory<String>(factory).loadXML(TestViewer.class.getResourceAsStream("/fr/labri/starnet/policies/pull/GossipPull.xml"));
List<TimedAutomata<String>> autos = new TimedAutomataFactory<String>(factory).loadXML(TestViewer.class.getResourceAsStream("/fr/labri/starnet/policies/push/GossipPush.xml"));

JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand Down