Skip to content

Commit a781e85

Browse files
committed
address review comments
1 parent 0e4db0b commit a781e85

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/main/java/io/github/hapjava/server/impl/HomekitRoot.java

+8
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,19 @@ public class HomekitRoot {
8686
label, DEFAULT_ACCESSORY_CATEGORY, webHandler, authInfo, new JmdnsHomekitAdvertiser(jmdns));
8787
}
8888

89+
/**
90+
* Begin a batch update of accessories.
91+
*
92+
* <p>After calling this, you can call addAccessory() and removeAccessory() multiple times without
93+
* causing HAP-Java to re-publishing the metadata to HomeKit. You'll need to call
94+
* completeUpdateBatch in order to publish all accumulated changes.
95+
*/
8996
public synchronized void batchUpdate() {
9097
if (this.nestedBatches == 0) madeChanges = false;
9198
++this.nestedBatches;
9299
}
93100

101+
/** Publish accumulated accessory changes since batchUpdate() was called. */
94102
public synchronized void completeUpdateBatch() {
95103
if (--this.nestedBatches == 0 && madeChanges) registry.reset();
96104
}

src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public synchronized void addSubscription(
5858
reverse.put(connection, new HashSet<>());
5959
}
6060
reverse.get(connection).add(characteristic);
61-
LOGGER.debug(
61+
LOGGER.trace(
6262
"Added subscription to {}:{} ({}) for {}",
6363
aid,
6464
iid,
@@ -73,7 +73,7 @@ public synchronized void removeSubscription(
7373
if (subscribers != null) {
7474
subscribers.connections.remove(connection);
7575
if (subscribers.connections.isEmpty()) {
76-
LOGGER.debug("Unsubscribing from characteristic as all subscriptions are closed");
76+
LOGGER.trace("Unsubscribing from characteristic as all subscriptions are closed");
7777
characteristic.unsubscribe();
7878
subscriptions.remove(characteristic);
7979
}
@@ -85,7 +85,7 @@ public synchronized void removeSubscription(
8585
if (connectionNotifications.isEmpty()) pendingNotifications.remove(connection);
8686
}
8787

88-
LOGGER.debug(
88+
LOGGER.trace(
8989
"Removed subscription from {}:{} ({}) for {}",
9090
subscribers.aid,
9191
subscribers.iid,
@@ -112,7 +112,7 @@ private void removeConnection(
112112
removeSubscription(characteristic, connection);
113113
}
114114
}
115-
LOGGER.debug("Removed connection {}", connection.hashCode());
115+
LOGGER.trace("Removed connection {}", connection.hashCode());
116116
}
117117

118118
public synchronized void batchUpdate() {
@@ -173,7 +173,7 @@ public synchronized void publish(int accessoryId, int iid, EventableCharacterist
173173
* characteristics
174174
*/
175175
public synchronized void resync(HomekitRegistry registry) {
176-
LOGGER.debug("Resyncing subscriptions");
176+
LOGGER.trace("Resyncing subscriptions");
177177
flushUpdateBatch();
178178

179179
Map<EventableCharacteristic, ConnectionsWithIds> newSubscriptions = new HashMap<>();
@@ -187,7 +187,7 @@ public synchronized void resync(HomekitRegistry registry) {
187187
registry.getCharacteristics(subscribers.aid).get(subscribers.iid);
188188
if (newCharacteristic == null || newCharacteristic.getType() != oldCharacteristic.getType()) {
189189
// characteristic is gone or has completely changed; drop all subscriptions for it
190-
LOGGER.debug(
190+
LOGGER.trace(
191191
"{}:{} ({}) has gone missing; dropping subscriptions.",
192192
subscribers.aid,
193193
subscribers.iid,
@@ -199,7 +199,7 @@ public synchronized void resync(HomekitRegistry registry) {
199199
} else if (newCharacteristic != oldCharacteristic) {
200200
EventableCharacteristic newEventableCharacteristic =
201201
(EventableCharacteristic) newCharacteristic;
202-
LOGGER.debug(
202+
LOGGER.trace(
203203
"{}:{} has been replaced by a compatible characteristic; re-connecting subscriptions",
204204
subscribers.aid,
205205
subscribers.iid);
@@ -242,16 +242,16 @@ private void subscribe(int aid, int iid, EventableCharacteristic characteristic)
242242

243243
/** Remove all existing subscriptions */
244244
public synchronized void removeAll() {
245-
LOGGER.debug("Removing {} reverse connections from subscription manager", reverse.size());
245+
LOGGER.trace("Removing {} reverse connections from subscription manager", reverse.size());
246246
Iterator<Map.Entry<HomekitClientConnection, Set<EventableCharacteristic>>> i =
247247
reverse.entrySet().iterator();
248248
while (i.hasNext()) {
249249
Map.Entry<HomekitClientConnection, Set<EventableCharacteristic>> entry = i.next();
250250
HomekitClientConnection connection = entry.getKey();
251-
LOGGER.debug("Removing connection {}", connection.hashCode());
251+
LOGGER.trace("Removing connection {}", connection.hashCode());
252252
i.remove();
253253
removeConnection(connection, entry.getValue());
254254
}
255-
LOGGER.debug("Subscription sizes are {} and {}", reverse.size(), subscriptions.size());
255+
LOGGER.trace("Subscription sizes are {} and {}", reverse.size(), subscriptions.size());
256256
}
257257
}

0 commit comments

Comments
 (0)