From 65ecc5ba205aa8b58fd3effad0755c8d6fcd727d Mon Sep 17 00:00:00 2001 From: anthonyraymond Date: Wed, 12 Jul 2017 00:02:02 +0200 Subject: [PATCH] Dispatch torrent file alteration to client --- .../WebTorrentFileEventListener.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/org/araymond/joal/web/services/corelistener/WebTorrentFileEventListener.java diff --git a/src/main/java/org/araymond/joal/web/services/corelistener/WebTorrentFileEventListener.java b/src/main/java/org/araymond/joal/web/services/corelistener/WebTorrentFileEventListener.java new file mode 100644 index 0000000..391c63d --- /dev/null +++ b/src/main/java/org/araymond/joal/web/services/corelistener/WebTorrentFileEventListener.java @@ -0,0 +1,57 @@ +package org.araymond.joal.web.services.corelistener; + +import org.araymond.joal.core.events.filechange.FailedToAddTorrentFileEvent; +import org.araymond.joal.core.events.filechange.TorrentFileAddedEvent; +import org.araymond.joal.core.events.filechange.TorrentFileDeletedEvent; +import org.araymond.joal.web.messages.outgoing.impl.files.FailedToAddTorrentFilePayload; +import org.araymond.joal.web.messages.outgoing.impl.files.TorrentFileAddedPayload; +import org.araymond.joal.web.messages.outgoing.impl.files.TorrentFileDeletedPayload; +import org.araymond.joal.web.services.JoalMessageSendingTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.event.EventListener; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.util.Map; + +/** + * Created by raymo on 11/07/2017. + */ + +@Service +public class WebTorrentFileEventListener extends WebEventListener { + private static final Logger logger = LoggerFactory.getLogger(WebTorrentFileEventListener.class); + + @Inject + public WebTorrentFileEventListener(final JoalMessageSendingTemplate messagingTemplate) { + super(messagingTemplate); + } + + @Order(Ordered.LOWEST_PRECEDENCE) + @EventListener + void handleTorrentFileAdded(final TorrentFileAddedEvent event) { + logger.debug("Send TorrentFileAddedPayload to clients."); + + this.messagingTemplate.convertAndSend("/torrents", new TorrentFileAddedPayload(event)); + } + + @Order(Ordered.LOWEST_PRECEDENCE) + @EventListener + void handleTorrentFileDeleted(final TorrentFileDeletedEvent event) { + logger.debug("Send TorrentFileDeletedPayload to clients."); + + this.messagingTemplate.convertAndSend("/torrents", new TorrentFileDeletedPayload(event)); + } + + @Order(Ordered.LOWEST_PRECEDENCE) + @EventListener + void handleFailedToAddTorrentFile(final FailedToAddTorrentFileEvent event) { + logger.debug("Send FailedToAddTorrentFilePayload to clients."); + + this.messagingTemplate.convertAndSend("/torrents", new FailedToAddTorrentFilePayload(event)); + } + +}