From 7c2f9e3603370a421df9f0049d20fa59dc9b49c9 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 13 Apr 2020 12:14:32 +0200 Subject: [PATCH] pep: cleanup pep users API Use EntityBareJid just as its done within PepManager. There is no need for AsyncButOrdered in the PEP user managers, as PepManager already takes care of that. Also the message carrying the PEP event should always be the last parameter of the callbacks, as it is the least important piece of information. --- .../smackx/geoloc/GeoLocationListener.java | 4 +-- .../smackx/geoloc/GeoLocationManager.java | 24 ++++++-------- .../smackx/mood/MoodListener.java | 7 +++-- .../jivesoftware/smackx/mood/MoodManager.java | 31 +++++++------------ .../smackx/pubsub/ItemsExtension.java | 1 + .../smackx/usertune/UserTuneListener.java | 7 +++-- .../smackx/usertune/UserTuneManager.java | 22 +++++-------- .../GeolocationIntegrationTest.java | 4 +-- .../smackx/mood/MoodIntegrationTest.java | 2 +- .../usertune/UserTuneIntegrationTest.java | 4 +-- 10 files changed, 44 insertions(+), 62 deletions(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationListener.java index 8b1259ec7..25b6bb4d6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationListener.java @@ -19,8 +19,8 @@ package org.jivesoftware.smackx.geoloc; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.geoloc.packet.GeoLocation; -import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.EntityBareJid; public interface GeoLocationListener { - void onGeoLocationUpdated(BareJid jid, GeoLocation geoLocation, Message message); + void onGeoLocationUpdated(EntityBareJid jid, GeoLocation geoLocation, Message message); } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationManager.java index 3dbee6589..642e7f147 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/geoloc/GeoLocationManager.java @@ -1,6 +1,6 @@ /** * - * Copyright 2015-2017 Ishan Khanna, Fernando Ramirez 2019 Florian Schmaus + * Copyright 2015-2017 Ishan Khanna, Fernando Ramirez 2019-2020 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArraySet; -import org.jivesoftware.smack.AsyncButOrdered; import org.jivesoftware.smack.ConnectionCreationListener; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException.NoResponseException; @@ -43,7 +42,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem; import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException; import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProviderManager; -import org.jxmpp.jid.BareJid; import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.Jid; @@ -73,7 +71,6 @@ public final class GeoLocationManager extends Manager { private static boolean ENABLE_USER_LOCATION_NOTIFICATIONS_BY_DEFAULT = true; private final Set geoLocationListeners = new CopyOnWriteArraySet<>(); - private final AsyncButOrdered asyncButOrdered = new AsyncButOrdered(); private final ServiceDiscoveryManager serviceDiscoveryManager; private final PepManager pepManager; @@ -116,17 +113,14 @@ public final class GeoLocationManager extends Manager { return; } - final BareJid contact = from.asBareJid(); - asyncButOrdered.performAsyncButOrdered(contact, () -> { - ItemsExtension itemsExtension = (ItemsExtension) event.getEvent(); - List items = itemsExtension.getExtensions(); - @SuppressWarnings("unchecked") - PayloadItem payload = (PayloadItem) items.get(0); - GeoLocation geoLocation = payload.getPayload(); - for (GeoLocationListener listener : geoLocationListeners) { - listener.onGeoLocationUpdated(contact, geoLocation, message); - } - }); + ItemsExtension itemsExtension = (ItemsExtension) event.getEvent(); + List items = itemsExtension.getExtensions(); + @SuppressWarnings("unchecked") + PayloadItem payload = (PayloadItem) items.get(0); + GeoLocation geoLocation = payload.getPayload(); + for (GeoLocationListener listener : geoLocationListeners) { + listener.onGeoLocationUpdated(from, geoLocation, message); + } } }); serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodListener.java index cc644bd07..243e67032 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodListener.java @@ -1,6 +1,6 @@ /** * - * Copyright 2018 Paul Schaub. + * Copyright 2018 Paul Schaub, 2020 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,10 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.mood.element.MoodElement; -import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.EntityBareJid; public interface MoodListener { - void onMoodUpdated(BareJid jid, Message message, MoodElement moodElement); + void onMoodUpdated(EntityBareJid from, MoodElement moodElement, Message message); + } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodManager.java index 27f270ae8..54f50b4ee 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/mood/MoodManager.java @@ -1,6 +1,6 @@ /** * - * Copyright 2018 Paul Schaub. + * Copyright 2018 Paul Schaub, 2020 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ */ package org.jivesoftware.smackx.mood; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; +import java.util.concurrent.CopyOnWriteArraySet; -import org.jivesoftware.smack.AsyncButOrdered; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; @@ -42,7 +41,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem; import org.jivesoftware.smackx.pubsub.PubSubException; import org.jivesoftware.smackx.pubsub.PubSubManager; -import org.jxmpp.jid.BareJid; import org.jxmpp.jid.EntityBareJid; /** @@ -72,8 +70,7 @@ public final class MoodManager extends Manager { private static final Map INSTANCES = new WeakHashMap<>(); - private final Set moodListeners = new HashSet<>(); - private final AsyncButOrdered asyncButOrdered = new AsyncButOrdered<>(); + private final Set moodListeners = new CopyOnWriteArraySet<>(); private PubSubManager pubSubManager; private MoodManager(XMPPConnection connection) { @@ -86,19 +83,13 @@ public final class MoodManager extends Manager { return; } - final BareJid contact = from.asBareJid(); - asyncButOrdered.performAsyncButOrdered(contact, new Runnable() { - @Override - public void run() { - ItemsExtension items = (ItemsExtension) event.getExtensions().get(0); - PayloadItem payload = (PayloadItem) items.getItems().get(0); - MoodElement mood = (MoodElement) payload.getPayload(); + ItemsExtension items = (ItemsExtension) event.getExtensions().get(0); + PayloadItem payload = (PayloadItem) items.getItems().get(0); + MoodElement mood = (MoodElement) payload.getPayload(); - for (MoodListener listener : moodListeners) { - listener.onMoodUpdated(contact, message, mood); - } - } - }); + for (MoodListener listener : moodListeners) { + listener.onMoodUpdated(from, mood, message); + } } }); } @@ -170,11 +161,11 @@ public final class MoodManager extends Manager { message.addExtension(element); } - public synchronized void addMoodListener(MoodListener listener) { + public void addMoodListener(MoodListener listener) { moodListeners.add(listener); } - public synchronized void removeMoodListener(MoodListener listener) { + public void removeMoodListener(MoodListener listener) { moodListeners.remove(listener); } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java index 12d7a4aa6..000138897 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/pubsub/ItemsExtension.java @@ -135,6 +135,7 @@ public class ItemsExtension extends NodeExtension implements EmbeddedPacketExten * * @return List of {@link Item}, {@link RetractItem}, or null */ + // TODO: Shouldn't this return List? Why is RetractItem not a subtype of item? public List getItems() { return items; } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneListener.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneListener.java index e020e4ec2..3e053776b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneListener.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneListener.java @@ -1,6 +1,6 @@ /** * - * Copyright 2019 Aditya Borikar. + * Copyright 2019 Aditya Borikar, 2020 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,10 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.usertune.element.UserTuneElement; -import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.EntityBareJid; public interface UserTuneListener { - void onUserTuneUpdated(BareJid jid, Message message, UserTuneElement userTuneElement); + void onUserTuneUpdated(EntityBareJid jid, UserTuneElement userTuneElement, Message message); + } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneManager.java index 415c53dcc..9b1a131af 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/usertune/UserTuneManager.java @@ -22,7 +22,6 @@ import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArraySet; -import org.jivesoftware.smack.AsyncButOrdered; import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException.NoResponseException; import org.jivesoftware.smack.SmackException.NotConnectedException; @@ -41,7 +40,6 @@ import org.jivesoftware.smackx.pubsub.PayloadItem; import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException; import org.jivesoftware.smackx.usertune.element.UserTuneElement; -import org.jxmpp.jid.BareJid; import org.jxmpp.jid.EntityBareJid; /** @@ -70,7 +68,6 @@ public final class UserTuneManager extends Manager { private static boolean ENABLE_USER_TUNE_NOTIFICATIONS_BY_DEFAULT = true; private final Set userTuneListeners = new CopyOnWriteArraySet<>(); - private final AsyncButOrdered asyncButOrdered = new AsyncButOrdered<>(); private final ServiceDiscoveryManager serviceDiscoveryManager; private final PepManager pepManager; @@ -93,18 +90,15 @@ public final class UserTuneManager extends Manager { return; } - final BareJid contact = from.asBareJid(); - asyncButOrdered.performAsyncButOrdered(contact, () -> { - ItemsExtension itemsExtension = (ItemsExtension) event.getEvent(); - List items = itemsExtension.getExtensions(); - @SuppressWarnings("unchecked") - PayloadItem payload = (PayloadItem) items.get(0); - UserTuneElement tune = payload.getPayload(); + ItemsExtension itemsExtension = (ItemsExtension) event.getEvent(); + List items = itemsExtension.getExtensions(); + @SuppressWarnings("unchecked") + PayloadItem payload = (PayloadItem) items.get(0); + UserTuneElement tune = payload.getPayload(); - for (UserTuneListener listener : userTuneListeners) { - listener.onUserTuneUpdated(contact, message, tune); - } - }); + for (UserTuneListener listener : userTuneListeners) { + listener.onUserTuneUpdated(from, tune, message); + } } }); serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection); diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java index 3909cee88..f6db34dae 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/geolocation/GeolocationIntegrationTest.java @@ -35,7 +35,7 @@ import org.igniterealtime.smack.inttest.annotations.AfterClass; import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest; import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil; import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint; -import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.EntityBareJid; import org.jxmpp.util.XmppDateTime; public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest { @@ -82,7 +82,7 @@ public class GeolocationIntegrationTest extends AbstractSmackIntegrationTest { final GeoLocationListener geoLocationListener = new GeoLocationListener() { @Override - public void onGeoLocationUpdated(BareJid jid, GeoLocation geoLocation, Message message) { + public void onGeoLocationUpdated(EntityBareJid jid, GeoLocation geoLocation, Message message) { if (geoLocation.equals(geoLocation1)) { geoLocationReceived.signal(); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java index 3338bc4f2..faccc9a83 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/mood/MoodIntegrationTest.java @@ -43,7 +43,7 @@ public class MoodIntegrationTest extends AbstractSmackIntegrationTest { final SimpleResultSyncPoint moodReceived = new SimpleResultSyncPoint(); - final MoodListener moodListener = (jid, message, moodElement) -> { + final MoodListener moodListener = (jid, moodElement, message) -> { if (moodElement.getMood() == Mood.satisfied) { moodReceived.signal(); } diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java index cae6c1d8d..45ddec6f0 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/usertune/UserTuneIntegrationTest.java @@ -31,7 +31,7 @@ import org.igniterealtime.smack.inttest.annotations.AfterClass; import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest; import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil; import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint; -import org.jxmpp.jid.BareJid; +import org.jxmpp.jid.EntityBareJid; public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest { @@ -63,7 +63,7 @@ public class UserTuneIntegrationTest extends AbstractSmackIntegrationTest { final UserTuneListener userTuneListener = new UserTuneListener() { @Override - public void onUserTuneUpdated(BareJid jid, Message message, UserTuneElement userTuneElement) { + public void onUserTuneUpdated(EntityBareJid jid, UserTuneElement userTuneElement, Message message) { if (userTuneElement.equals(userTuneElement1)) { userTuneReceived.signal(); }