mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Synchronize SDM methods that change the state
Other Managers, e.g. EntityCapsManager, may be notified if e.g. a feature is added or removed. While they are notified, the state of SDM must be consistent, therefore synchronize SDM methods that modify the state.
This commit is contained in:
parent
130a8216d1
commit
49c2c35609
1 changed files with 35 additions and 33 deletions
|
@ -29,6 +29,7 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smack.packet.Stanza;
|
import org.jivesoftware.smack.packet.Stanza;
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.XMPPError;
|
import org.jivesoftware.smack.packet.XMPPError;
|
||||||
|
import org.jivesoftware.smack.util.Objects;
|
||||||
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
import org.jivesoftware.smackx.caps.EntityCapsManager;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
|
||||||
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
import org.jivesoftware.smackx.disco.packet.DiscoverItems;
|
||||||
|
@ -200,9 +201,10 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param identity
|
* @param identity
|
||||||
*/
|
*/
|
||||||
public void setIdentity(Identity identity) {
|
public synchronized void setIdentity(Identity identity) {
|
||||||
if (identity == null) throw new IllegalArgumentException("Identity can not be null");
|
this.identity = Objects.requireNonNull(identity, "Identity can not be null");
|
||||||
this.identity = identity;
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,8 +234,10 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param identity
|
* @param identity
|
||||||
*/
|
*/
|
||||||
public void addIdentity(DiscoverInfo.Identity identity) {
|
public synchronized void addIdentity(DiscoverInfo.Identity identity) {
|
||||||
identities.add(identity);
|
identities.add(identity);
|
||||||
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,9 +248,11 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
* @param identity
|
* @param identity
|
||||||
* @return true, if successful. Otherwise the default identity was given.
|
* @return true, if successful. Otherwise the default identity was given.
|
||||||
*/
|
*/
|
||||||
public boolean removeIdentity(DiscoverInfo.Identity identity) {
|
public synchronized boolean removeIdentity(DiscoverInfo.Identity identity) {
|
||||||
if (identity.equals(this.identity)) return false;
|
if (identity.equals(this.identity)) return false;
|
||||||
identities.remove(identity);
|
identities.remove(identity);
|
||||||
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -286,17 +292,15 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param response the discover info response packet
|
* @param response the discover info response packet
|
||||||
*/
|
*/
|
||||||
public void addDiscoverInfoTo(DiscoverInfo response) {
|
public synchronized void addDiscoverInfoTo(DiscoverInfo response) {
|
||||||
// First add the identities of the connection
|
// First add the identities of the connection
|
||||||
response.addIdentities(getIdentities());
|
response.addIdentities(getIdentities());
|
||||||
|
|
||||||
// Add the registered features to the response
|
// Add the registered features to the response
|
||||||
synchronized (features) {
|
for (String feature : getFeatures()) {
|
||||||
for (String feature : getFeatures()) {
|
response.addFeature(feature);
|
||||||
response.addFeature(feature);
|
|
||||||
}
|
|
||||||
response.addExtension(extendedInfo);
|
|
||||||
}
|
}
|
||||||
|
response.addExtension(extendedInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,10 +360,8 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @return a List of the supported features by this XMPP entity.
|
* @return a List of the supported features by this XMPP entity.
|
||||||
*/
|
*/
|
||||||
public List<String> getFeatures() {
|
public synchronized List<String> getFeatures() {
|
||||||
synchronized (features) {
|
return new ArrayList<String>(features);
|
||||||
return new ArrayList<String>(features);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -373,13 +375,11 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param feature the feature to register as supported.
|
* @param feature the feature to register as supported.
|
||||||
*/
|
*/
|
||||||
public void addFeature(String feature) {
|
public synchronized void addFeature(String feature) {
|
||||||
synchronized (features) {
|
features.add(feature);
|
||||||
if (!features.contains(feature)) {
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
features.add(feature);
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -390,11 +390,11 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
*
|
*
|
||||||
* @param feature the feature to remove from the supported features.
|
* @param feature the feature to remove from the supported features.
|
||||||
*/
|
*/
|
||||||
public void removeFeature(String feature) {
|
public synchronized void removeFeature(String feature) {
|
||||||
synchronized (features) {
|
features.remove(feature);
|
||||||
features.remove(feature);
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
renewEntityCapsVersion();
|
// method is synchronized
|
||||||
}
|
renewEntityCapsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -403,10 +403,8 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
* @param feature the feature to look for.
|
* @param feature the feature to look for.
|
||||||
* @return a boolean indicating if the specified featured is registered or not.
|
* @return a boolean indicating if the specified featured is registered or not.
|
||||||
*/
|
*/
|
||||||
public boolean includesFeature(String feature) {
|
public synchronized boolean includesFeature(String feature) {
|
||||||
synchronized (features) {
|
return features.contains(feature);
|
||||||
return features.contains(feature);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,8 +422,10 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
* the data form that contains the extend service discovery
|
* the data form that contains the extend service discovery
|
||||||
* information.
|
* information.
|
||||||
*/
|
*/
|
||||||
public void setExtendedInfo(DataForm info) {
|
public synchronized void setExtendedInfo(DataForm info) {
|
||||||
extendedInfo = info;
|
extendedInfo = info;
|
||||||
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,8 +461,10 @@ public class ServiceDiscoveryManager extends Manager {
|
||||||
* Since no stanza(/packet) is actually sent to the server it is safe to perform this
|
* Since no stanza(/packet) is actually sent to the server it is safe to perform this
|
||||||
* operation before logging to the server.
|
* operation before logging to the server.
|
||||||
*/
|
*/
|
||||||
public void removeExtendedInfo() {
|
public synchronized void removeExtendedInfo() {
|
||||||
extendedInfo = null;
|
extendedInfo = null;
|
||||||
|
// Notify others of a state change of SDM. In order to keep the state consistent, this
|
||||||
|
// method is synchronized
|
||||||
renewEntityCapsVersion();
|
renewEntityCapsVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue