moved the logic of sending push messages on the network outside the push manager lock
@@ -143,8 +143,13 @@ public class OPushManager implements OMetadataUpdateListener {
private void genericNotify(Map<String, Set<WeakReference<ONetworkProtocolBinary>>> context, String database,
OBinaryPushRequest<?> request) {
Orient.instance().submit(() -> {
+ Set<WeakReference<ONetworkProtocolBinary>> clients = null;
synchronized (OPushManager.this) {
- Set<WeakReference<ONetworkProtocolBinary>> clients = context.get(database);
+ Set<WeakReference<ONetworkProtocolBinary>> cl = context.get(database);
+ if (cl != null) {
+ clients = new HashSet<>(cl);
+ }
+ }
if (clients != null) {
Iterator<WeakReference<ONetworkProtocolBinary>> iter = clients.iterator();
while (iter.hasNext()) {
@@ -154,14 +159,18 @@ public class OPushManager implements OMetadataUpdateListener {
try {
OBinaryPushResponse response = protocolBinary.push(request);
} catch (IOException e) {
- iter.remove();
+ synchronized (OPushManager.this) {
+ context.get(database).remove(ref);
+ }
}
} else {
- iter.remove();
+ synchronized (OPushManager.this) {
+ context.get(database).remove(ref);
}
}
}
}
+
});
}
