From 0559e1f5239d1f5496155eacd447bdad75e19006 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 4 Oct 2018 23:02:06 +0300 Subject: Async event listeners --- .../main/java/com/juick/server/EmailManager.java | 27 ++++++++++++++++++---- .../java/com/juick/server/MessengerManager.java | 27 ++++++++++++++++++---- .../server/configuration/ApiAppConfiguration.java | 2 +- .../juick/service/activities/ActivityListener.java | 5 ++++ 4 files changed, 52 insertions(+), 9 deletions(-) (limited to 'juick-server/src/main/java') diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java index 2be21127..534de35b 100644 --- a/juick-server/src/main/java/com/juick/server/EmailManager.java +++ b/juick-server/src/main/java/com/juick/server/EmailManager.java @@ -2,15 +2,14 @@ package com.juick.server; import com.juick.Message; import com.juick.User; -import com.juick.service.component.MessageEvent; import com.juick.service.EmailService; import com.juick.service.MessagesService; import com.juick.service.UserService; +import com.juick.service.component.*; import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; @@ -32,7 +31,7 @@ import static com.juick.formatters.PlainTextFormatter.formatPost; import static com.juick.formatters.PlainTextFormatter.formatUrl; @Component -public class EmailManager implements ApplicationListener { +public class EmailManager implements NotificationListener { public static final String MSGID_PATTERN = "\\.|@|<"; @@ -44,7 +43,7 @@ public class EmailManager implements ApplicationListener { @Inject private UserService userService; @Override - public void onApplicationEvent(@Nonnull MessageEvent event) { + public void processMessageEvent(@Nonnull MessageEvent event) { Message msg = event.getMessage(); List subscribedUsers = event.getUsers(); if (msg.isService()) { @@ -69,6 +68,26 @@ public class EmailManager implements ApplicationListener { } } + @Override + public void processSubscribeEvent(SubscribeEvent subscribeEvent) { + + } + + @Override + public void processLikeEvent(LikeEvent likeEvent) { + + } + + @Override + public void processPingEvent(PingEvent pingEvent) { + + } + + @Override + public void processMessageReadEvent(MessageReadEvent messageReadEvent) { + + } + private void emailNotify(String email, String subject, Message msg) { Map headers = new HashMap<>(); if (!MessageUtils.isPM(msg)) { diff --git a/juick-server/src/main/java/com/juick/server/MessengerManager.java b/juick-server/src/main/java/com/juick/server/MessengerManager.java index 1283d8b2..90c58f03 100644 --- a/juick-server/src/main/java/com/juick/server/MessengerManager.java +++ b/juick-server/src/main/java/com/juick/server/MessengerManager.java @@ -17,17 +17,16 @@ import com.github.messenger4j.userprofile.UserProfile; import com.github.messenger4j.webhook.event.TextMessageEvent; import com.juick.Message; import com.juick.User; -import com.juick.service.component.MessageEvent; import com.juick.model.AnonymousUser; import com.juick.service.MessagesService; import com.juick.service.MessengerService; import com.juick.service.UserService; +import com.juick.service.component.*; import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; import javax.annotation.Nonnull; @@ -45,7 +44,7 @@ import static com.juick.formatters.PlainTextFormatter.formatPost; import static com.juick.formatters.PlainTextFormatter.formatUrl; @Component -public class MessengerManager implements ApplicationListener { +public class MessengerManager implements NotificationListener { private static final Logger logger = LoggerFactory.getLogger(MessengerManager.class); @Inject private MessagesService messagesService; @@ -112,7 +111,7 @@ public class MessengerManager implements ApplicationListener { } @Override - public void onApplicationEvent(@Nonnull MessageEvent event) { + public void processMessageEvent(@Nonnull MessageEvent event) { Message msg = event.getMessage(); List subscribedUsers = event.getUsers(); if (msg.isService()) { @@ -126,6 +125,26 @@ public class MessengerManager implements ApplicationListener { } } + @Override + public void processSubscribeEvent(SubscribeEvent subscribeEvent) { + + } + + @Override + public void processLikeEvent(LikeEvent likeEvent) { + + } + + @Override + public void processPingEvent(PingEvent pingEvent) { + + } + + @Override + public void processMessageReadEvent(MessageReadEvent messageReadEvent) { + + } + private void messengerNotify(String messengerUser, String text, String url) { try { if (!StringUtils.isEmpty(url)) { diff --git a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java index 45d17306..5a5d2c7b 100644 --- a/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java +++ b/juick-server/src/main/java/com/juick/server/configuration/ApiAppConfiguration.java @@ -41,7 +41,7 @@ import javax.inject.Inject; * Created by aalexeev on 11/12/16. */ @Configuration -@EnableAsync +@EnableAsync(proxyTargetClass = true) @EnableScheduling @EnableWebSocket public class ApiAppConfiguration implements WebMvcConfigurer, WebSocketConfigurer { diff --git a/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java b/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java index 3174ff23..863bda04 100644 --- a/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java +++ b/juick-server/src/main/java/com/juick/service/activities/ActivityListener.java @@ -1,14 +1,19 @@ package com.juick.service.activities; import org.springframework.context.event.EventListener; +import org.springframework.scheduling.annotation.Async; public interface ActivityListener { + @Async @EventListener void processFollowEvent(FollowEvent event); + @Async @EventListener void undoFollowEvent(UndoFollowEvent event); + @Async @EventListener void deleteUserEvent(DeleteUserEvent event); + @Async @EventListener void deleteMessageEvent(DeleteMessageEvent event); } -- cgit v1.2.3