synchronized (messageHandlers) {
messageHandlers.remove(handler);
if (messageHandlers.size() == 0) {
- try {
- connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
- connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
- connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
- } catch (DBusException e) {
- e.printStackTrace();
- }
+ uninstallMessageHandlers();
}
}
}
@Override
public void close() throws IOException {
+ synchronized (this) {
+ this.notify();
+ }
+ synchronized (messageHandlers) {
+ messageHandlers.clear();
+ uninstallMessageHandlers();
+ }
}
private SendMessageResults handleMessage(
}
}
+ private void uninstallMessageHandlers() {
+ try {
+ connection.removeSigHandler(Signal.MessageReceivedV2.class, signal, this.dbusMsgHandler);
+ connection.removeSigHandler(Signal.ReceiptReceivedV2.class, signal, this.dbusRcptHandler);
+ connection.removeSigHandler(Signal.SyncMessageReceivedV2.class, signal, this.dbusSyncHandler);
+ } catch (DBusException e) {
+ e.printStackTrace();
+ }
+ }
+
private List<MessageEnvelope.Data.Attachment> getAttachments(final Map<String, Variant<?>> extras) {
if (!extras.containsKey("attachments")) {
return List.of();