From d2af7ac0bbdde07e0f0f8b68c56f370ed3c06fe6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 3 Apr 2018 12:47:29 +0300 Subject: boot: reuse single xmpp connection when possible --- .../java/com/juick/www/configuration/EmbeddedXMPPConfig.java | 11 +++++++++++ .../java/com/juick/www/configuration/XMPPConfiguration.java | 2 ++ 2 files changed, 13 insertions(+) (limited to 'juick-www/src/main/java/com/juick/www/configuration') diff --git a/juick-www/src/main/java/com/juick/www/configuration/EmbeddedXMPPConfig.java b/juick-www/src/main/java/com/juick/www/configuration/EmbeddedXMPPConfig.java index 35377dcd..a54b76a1 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/EmbeddedXMPPConfig.java +++ b/juick-www/src/main/java/com/juick/www/configuration/EmbeddedXMPPConfig.java @@ -1,11 +1,22 @@ package com.juick.www.configuration; +import com.juick.server.XMPPConnection; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import rocks.xmpp.extensions.component.accept.ExternalComponent; + +import javax.inject.Inject; @Configuration @ConditionalOnClass(name = "com.juick.server.xmpp.router.XMPPRouter") @ComponentScan(basePackages = "com.juick.server") public class EmbeddedXMPPConfig { + @Inject + private XMPPConnection xmppConnection; + @Bean + public ExternalComponent xmpp() { + return xmppConnection.getRouter(); + } } diff --git a/juick-www/src/main/java/com/juick/www/configuration/XMPPConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/XMPPConfiguration.java index 0fc86e2a..c8efc9e9 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/XMPPConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/XMPPConfiguration.java @@ -4,6 +4,7 @@ import com.juick.Message; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import rocks.xmpp.core.XmppException; @@ -26,6 +27,7 @@ public class XMPPConfiguration { @Value("${xmpp_disabled:false}") private boolean isXmppDisabled; @Bean + @ConditionalOnMissingBean(type = "rocks.xmpp.extensions.component.accept.ExternalComponent") public ExternalComponent xmpp() { XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() .extensions(Extension.of(Message.class)) -- cgit v1.2.3