2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.gpstracker.internal.message;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.binding.gpstracker.internal.message.dto.LocationMessage;
22 * Notification broker.
24 * @author Gabor Bicskei - Initial contribution
27 public class NotificationBroker {
31 private Map<String, NotificationHandler> handlers = new HashMap<>();
34 * Register new handler.
36 * @param trackerId Tracker id
37 * @param handler Notification handler
39 public void registerHandler(String trackerId, NotificationHandler handler) {
40 handlers.put(trackerId, handler);
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));