From 75feb5c4ae67566bada789f27a2df2e2cb641b11 Mon Sep 17 00:00:00 2001 From: reynisson Date: Sun, 14 Nov 2021 23:33:23 +0100 Subject: [PATCH] Renaming and small refactoring --- .../common/clients/TapasMqttClient.java | 8 ++++---- .../ExecutorAddedEventListenerMqttAdapter.java | 4 ++-- ...ner.java => ExecutorEventMqttListener.java} | 2 +- ....java => ExecutorEventsMqttDispatcher.java} | 18 ++++-------------- ...xecutorRemovedEventListenerMqttAdapter.java | 2 +- 5 files changed, 12 insertions(+), 22 deletions(-) rename roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/{AuctionEventMqttListener.java => ExecutorEventMqttListener.java} (82%) rename roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/{AuctionEventsMqttDispatcher.java => ExecutorEventsMqttDispatcher.java} (61%) diff --git a/roster/src/main/java/ch/unisg/roster/roster/adapter/common/clients/TapasMqttClient.java b/roster/src/main/java/ch/unisg/roster/roster/adapter/common/clients/TapasMqttClient.java index 8b5411b..78f2d0c 100644 --- a/roster/src/main/java/ch/unisg/roster/roster/adapter/common/clients/TapasMqttClient.java +++ b/roster/src/main/java/ch/unisg/roster/roster/adapter/common/clients/TapasMqttClient.java @@ -1,6 +1,6 @@ package ch.unisg.roster.roster.adapter.common.clients; -import ch.unisg.roster.roster.adapter.in.messaging.mqtt.AuctionEventsMqttDispatcher; +import ch.unisg.roster.roster.adapter.in.messaging.mqtt.ExecutorEventsMqttDispatcher; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.paho.client.mqttv3.*; @@ -25,9 +25,9 @@ public class TapasMqttClient { private final MessageReceivedCallback messageReceivedCallback; - private final AuctionEventsMqttDispatcher dispatcher; + private final ExecutorEventsMqttDispatcher dispatcher; - private TapasMqttClient(String brokerAddress, AuctionEventsMqttDispatcher dispatcher) { + private TapasMqttClient(String brokerAddress, ExecutorEventsMqttDispatcher dispatcher) { this.mqttClientId = UUID.randomUUID().toString(); this.brokerAddress = brokerAddress; @@ -37,7 +37,7 @@ public class TapasMqttClient { } public static synchronized TapasMqttClient getInstance(String brokerAddress, - AuctionEventsMqttDispatcher dispatcher) { + ExecutorEventsMqttDispatcher dispatcher) { if (tapasClient == null) { tapasClient = new TapasMqttClient(brokerAddress, dispatcher); diff --git a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorAddedEventListenerMqttAdapter.java b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorAddedEventListenerMqttAdapter.java index dd9257e..1c3cbcd 100644 --- a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorAddedEventListenerMqttAdapter.java +++ b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorAddedEventListenerMqttAdapter.java @@ -12,7 +12,7 @@ import ch.unisg.roster.roster.application.handler.ExecutorAddedHandler; import ch.unisg.roster.roster.application.port.in.ExecutorAddedEvent; import ch.unisg.roster.roster.domain.valueobject.ExecutorType; -public class ExecutorAddedEventListenerMqttAdapter extends AuctionEventMqttListener { +public class ExecutorAddedEventListenerMqttAdapter extends ExecutorEventMqttListener { private static final Logger LOGGER = LogManager.getLogger(ExecutorAddedEventListenerMqttAdapter.class); @Override @@ -24,7 +24,7 @@ public class ExecutorAddedEventListenerMqttAdapter extends AuctionEventMqttListe // representation that makes sense in the context of your application. JsonNode data = new ObjectMapper().readTree(payload); - String taskType = data.get("taskType").asText(); + String taskType = data.get("executorTaskType").asText(); String executorId = data.get("executorURI").asText(); ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent( diff --git a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventMqttListener.java b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventMqttListener.java similarity index 82% rename from roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventMqttListener.java rename to roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventMqttListener.java index 6eb109f..df46b00 100644 --- a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventMqttListener.java +++ b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventMqttListener.java @@ -5,7 +5,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; /** * Abstract MQTT listener for auction-related events */ -public abstract class AuctionEventMqttListener { +public abstract class ExecutorEventMqttListener { public abstract boolean handleEvent(MqttMessage message); } diff --git a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventsMqttDispatcher.java b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventsMqttDispatcher.java similarity index 61% rename from roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventsMqttDispatcher.java rename to roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventsMqttDispatcher.java index d19c803..caa6202 100644 --- a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/AuctionEventsMqttDispatcher.java +++ b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorEventsMqttDispatcher.java @@ -6,20 +6,10 @@ import java.util.Hashtable; import java.util.Map; import java.util.Set; -/** - * Dispatches MQTT messages for known topics to associated event listeners. Used in conjunction with - * {@link ch.unisg.tapas.auctionhouse.adapter.common.clients.TapasMqttClient}. - * - * This is where you would define MQTT topics and map them to event listeners (see - * {@link AuctionEventsMqttDispatcher#initRouter()}). - * - * This class is only provided as an example to help you bootstrap the project. You are welcomed to - * change this class as you see fit. - */ -public class AuctionEventsMqttDispatcher { - private final Map router; +public class ExecutorEventsMqttDispatcher { + private final Map router; - public AuctionEventsMqttDispatcher() { + public ExecutorEventsMqttDispatcher() { this.router = new Hashtable<>(); initRouter(); } @@ -46,7 +36,7 @@ public class AuctionEventsMqttDispatcher { * @param message the received MQTT message */ public void dispatchEvent(String topic, MqttMessage message) { - AuctionEventMqttListener listener = router.get(topic); + ExecutorEventMqttListener listener = router.get(topic); listener.handleEvent(message); } } diff --git a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorRemovedEventListenerMqttAdapter.java b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorRemovedEventListenerMqttAdapter.java index d7b5067..71af86d 100644 --- a/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorRemovedEventListenerMqttAdapter.java +++ b/roster/src/main/java/ch/unisg/roster/roster/adapter/in/messaging/mqtt/ExecutorRemovedEventListenerMqttAdapter.java @@ -11,7 +11,7 @@ import ch.unisg.common.valueobject.ExecutorURI; import ch.unisg.roster.roster.application.handler.ExecutorRemovedHandler; import ch.unisg.roster.roster.application.port.in.ExecutorRemovedEvent; -public class ExecutorRemovedEventListenerMqttAdapter extends AuctionEventMqttListener { +public class ExecutorRemovedEventListenerMqttAdapter extends ExecutorEventMqttListener { private static final Logger LOGGER = LogManager.getLogger(ExecutorRemovedEventListenerMqttAdapter.class); @Override