]> git.basschouten.com Git - openhab-addons.git/blob
b92a5772a507295483a6dceed3fe34de7012e58d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.gpstracker.internal.message;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.gpstracker.internal.message.dto.LocationMessage;
20
21 /**
22  * Notification broker.
23  *
24  * @author Gabor Bicskei - Initial contribution
25  */
26 @NonNullByDefault
27 public class NotificationBroker {
28     /**
29      * Handlers
30      */
31     private Map<String, NotificationHandler> handlers = new HashMap<>();
32
33     /**
34      * Register new handler.
35      *
36      * @param trackerId Tracker id
37      * @param handler Notification handler
38      */
39     public void registerHandler(String trackerId, NotificationHandler handler) {
40         handlers.put(trackerId, handler);
41     }
42
43     public void sendNotification(LocationMessage msg) {
44         String trackerId = msg.getTrackerId();
45         handlers.entrySet().stream().filter(e -> !e.getKey().equals(trackerId))
46                 .forEach(e -> e.getValue().handleNotification(msg));
47     }
48 }