From 4679da47ffedf2a0f29c324880fa537fe9447f39 Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Fri, 18 Nov 2016 03:47:00 +0700 Subject: correct closing babble components implemented --- .../src/main/java/com/juick/components/XMPPBot.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'juick-xmpp-bot/src/main/java/com/juick') diff --git a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java index c95c94e3..bced456b 100644 --- a/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java +++ b/juick-xmpp-bot/src/main/java/com/juick/components/XMPPBot.java @@ -21,6 +21,7 @@ import rocks.xmpp.extensions.version.SoftwareVersionManager; import rocks.xmpp.extensions.version.model.SoftwareVersion; import javax.inject.Inject; +import java.io.Closeable; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.net.URL; @@ -28,13 +29,15 @@ import java.net.URL; /** * Created by vt on 12/11/2016. */ -public class XMPPBot { +public class XMPPBot implements AutoCloseable{ private static final Logger logger = LoggerFactory.getLogger(XMPPBot.class); @Inject JdbcTemplate jdbc; + private ExternalComponent component; + public XMPPBot(Environment env) { - ExternalComponent component = ExternalComponent.create(env.getProperty("component_name", "juick.com"), + component = ExternalComponent.create(env.getProperty("component_name", "juick.com"), env.getProperty("component_password", "secret"), env.getProperty("component_host", "localhost"), NumberUtils.toInt(env.getProperty("component_port", "5347"), 5347)); Jid juickJid = Jid.of(env.getProperty("xmppbot_jid", "juick@juick.com/Juick")); @@ -88,4 +91,12 @@ public class XMPPBot { logger.error("bot initialization error", e); } } + + @Override + public void close() throws Exception { + if (component != null) + component.close(); + + logger.info("ExternalComponent on xmpp-bot destroyed"); + } } -- cgit v1.2.3