aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp/src/main/java/com/juick/components/XMPPServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-xmpp/src/main/java/com/juick/components/XMPPServer.java')
-rw-r--r--juick-xmpp/src/main/java/com/juick/components/XMPPServer.java32
1 files changed, 22 insertions, 10 deletions
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<ConnectionIn> inConnections = Collections.synchronizedList(new ArrayList<>());
private final List<ConnectionOut> outConnections = Collections.synchronizedList(new ArrayList<>());
private final List<CacheEntry> outCache = Collections.synchronizedList(new ArrayList<>());
+ private final List<StanzaListener> stanzaListeners = Collections.synchronizedList(new ArrayList<>());
final public HashMap<String, StanzaChild> 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<StanzaListener> 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;
+ }
}