From eea7abf829ed9b011d34d6ac8131fe3057b1b6f6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 7 Dec 2016 14:28:31 +0300 Subject: juick-xmpp: JuickBot is now Bean --- .../main/java/com/juick/components/XMPPServer.java | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'juick-xmpp/src/main/java/com/juick/components/XMPPServer.java') diff --git a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java index caa4c200..e057a9ea 100644 --- a/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java +++ b/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java @@ -33,7 +33,6 @@ public class XMPPServer implements AutoCloseable { public ExecutorService service; private ConnectionRouter router; - public JuickBot bot; public String HOSTNAME, componentName; public String keystore; @@ -44,6 +43,7 @@ public class XMPPServer implements AutoCloseable { private final List inConnections = Collections.synchronizedList(new ArrayList<>()); private final List outConnections = Collections.synchronizedList(new ArrayList<>()); private final List outCache = Collections.synchronizedList(new ArrayList<>()); + private final List stanzaListeners = Collections.synchronizedList(new ArrayList<>()); final public HashMap childParsers = new HashMap<>(); @@ -58,6 +58,7 @@ public class XMPPServer implements AutoCloseable { @Inject public SubscriptionService subscriptionService; + private JID jid; public XMPPServer(Environment env, ExecutorService service) { this.service = service; @@ -68,12 +69,11 @@ public class XMPPServer implements AutoCloseable { componentName = env.getProperty("componentname"); int componentPort = NumberUtils.toInt(env.getProperty("component_port"), 5347); int s2sPort = NumberUtils.toInt(env.getProperty("s2s_port"), 5269); - JID Jid = new JID(env.getProperty("xmppbot_jid")); keystore = env.getProperty("keystore"); keystorePassword = env.getProperty("keystore_password"); brokenSSLhosts = Arrays.asList(env.getProperty("broken_ssl_hosts", "").split(",")); bannedHosts = Arrays.asList(env.getProperty("banned_hosts", "").split(",")); - bot = new JuickBot(this, Jid); + jid = new JID(env.getProperty("xmppbot_jid")); boolean disabled = BooleanUtils.toBoolean(env.getProperty("xmpp_disabled", "false")); childParsers.put(JuickMessage.XMLNS, new JuickMessage()); @@ -88,7 +88,7 @@ public class XMPPServer implements AutoCloseable { while (true) { try { Socket socket = listener.accept(); - ConnectionIn client = new ConnectionIn(this, bot, socket); + ConnectionIn client = new ConnectionIn(this, socket); addConnectionIn(client); service.submit(client); } catch (Exception e) { @@ -206,12 +206,7 @@ public class XMPPServer implements AutoCloseable { } } if (connOut != null) { - try { - connOut.sendStanza(xml); - } catch (IOException e) { - logger.warn("stream to {} {} error: {}", - connOut.to, connOut.streamID, e); - } + connOut.sendStanza(xml); return; } @@ -266,4 +261,21 @@ public class XMPPServer implements AutoCloseable { } } + public List getStanzaListeners() { + return stanzaListeners; + } + + public void addStanzaListener(StanzaListener listener) { + synchronized (stanzaListeners) { + stanzaListeners.add(listener); + } + } + + public void onStanzaReceived(String type, Stanza xmlValue) { + stanzaListeners.forEach(l -> l.stanzaReceived(type, xmlValue)); + } + + public JID getJid() { + return jid; + } } -- cgit v1.2.3