]> git.basschouten.com Git - openhab-addons.git/blob
cfb3b5900ee205d4f4c28ca516a5cd0f919fc328
[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 /**
19  * Notification broker.
20  *
21  * @author Gabor Bicskei - Initial contribution
22  */
23 public class NotificationBroker {
24     /**
25      * Handlers
26      */
27     private Map<String, NotificationHandler> handlers = new HashMap<>();
28
29     /**
30      * Register new handler.
31      *
32      * @param trackerId Tracker id
33      * @param handler Notification handler
34      */
35     public void registerHandler(String trackerId, NotificationHandler handler) {
36         handlers.put(trackerId, handler);
37     }
38
39     public void sendNotification(LocationMessage msg) {
40         String trackerId = msg.getTrackerId();
41         handlers.entrySet().stream().filter(e -> !e.getKey().equals(trackerId))
42                 .forEach(e -> e.getValue().handleNotification(msg));
43     }
44 }