Issue #2822 fixed check for topic subscription before leader transfer
now only checks if the bare ID (no resource) is subscribed to topic added method to check for same ID using multiple handles Former-commit-id:833d693098
[formerlyc4a38d1f68
] [formerly6c47c78038
] [formerlyaed25eeb61
[formerly6c47c78038
[formerly 09d7a1113a6254d8f01cf42d863e9365aac23cc7]]] Former-commit-id:aed25eeb61
Former-commit-id: 7ac0692b2d053f58ada13699f7e27bac3e23b62c [formerly474255ed29
] Former-commit-id:56e0dad5ff
This commit is contained in:
parent
69e45bdfbd
commit
79c5884e45
2 changed files with 57 additions and 22 deletions
|
@ -23,9 +23,7 @@ import java.net.URI;
|
|||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
@ -99,6 +97,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
|
|||
* ensure that subscription is setup before joining room
|
||||
* Mar 31, 2014 2899 mpduff Improve error messages.
|
||||
* Apr 15, 2014 2822 bclement added check for other participants being subscribed to topic
|
||||
* Apr 21, 2014 2822 bclement removed use of resources in topicSubscribers, added skipCache
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -120,7 +119,7 @@ public class SharedDisplaySession extends VenueSession implements
|
|||
|
||||
private LeafNode topic;
|
||||
|
||||
private final Map<UserId, Boolean> topicSubscribers = new ConcurrentHashMap<UserId, Boolean>();
|
||||
private final Set<String> topicSubscribers = new HashSet<String>();
|
||||
|
||||
private XMPPConnection conn;
|
||||
|
||||
|
@ -631,30 +630,35 @@ public class SharedDisplaySession extends VenueSession implements
|
|||
}
|
||||
|
||||
/**
|
||||
* may return false positives if skipCache is set to false, won't return a
|
||||
* false negative
|
||||
*
|
||||
* @param user
|
||||
* @return true if user has a subscription to the session topic
|
||||
* @param skipCache
|
||||
* if true, a list of current subscribers is always retrieved
|
||||
* from the server
|
||||
* @return return false if user doesn't have a subscription to the session
|
||||
* topic
|
||||
* @throws XMPPException
|
||||
*/
|
||||
private boolean isSubscribedToTopic(UserId user)
|
||||
private boolean isSubscribedToTopic(UserId user, boolean skipCache)
|
||||
throws XMPPException {
|
||||
Boolean rval = topicSubscribers.get(user);
|
||||
if (rval == null) {
|
||||
synchronized (topicSubscribers) {
|
||||
boolean rval;
|
||||
synchronized (topicSubscribers) {
|
||||
rval = topicSubscribers.contains(user.getNormalizedId());
|
||||
if (skipCache || !rval) {
|
||||
topicSubscribers.clear();
|
||||
List<Subscription> subs = PubSubOperations.getAllSubscriptions(
|
||||
conn, topic);
|
||||
for (Subscription sub : subs) {
|
||||
topicSubscribers.put(IDConverter.convertFrom(sub.getJid()),
|
||||
true);
|
||||
/*
|
||||
* we can't use the resource from the subscription here
|
||||
* because the room user won't always have a resource
|
||||
*/
|
||||
UserId subber = IDConverter.convertFrom(sub.getJid());
|
||||
topicSubscribers.add(subber.getNormalizedId());
|
||||
}
|
||||
}
|
||||
rval = topicSubscribers.get(user);
|
||||
if (rval == null) {
|
||||
/*
|
||||
* userid object hash includes resource, cache as a client that
|
||||
* doesn't use topic
|
||||
*/
|
||||
topicSubscribers.put(user, false);
|
||||
rval = false;
|
||||
rval = topicSubscribers.contains(user.getNormalizedId());
|
||||
}
|
||||
}
|
||||
return rval;
|
||||
|
@ -673,6 +677,16 @@ public class SharedDisplaySession extends VenueSession implements
|
|||
throw new CollaborationException(
|
||||
"Unable to grant ownership because new leader's actual userid is not known");
|
||||
}
|
||||
/*
|
||||
* leadership transfer must be sync'd between room ownership and topic
|
||||
* ownership. If a user is in the room under multiple handles, we can't
|
||||
* know for sure that this handle is associated with the same client
|
||||
* that understands leadership and is subscribed to the pubsub topic
|
||||
*/
|
||||
if (hasMultipleHandles(actualId)) {
|
||||
throw new CollaborationException(
|
||||
"Unable to grant ownership because new leader is in the room under multiple handles");
|
||||
}
|
||||
|
||||
final String newLeaderId = actualId.getNormalizedId();
|
||||
|
||||
|
@ -683,9 +697,10 @@ public class SharedDisplaySession extends VenueSession implements
|
|||
try {
|
||||
/*
|
||||
* make sure that the new leader is not just in the room, but also
|
||||
* subscribed to the pubsub topic
|
||||
* subscribed to the pubsub topic. Skip cache to handle participants
|
||||
* who may have switched clients since that last time we cached
|
||||
*/
|
||||
if (!isSubscribedToTopic(actualId)) {
|
||||
if (!isSubscribedToTopic(actualId, true)) {
|
||||
throw new CollaborationException(
|
||||
"Unable to grant ownership because new leader is not subscribed to session topic");
|
||||
}
|
||||
|
@ -774,7 +789,7 @@ public class SharedDisplaySession extends VenueSession implements
|
|||
boolean rval = false;
|
||||
if (actualId != null) {
|
||||
try {
|
||||
rval = isSubscribedToTopic(actualId);
|
||||
rval = isSubscribedToTopic(actualId, false);
|
||||
} catch (XMPPException e) {
|
||||
log.error("Error checking if user is a shared display client",
|
||||
e);
|
||||
|
|
|
@ -108,6 +108,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
|
|||
* handle is now set in constructor
|
||||
* Apr 11, 2014 2903 bclement made constructor public b/c connection code moved packages
|
||||
* Apr 16, 2014 3020 bclement added check for invited rooms in roomExistsOnServer()
|
||||
* Apr 21, 2014 2822 bclement added hasMultipleHandles()
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
|
@ -939,6 +940,25 @@ public class VenueSession extends BaseSession implements IVenueSession {
|
|||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* the return value is only accurate if the actual userIDs of all
|
||||
* participants can be seen by this client
|
||||
*
|
||||
* @param user
|
||||
* @return true if the user is in the room under multiple handles
|
||||
*/
|
||||
protected boolean hasMultipleHandles(UserId user) {
|
||||
int count = 0;
|
||||
IVenue v = getVenue();
|
||||
for (VenueParticipant p : v.getParticipants()) {
|
||||
UserId other = v.getParticipantUserid(p);
|
||||
if (other != null && user.isSameUser(other)) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count > 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue