aboutsummaryrefslogtreecommitdiff
path: root/juick-ws/src/main/java/com/juick/ws
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-08-08 11:01:02 +0300
committerGravatar Vitaly Takmazov2016-08-08 11:02:26 +0300
commit930b3f29f788d7866d66fcb9e946f5947782d968 (patch)
tree5a710a4598deaf74c432cdcc775b45572fa933e7 /juick-ws/src/main/java/com/juick/ws
parent64824ed6dddf776ce3ed36fe96ffc300d4127e29 (diff)
juick-ws: components as async beans
Diffstat (limited to 'juick-ws/src/main/java/com/juick/ws')
-rw-r--r--juick-ws/src/main/java/com/juick/ws/XMPPConnection.java5
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/CrosspostComponent.java4
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/JuickComponent.java8
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/PushComponent.java4
-rw-r--r--juick-ws/src/main/java/com/juick/ws/components/XMPPComponent.java4
-rw-r--r--juick-ws/src/main/java/com/juick/ws/configuration/WebsocketConfiguration.java36
6 files changed, 53 insertions, 8 deletions
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() {