Merge pull request #64 from SCS-ASSE-FS21-Group1/fixinf_roster
Renaming and small refactoring
This commit is contained in:
		| @@ -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); | ||||
|   | ||||
| @@ -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( | ||||
|   | ||||
| @@ -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); | ||||
| } | ||||
| @@ -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<String, AuctionEventMqttListener> router; | ||||
| public class ExecutorEventsMqttDispatcher { | ||||
|     private final Map<String, ExecutorEventMqttListener> 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); | ||||
|     } | ||||
| } | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user