diff --git a/src/main/jastadd/engine/balloonMarking/BalloonExecution.jadd b/src/main/jastadd/engine/balloonMarking/BalloonExecution.jadd index f934af43c1e20231bacaee83e3f67f16b10eaee4..e0d5630c2ab762465db978be0ab5322378444940 100644 --- a/src/main/jastadd/engine/balloonMarking/BalloonExecution.jadd +++ b/src/main/jastadd/engine/balloonMarking/BalloonExecution.jadd @@ -30,7 +30,7 @@ aspect BalloonExecution{ for(Map.Entry<String, ArrayList<String>> entry : reqMap.entrySet()){ for(String s : entry.getValue()){ - if(s.equals(bmp.getPlace().getId()) || + if(s.replace("\n", "").replace(" ", "").equals(bmp.getPlace().getId().replace(" ", "").replace("\n", "")) || (bmp.getPlace().getId().startsWith(s) && bmp.getPlace().getId().contains("-INSTANCE-"))){ System.out.println("Calling service from orphan request place: " + bmp.getPlace().getId()); node.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_SERVICE_REQ_CLIENT, bmp.getPlace().getId())); diff --git a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosDefaultNode.java b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosDefaultNode.java index bfbbd917dccb5804fa8f10b5649b35b30b32df40..c7183a72fa0cac74ebd1c8dbacc6e17799ef7306 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosDefaultNode.java +++ b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosDefaultNode.java @@ -25,10 +25,34 @@ public class DiNeRosDefaultNode extends DiNeRosNode{ } protected TransitionSelectionResult onChange(List<Transition> enabledTransitions){ - return null; + + printTransitions(enabledTransitions); + + if(enabledTransitions.size() == 0){ + return new FiringSelectionNone(); + } + + TransitionSelectionResult res = fireRandomEnabledTransition(enabledTransitions); + System.out.println("Selected transition: " + res.asFiringSelectionSuccess().getTransition().getId()); + return res; } protected TransitionSelectionResult onStartupEnded(List<Transition> enabledTransitions){ - return null; + + printTransitions(enabledTransitions); + + if(enabledTransitions.size() == 0){ + return new FiringSelectionNone(); + } + + TransitionSelectionResult res = fireRandomEnabledTransition(enabledTransitions); + System.out.println("Selected transition: " + res.asFiringSelectionSuccess().getTransition().getId()); + return res; + } + + public static void printTransitions(List<Transition> list){ + for(Transition t : list){ + System.out.println("Enabled t: " + t.getId()); + } } } diff --git a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosNode.java b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosNode.java index 8f32ae7e01cfd09e034ff70253c0b6c2128e58f1..810bafad75316dfb3e0b12d1140e4e75ab636ea0 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosNode.java +++ b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/DiNeRosNode.java @@ -1,5 +1,8 @@ package de.tudresden.inf.st.pnml.engine.ros; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import de.tudresden.inf.st.pnml.base.constants.PnmlConstants; import de.tudresden.inf.st.pnml.base.data.ClauseValuesDefinition; import de.tudresden.inf.st.pnml.engine.event.DiNeRosEvent; @@ -28,6 +31,7 @@ import std_msgs.String; import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.lang.reflect.Type; import java.util.*; import java.util.function.Function; @@ -141,13 +145,14 @@ public abstract class DiNeRosNode extends AbstractNodeMain { private void onTopicPublisherAvailable(java.lang.String placeId) { - java.lang.String[] split = placeId.split("-"); + java.lang.String[] split = placeId.split("-INSTANCE-"); java.lang.String originalId = split[0]; - java.lang.String topicName = petriNet.getPortNameByPlaceId(originalId); + java.lang.String topicName = petriNet.getPortNameByPlaceId(originalId, PnmlConstants.CHANNEL_PLACE_TYPE_PUB_KEY); Place place = petriNet.getPlaceById(placeId); BalloonMarkedPlace bmp = this.marking.resolveBalloonPlace(place); RosCommunicationUtil.publish(topicName, bmp.getBalloonMarking(0).getValue().getBytes(), this.connectedNode, getPublisherByPlaceId(placeId)); + System.out.println("[DiNeROS-Node] [" + nodeName + "] Published msg: " + bmp.getBalloonMarking(0).getValue()); bmp.getBalloonMarking(0).removeSelf(); petriNet.flushTreeCache(); this.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_MARKING_CHANGE)); @@ -178,15 +183,15 @@ public abstract class DiNeRosNode extends AbstractNodeMain { // crop name if place is within a server instance // Naming pattern is here: original PlaceID + "-INSTANCE-" + instanceId - java.lang.String[] split = placeId.split("-"); + java.lang.String[] split = placeId.split("-INSTANCE-"); java.lang.String originalId = split[0]; - java.lang.String serviceName = petriNet.getPortNameByPlaceId(originalId); + java.lang.String serviceName = petriNet.getPortNameByPlaceId(originalId, PnmlConstants.CHANNEL_PLACE_TYPE_CLIENT_REQ_KEY); java.lang.String cResPlaceId; if(split.length > 1){ - cResPlaceId = petriNet.getServiceClientResponsePlaceId(originalId) + "-INSTANCE-" + placeId.split("-")[split.length - 1]; + cResPlaceId = petriNet.getServiceClientResponsePlaceId(originalId) + "-INSTANCE-" + placeId.split("-INSTANCE-")[split.length - 1]; } else { cResPlaceId = petriNet.getServiceClientResponsePlaceId(originalId); } @@ -208,16 +213,23 @@ public abstract class DiNeRosNode extends AbstractNodeMain { @Override public void onSuccess(StringServiceResponse stringServiceResponse) { + System.out.println("[DiNeROS-Node] [" + nodeName + "] Received response from service: " + serviceName); bmpSource.getBalloonMarking(0).removeSelf(); bmpTarget.addBalloonMarking(new BalloonToken(stringServiceResponse.getOutput(), System.currentTimeMillis())); marking.callServiceIfRequest(bmpTarget, self); - self.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_MARKING_CHANGE)); + + if(petriNet.getPortNameByPlaceId(cResPlaceId, PnmlConstants.CHANNEL_PLACE_TYPE_PUB_KEY) != null ){ + System.out.println("[DiNeROS-Node] [" + nodeName + "] Orphan publisher place ready: " + cResPlaceId); + self.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_TOPIC_PUB, cResPlaceId)); + } else { + self.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_MARKING_CHANGE)); + } serviceClient.shutdown(); } @Override public void onFailure(RemoteException e) { - System.err.println("Error while calling: token will not be removed!"); + System.err.println("[DiNeROS-Node] [" + nodeName + "] Error while calling: token will not be removed!"); serviceClient.shutdown(); } }); @@ -311,6 +323,7 @@ public abstract class DiNeRosNode extends AbstractNodeMain { @Override public void onStart(final ConnectedNode connectedNode) { + DiNeRosNode self = this; this.connectedNode = connectedNode; System.out.println("[" + nodeName + "] Initializing node"); @@ -451,6 +464,8 @@ public abstract class DiNeRosNode extends AbstractNodeMain { subscriber.addMessageListener(message -> { + System.out.println("Received new message on " + key + " : " + message.getData()); + BalloonToken bt = new BalloonToken(); bt.setValue(message.getData()); bt.setCreationTime(System.currentTimeMillis()); @@ -458,7 +473,10 @@ public abstract class DiNeRosNode extends AbstractNodeMain { BalloonMarkedPlace bmp = marking.resolveBalloonPlace(targetPlace); bmp.getBalloonMarkingList().add(bt); petriNet.flushTreeCache(); - this.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_MARKING_CHANGE)); + + if(!marking.callServiceIfRequest(bmp, self)){ + this.notify(new DiNeRosEvent(DiNeRosEventTypes.NOTIFICATION_MARKING_CHANGE)); + } }, petriNet.getChannelElementLimitById(placeId)); } @@ -499,6 +517,12 @@ public abstract class DiNeRosNode extends AbstractNodeMain { return fsc; } + protected Map<java.lang.String, Object> parseToken(java.lang.String s) { + Gson gson = new GsonBuilder().create(); + Type mapType = new TypeToken<Map<java.lang.String, Object>>(){}.getType(); + return gson.fromJson(s, mapType); + } + public boolean isServerInstancePlace(java.lang.String placeId) { return responsePlaces.contains(placeId); } diff --git a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/RosCommunicationUtil.java b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/RosCommunicationUtil.java index 2c7ad453e8894b4e1e6c61f95c44ccf6f96aa80a..4a3ea31adb44406ce0b475d2396364a53b0b6118 100644 --- a/src/main/java/de/tudresden/inf/st/pnml/engine/ros/RosCommunicationUtil.java +++ b/src/main/java/de/tudresden/inf/st/pnml/engine/ros/RosCommunicationUtil.java @@ -15,7 +15,7 @@ public class RosCommunicationUtil { pub = node.newPublisher(topic, std_msgs.String._TYPE); } - if(pub == null){ + if(pub != null){ while(true){ if(node != null){ break;