55import com .beowulfe .hap .impl .http .HttpResponse ;
66import com .beowulfe .hap .impl .json .EventController ;
77import java .util .Collections ;
8+ import java .util .Iterator ;
89import java .util .Set ;
910import java .util .concurrent .ConcurrentHashMap ;
1011import java .util .concurrent .ConcurrentMap ;
@@ -77,10 +78,13 @@ public synchronized void removeConnection(HomekitClientConnection connection) {
7778 subscriptions .get (characteristic );
7879 characteristicSubscriptions .remove (connection );
7980 if (characteristicSubscriptions .isEmpty ()) {
81+ LOGGER .debug ("Unsubscribing from characteristic as all subscriptions are closed" );
8082 characteristic .unsubscribe ();
83+ subscriptions .remove (characteristic );
8184 }
8285 }
8386 }
87+ LOGGER .debug ("Removed connection {}" , connection .hashCode ());
8488 }
8589
8690 private <T > Set <T > newSet () {
@@ -98,4 +102,16 @@ public void publish(int accessoryId, int iid, EventableCharacteristic changed) {
98102 LOGGER .error ("Failed to create new event message" , e );
99103 }
100104 }
105+
106+ /** Remove all existing subscriptions */
107+ public void removeAll () {
108+ LOGGER .debug ("Removing {} reverse connections from subscription manager" , reverse .size ());
109+ Iterator <HomekitClientConnection > i = reverse .keySet ().iterator ();
110+ while (i .hasNext ()) {
111+ HomekitClientConnection connection = i .next ();
112+ LOGGER .debug ("Removing connection {}" , connection .hashCode ());
113+ removeConnection (connection );
114+ }
115+ LOGGER .debug ("Subscription sizes are {} and {}" , reverse .size (), subscriptions .size ());
116+ }
101117}
0 commit comments