Implemented the handling of the mqtt executor removed event

This commit is contained in:
reynisson 2021-11-14 19:26:19 +01:00
parent 1d9459d8f3
commit 1b7395ba0d
3 changed files with 6 additions and 6 deletions

View File

@ -27,6 +27,7 @@ public class AuctionEventsMqttDispatcher {
// TODO: Register here your topics and event listener adapters // TODO: Register here your topics and event listener adapters
private void initRouter() { private void initRouter() {
router.put("ch/unisg/tapas/executors/added", new ExecutorAddedEventListenerMqttAdapter()); router.put("ch/unisg/tapas/executors/added", new ExecutorAddedEventListenerMqttAdapter());
router.put("ch/unisg/tapas/executors/removed", new ExecutorRemovedEventListenerMqttAdapter());
} }
/** /**

View File

@ -11,6 +11,8 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttMessage; import org.eclipse.paho.client.mqttv3.MqttMessage;
import java.net.URI;
/** /**
* Listener that handles events when an executor was removed to this TAPAS application. * Listener that handles events when an executor was removed to this TAPAS application.
* *
@ -28,14 +30,14 @@ public class ExecutorRemovedEventListenerMqttAdapter extends AuctionEventMqttLis
// 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 executorId = data.get("executorId").asText(); String executorUri = data.get("executorUri").asText();
ExecutorRemovedEvent executorRemovedEvent = new ExecutorRemovedEvent( ExecutorRemovedEvent executorRemovedEvent = new ExecutorRemovedEvent(
new ExecutorRegistry.ExecutorIdentifier(executorId) new ExecutorRegistry.ExecutorUri(URI.create(executorUri))
); );
ExecutorRemovedHandler newExecutorHandler = new ExecutorRemovedHandler(); ExecutorRemovedHandler newExecutorHandler = new ExecutorRemovedHandler();
newExecutorHandler.handleNewExecutorEvent(executorRemovedEvent); newExecutorHandler.handleExecutorRemovedEvent(executorRemovedEvent);
} catch (JsonProcessingException | NullPointerException e) { } catch (JsonProcessingException | NullPointerException e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
return false; return false;

View File

@ -16,7 +16,4 @@ public class ExecutorRemovedHandler implements ExecutorRemovedEventHandler {
public boolean handleExecutorRemovedEvent(ExecutorRemovedEvent executorRemovedEvent) { public boolean handleExecutorRemovedEvent(ExecutorRemovedEvent executorRemovedEvent) {
return ExecutorRegistry.getInstance().removeExecutor(executorRemovedEvent.getExecutorUri()); return ExecutorRegistry.getInstance().removeExecutor(executorRemovedEvent.getExecutorUri());
} }
public void handleNewExecutorEvent(ExecutorRemovedEvent executorRemovedEvent) {
}
} }