migrate copy ond write list to synchronized hashset for pending mucs

This commit is contained in:
Daniel Gultsch 2019-06-30 21:57:37 +02:00
parent 9f08a32ffb
commit 7ec8f7952f
2 changed files with 40 additions and 15 deletions

View file

@ -64,8 +64,8 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
protected final JSONObject keys; protected final JSONObject keys;
private final Roster roster = new Roster(this); private final Roster roster = new Roster(this);
private final Collection<Jid> blocklist = new CopyOnWriteArraySet<>(); private final Collection<Jid> blocklist = new CopyOnWriteArraySet<>();
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<>(); public final Set<Conversation> pendingConferenceJoins = new HashSet<>();
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<>(); public final Set<Conversation> pendingConferenceLeaves = new HashSet<>();
public final Set<Conversation> inProgressConferenceJoins = new HashSet<>(); public final Set<Conversation> inProgressConferenceJoins = new HashSet<>();
public final Set<Conversation> inProgressConferencePings = new HashSet<>(); public final Set<Conversation> inProgressConferencePings = new HashSet<>();
protected Jid jid; protected Jid jid;

View file

@ -382,20 +382,33 @@ public class XmppConnectionService extends Service {
synchronized (account.inProgressConferenceJoins) { synchronized (account.inProgressConferenceJoins) {
inProgressJoin = account.inProgressConferenceJoins.contains(conversation); inProgressJoin = account.inProgressConferenceJoins.contains(conversation);
} }
final boolean pendingJoin;
synchronized (account.pendingConferenceJoins) {
pendingJoin = account.pendingConferenceJoins.contains(conversation);
}
if (conversation.getAccount() == account if (conversation.getAccount() == account
&& !account.pendingConferenceJoins.contains(conversation) && !pendingJoin
&& !inProgressJoin) { && !inProgressJoin) {
sendUnsentMessages(conversation); sendUnsentMessages(conversation);
} }
} }
for (Conversation conversation : account.pendingConferenceLeaves) { final List<Conversation> pendingLeaves;
synchronized (account.pendingConferenceLeaves) {
pendingLeaves = new ArrayList<>(account.pendingConferenceLeaves);
account.pendingConferenceLeaves.clear();
}
for (Conversation conversation : pendingLeaves) {
leaveMuc(conversation); leaveMuc(conversation);
} }
account.pendingConferenceLeaves.clear(); final List<Conversation> pendingJoins;
for (Conversation conversation : account.pendingConferenceJoins) { synchronized (account.pendingConferenceJoins) {
pendingJoins = new ArrayList<>(account.pendingConferenceJoins);
account.pendingConferenceJoins.clear();
}
for (Conversation conversation : pendingJoins) {
joinMuc(conversation); joinMuc(conversation);
} }
account.pendingConferenceJoins.clear();
scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode()); scheduleWakeUpCall(Config.PING_MAX_INTERVAL, account.getUuid().hashCode());
} else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) { } else if (account.getStatus() == Account.State.OFFLINE || account.getStatus() == Account.State.DISABLED) {
resetSendingToWaiting(account); resetSendingToWaiting(account);
@ -2518,9 +2531,13 @@ public class XmppConnectionService extends Service {
} }
private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) { private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
Account account = conversation.getAccount(); final Account account = conversation.getAccount();
synchronized (account.pendingConferenceJoins) {
account.pendingConferenceJoins.remove(conversation); account.pendingConferenceJoins.remove(conversation);
}
synchronized (account.pendingConferenceLeaves) {
account.pendingConferenceLeaves.remove(conversation); account.pendingConferenceLeaves.remove(conversation);
}
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
synchronized (account.inProgressConferenceJoins) { synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.add(conversation); account.inProgressConferenceJoins.add(conversation);
@ -2619,7 +2636,9 @@ public class XmppConnectionService extends Service {
}); });
updateConversationUi(); updateConversationUi();
} else { } else {
synchronized (account.pendingConferenceJoins) {
account.pendingConferenceJoins.add(conversation); account.pendingConferenceJoins.add(conversation);
}
conversation.resetMucOptions(); conversation.resetMucOptions();
conversation.setHasMessagesLeftOnServer(false); conversation.setHasMessagesLeftOnServer(false);
updateConversationUi(); updateConversationUi();
@ -2834,9 +2853,13 @@ public class XmppConnectionService extends Service {
} }
private void leaveMuc(Conversation conversation, boolean now) { private void leaveMuc(Conversation conversation, boolean now) {
Account account = conversation.getAccount(); final Account account = conversation.getAccount();
synchronized (account.pendingConferenceJoins) {
account.pendingConferenceJoins.remove(conversation); account.pendingConferenceJoins.remove(conversation);
}
synchronized (account.pendingConferenceLeaves) {
account.pendingConferenceLeaves.remove(conversation); account.pendingConferenceLeaves.remove(conversation);
}
if (account.getStatus() == Account.State.ONLINE || now) { if (account.getStatus() == Account.State.ONLINE || now) {
if (conversation.getMucOptions().push()) { if (conversation.getMucOptions().push()) {
disableDirectMucPush(conversation); disableDirectMucPush(conversation);
@ -2850,9 +2873,11 @@ public class XmppConnectionService extends Service {
} }
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": leaving muc " + conversation.getJid()); Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": leaving muc " + conversation.getJid());
} else { } else {
synchronized (account.pendingConferenceLeaves) {
account.pendingConferenceLeaves.add(conversation); account.pendingConferenceLeaves.add(conversation);
} }
} }
}
public String findConferenceServer(final Account account) { public String findConferenceServer(final Account account) {
String server; String server;