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; | 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.LogManager; | ||||||
| import org.apache.logging.log4j.Logger; | import org.apache.logging.log4j.Logger; | ||||||
| import org.eclipse.paho.client.mqttv3.*; | import org.eclipse.paho.client.mqttv3.*; | ||||||
| @@ -25,9 +25,9 @@ public class TapasMqttClient { | |||||||
|  |  | ||||||
|     private final MessageReceivedCallback messageReceivedCallback; |     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.mqttClientId = UUID.randomUUID().toString(); | ||||||
|         this.brokerAddress = brokerAddress; |         this.brokerAddress = brokerAddress; | ||||||
|  |  | ||||||
| @@ -37,7 +37,7 @@ public class TapasMqttClient { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static synchronized TapasMqttClient getInstance(String brokerAddress, |     public static synchronized TapasMqttClient getInstance(String brokerAddress, | ||||||
|             AuctionEventsMqttDispatcher dispatcher) { |             ExecutorEventsMqttDispatcher dispatcher) { | ||||||
|  |  | ||||||
|         if (tapasClient == null) { |         if (tapasClient == null) { | ||||||
|             tapasClient = new TapasMqttClient(brokerAddress, dispatcher); |             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.application.port.in.ExecutorAddedEvent; | ||||||
| import ch.unisg.roster.roster.domain.valueobject.ExecutorType; | 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); |     private static final Logger LOGGER = LogManager.getLogger(ExecutorAddedEventListenerMqttAdapter.class); | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
| @@ -24,7 +24,7 @@ public class ExecutorAddedEventListenerMqttAdapter extends AuctionEventMqttListe | |||||||
|             // representation that makes sense in the context of your application. |             // representation that makes sense in the context of your application. | ||||||
|             JsonNode data = new ObjectMapper().readTree(payload); |             JsonNode data = new ObjectMapper().readTree(payload); | ||||||
|  |  | ||||||
|             String taskType = data.get("taskType").asText(); |             String taskType = data.get("executorTaskType").asText(); | ||||||
|             String executorId = data.get("executorURI").asText(); |             String executorId = data.get("executorURI").asText(); | ||||||
|  |  | ||||||
|             ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent( |             ExecutorAddedEvent executorAddedEvent = new ExecutorAddedEvent( | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ import org.eclipse.paho.client.mqttv3.MqttMessage; | |||||||
| /** | /** | ||||||
|  * Abstract MQTT listener for auction-related events |  * Abstract MQTT listener for auction-related events | ||||||
|  */ |  */ | ||||||
| public abstract class AuctionEventMqttListener { | public abstract class ExecutorEventMqttListener { | ||||||
| 
 | 
 | ||||||
|     public abstract boolean handleEvent(MqttMessage message); |     public abstract boolean handleEvent(MqttMessage message); | ||||||
| } | } | ||||||
| @@ -6,20 +6,10 @@ import java.util.Hashtable; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| 
 | 
 | ||||||
| /** | public class ExecutorEventsMqttDispatcher { | ||||||
|  * Dispatches MQTT messages for known topics to associated event listeners. Used in conjunction with |     private final Map<String, ExecutorEventMqttListener> router; | ||||||
|  * {@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 AuctionEventsMqttDispatcher() { |     public ExecutorEventsMqttDispatcher() { | ||||||
|         this.router = new Hashtable<>(); |         this.router = new Hashtable<>(); | ||||||
|         initRouter(); |         initRouter(); | ||||||
|     } |     } | ||||||
| @@ -46,7 +36,7 @@ public class AuctionEventsMqttDispatcher { | |||||||
|      * @param message the received MQTT message |      * @param message the received MQTT message | ||||||
|      */ |      */ | ||||||
|     public void dispatchEvent(String topic, MqttMessage message) { |     public void dispatchEvent(String topic, MqttMessage message) { | ||||||
|         AuctionEventMqttListener listener = router.get(topic); |         ExecutorEventMqttListener listener = router.get(topic); | ||||||
|         listener.handleEvent(message); |         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.handler.ExecutorRemovedHandler; | ||||||
| import ch.unisg.roster.roster.application.port.in.ExecutorRemovedEvent; | 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); |     private static final Logger LOGGER = LogManager.getLogger(ExecutorRemovedEventListenerMqttAdapter.class); | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user