Skip to content

Commit

Permalink
Clear all connections in SessionManager during HomekitRoot.stop() (#55)
Browse files Browse the repository at this point in the history
Remove all subscriptions during homekitRoot.stop()

This is a potential fix for #54
  • Loading branch information
Tim Harper authored and andylintner committed Feb 3, 2019
1 parent 1e9d187 commit 97ae5ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/beowulfe/hap/HomekitRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void start() {
public void stop() {
advertiser.stop();
webHandler.stop();
subscriptions.removeAll();
started = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.beowulfe.hap.impl.http.HttpResponse;
import com.beowulfe.hap.impl.json.EventController;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -77,10 +78,13 @@ public synchronized void removeConnection(HomekitClientConnection connection) {
subscriptions.get(characteristic);
characteristicSubscriptions.remove(connection);
if (characteristicSubscriptions.isEmpty()) {
LOGGER.debug("Unsubscribing from characteristic as all subscriptions are closed");
characteristic.unsubscribe();
subscriptions.remove(characteristic);
}
}
}
LOGGER.debug("Removed connection {}", connection.hashCode());
}

private <T> Set<T> newSet() {
Expand All @@ -98,4 +102,16 @@ public void publish(int accessoryId, int iid, EventableCharacteristic changed) {
LOGGER.error("Failed to create new event message", e);
}
}

/** Remove all existing subscriptions */
public void removeAll() {
LOGGER.debug("Removing {} reverse connections from subscription manager", reverse.size());
Iterator<HomekitClientConnection> i = reverse.keySet().iterator();
while (i.hasNext()) {
HomekitClientConnection connection = i.next();
LOGGER.debug("Removing connection {}", connection.hashCode());
removeConnection(connection);
}
LOGGER.debug("Subscription sizes are {} and {}", reverse.size(), subscriptions.size());
}
}

0 comments on commit 97ae5ad

Please sign in to comment.