From 930b3f29f788d7866d66fcb9e946f5947782d968 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 8 Aug 2016 11:01:02 +0300 Subject: juick-ws: components as async beans --- .../src/main/java/com/juick/ws/XMPPConnection.java | 5 +-- .../juick/ws/components/CrosspostComponent.java | 4 +-- .../com/juick/ws/components/JuickComponent.java | 8 +++++ .../com/juick/ws/components/PushComponent.java | 4 +-- .../com/juick/ws/components/XMPPComponent.java | 4 +-- .../ws/configuration/WebsocketConfiguration.java | 36 ++++++++++++++++++++++ 6 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 juick-ws/src/main/java/com/juick/ws/components/JuickComponent.java (limited to 'juick-ws') diff --git a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java index da064726..77a95159 100644 --- a/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java +++ b/juick-ws/src/main/java/com/juick/ws/XMPPConnection.java @@ -3,6 +3,7 @@ package com.juick.ws; import com.juick.User; import com.juick.json.MessageSerializer; import com.juick.server.SubscriptionsQueries; +import com.juick.ws.components.JuickComponent; import com.juick.xmpp.JID; import com.juick.xmpp.Message; import com.juick.xmpp.Stream; @@ -29,7 +30,7 @@ import java.util.stream.Collectors; * @author ugnich */ @Component -public class XMPPConnection implements InitializingBean, Stream.StreamListener, Message.MessageListener { +public class XMPPConnection implements JuickComponent, Stream.StreamListener, Message.MessageListener { private static final Logger logger = Logger.getLogger(XMPPConnection.class.getName()); @Inject JdbcTemplate sql; @@ -42,7 +43,7 @@ public class XMPPConnection implements InitializingBean, Stream.StreamListener, @Async @Override - public void afterPropertiesSet() { + public void init() { xmppPassword = env.getProperty("xmpp_password"); ms = new MessageSerializer(); try { diff --git a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java b/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java index 977e0ed0..14d65d07 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java @@ -52,7 +52,7 @@ import java.util.logging.Logger; * @author Ugnich Anton */ @Component -public class CrosspostComponent implements InitializingBean, DisposableBean, Stream.StreamListener, Message.MessageListener { +public class CrosspostComponent implements JuickComponent, DisposableBean, Stream.StreamListener, Message.MessageListener { private static Logger logger = Logger.getLogger(CrosspostComponent.class.getName()); @@ -68,7 +68,7 @@ public class CrosspostComponent implements InitializingBean, DisposableBean, Str @Async @Override - public void afterPropertiesSet() throws Exception { + public void init() { logger.info("component initialized"); try { twitter_consumer_key = env.getProperty("twitter_consumer_key", ""); diff --git a/juick-ws/src/main/java/com/juick/ws/components/JuickComponent.java b/juick-ws/src/main/java/com/juick/ws/components/JuickComponent.java new file mode 100644 index 00000000..0f53ed66 --- /dev/null +++ b/juick-ws/src/main/java/com/juick/ws/components/JuickComponent.java @@ -0,0 +1,8 @@ +package com.juick.ws.components; + +/** + * Created by vitalyster on 08.08.2016. + */ +public interface JuickComponent { + void init(); +} diff --git a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java index 325f4a7e..75c42b2c 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/PushComponent.java @@ -69,7 +69,7 @@ import java.util.stream.Collectors; * @author Ugnich Anton */ @Component -public class PushComponent implements InitializingBean, DisposableBean, Stream.StreamListener, MessageListener { +public class PushComponent implements JuickComponent, DisposableBean, Stream.StreamListener, MessageListener { private static Logger logger = Logger.getLogger(PushComponent.class.getName()); @@ -84,7 +84,7 @@ public class PushComponent implements InitializingBean, DisposableBean, Stream.S @Async @Override - public void afterPropertiesSet() { + public void init() { logger.info("component initialized"); wns_application_sip = env.getProperty("wns_application_sip", ""); wns_client_secret = env.getProperty("wns_client_secret", ""); diff --git a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java index c0216eb2..7240769e 100644 --- a/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java +++ b/juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java @@ -39,7 +39,7 @@ import java.util.logging.Logger; * @author ugnich */ @Component -public class XMPPComponent implements InitializingBean, DisposableBean, Stream.StreamListener, +public class XMPPComponent implements JuickComponent, DisposableBean, Stream.StreamListener, Message.MessageListener, Iq.IqListener, Presence.PresenceListener { private static final Logger logger = Logger.getLogger(XMPPComponent.class.getName()); @@ -180,7 +180,7 @@ public class XMPPComponent implements InitializingBean, DisposableBean, Stream.S @Async @Override - public void afterPropertiesSet() { + public void init() { logger.info("component initialized"); try { diff --git a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java index 92b61bc7..086ae4ce 100644 --- a/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java +++ b/juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java @@ -3,6 +3,10 @@ package com.juick.ws.configuration; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.ws.WebsocketComponent; +import com.juick.ws.XMPPConnection; +import com.juick.ws.components.CrosspostComponent; +import com.juick.ws.components.PushComponent; +import com.juick.ws.components.XMPPComponent; import com.mitchellbosecke.pebble.PebbleEngine; import com.mitchellbosecke.pebble.loader.Loader; import com.mitchellbosecke.pebble.loader.ServletLoader; @@ -41,6 +45,14 @@ import java.util.List; public class WebsocketConfiguration extends WebMvcConfigurationSupport implements WebSocketConfigurer { @Inject Environment env; + @Inject + XMPPComponent ws; + @Inject + CrosspostComponent crosspost; + @Inject + PushComponent push; + @Inject + XMPPConnection xmpp; @Bean WebsocketComponent wsHandler() { return new WebsocketComponent(); @@ -82,6 +94,30 @@ public class WebsocketConfiguration extends WebMvcConfigurationSupport implement viewResolver.setPebbleEngine(pebbleEngine()); return viewResolver; } + @Bean + public XMPPConnection ws() { + XMPPConnection ws = new XMPPConnection(); + ws.init(); + return ws; + } + @Bean + public XMPPComponent xmpp() { + XMPPComponent xmpp = new XMPPComponent(); + xmpp.init(); + return xmpp; + } + @Bean + public CrosspostComponent crosspost() { + CrosspostComponent crosspost = new CrosspostComponent(); + crosspost.init(); + return crosspost; + } + @Bean + public PushComponent push() { + PushComponent push = new PushComponent(); + push.init(); + return push; + } @Override public RequestMappingHandlerMapping requestMappingHandlerMapping() { -- cgit v1.2.3