Skip to content

Commit 4b8ba89

Browse files
author
Eugen Freiter
committed
fix potential NPE. adapt log level
Signed-off-by: Eugen Freiter <freiter@gmx.de>
1 parent 3cfad1d commit 4b8ba89

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public synchronized void batchUpdate() {
9797

9898
public synchronized void completeUpdateBatch() {
9999
if (--this.nestedBatches == 0 && !pendingNotifications.isEmpty()) {
100-
LOGGER.info("Publishing batched changes");
100+
LOGGER.debug("Publishing batched changes");
101101
for (ConcurrentMap.Entry<HomekitClientConnection, ArrayList<PendingNotification>> entry :
102102
pendingNotifications.entrySet()) {
103103
try {
@@ -112,10 +112,12 @@ public synchronized void completeUpdateBatch() {
112112
}
113113

114114
public synchronized void publish(int accessoryId, int iid, EventableCharacteristic changed) {
115+
final Set<HomekitClientConnection> subscribers = subscriptions.get(changed);
116+
if ((subscribers == null) || (subscribers.isEmpty())) return; // no subscribers
115117
if (nestedBatches != 0) {
116-
LOGGER.info("Batching change for " + accessoryId);
118+
LOGGER.debug("Batching change for " + accessoryId);
117119
PendingNotification notification = new PendingNotification(accessoryId, iid, changed);
118-
for (HomekitClientConnection connection : subscriptions.get(changed)) {
120+
for (HomekitClientConnection connection : subscribers) {
119121
if (!pendingNotifications.containsKey(connection)) {
120122
pendingNotifications.put(connection, new ArrayList<PendingNotification>());
121123
}
@@ -126,8 +128,8 @@ public synchronized void publish(int accessoryId, int iid, EventableCharacterist
126128

127129
try {
128130
HttpResponse message = new EventController().getMessage(accessoryId, iid, changed);
129-
LOGGER.info("Publishing change for " + accessoryId);
130-
for (HomekitClientConnection connection : subscriptions.get(changed)) {
131+
LOGGER.debug("Publishing change for " + accessoryId);
132+
for (HomekitClientConnection connection : subscribers) {
131133
connection.outOfBand(message);
132134
}
133135
} catch (Exception e) {

0 commit comments

Comments
 (0)