SMSEventListenerManager.java revision 083ce1f7c46d83d177124cf39bf2e25b15c70745
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: SMSEventListenerManager.java,v 1.12 2009/01/28 05:35:03 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey * Portions Copyright 2015-2016 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.sm;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Collections;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.DN;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.SearchScope;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumseyimport com.sun.identity.shared.debug.Debug;
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Receives notifications for all SMS object changes from
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <class>SMSNotificationManager</class> and dispatches the same to <class>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CachedSMSEntry</class> and <class>CachedSubEntries</class>. This class
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * also handles the case of sending deleted event for recursive deletes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterclass SMSEventListenerManager implements SMSObjectListener {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // All Notification Objects list
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private static final Map<String, NotificationObject> notificationObjects =
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington Collections.synchronizedMap(new HashMap<String, NotificationObject>());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // CachedSMSEntry objects
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private static final Map<String, Set<NotificationObject>> nodeChanges =
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Collections.synchronizedMap(new HashMap<String, Set<NotificationObject>>());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // CachedSubEntries objects
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private static final Map<String, Set<NotificationObject>> subNodeChanges =
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Collections.synchronizedMap(new HashMap<String, Set<NotificationObject>>());
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Static Initialization variables
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = SMSEntry.eventDebug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static boolean initialized;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey static void initialize() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!initialized) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (SMSNotificationManager.isCacheEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSNotificationManager.getInstance()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .registerCallbackHandler(new SMSEventListenerManager());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Initialized SMS Event listner");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initialized = true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("SMSEventListenerManager::initialize " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "Unable to intialize SMS listener: " + e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private SMSEventListenerManager() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Processes object changed notifications
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void objectChanged(String odn, int event) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster objectChanged(odn, event, false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Processes object changed notifications. The flag isLocal is used
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // distingush the self generated DELETE notifications for recursive
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // deletes, especially when data store notifications are disabled.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // In which case, delete notifications will never be generated.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void objectChanged(String odn, int event, boolean isLocal) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("SMSEventListener::entry changed for: " + odn +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " type: " + event);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Normalize the DN
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington DN sdn = DN.valueOf(odn);
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String dn = sdn.toString().toLowerCase();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // If event is delete, need to send notifications for sub-entries
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Even if backend datastore notification is enabled, they woould
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // arrive much later causing write-through cache issues.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!isLocal && (event == SMSObjectListener.DELETE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Collect the immediate children of the current sdn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // from nodeChanges. All "subNodeChanges" entries would
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // have an entry in "nodeChanges", hence donot have to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // iterate throught it
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Set<String> childDNs = new HashSet<>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (nodeChanges) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey for (String cdn : nodeChanges.keySet()) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if (DN.valueOf(cdn).isInScopeOf(sdn, SearchScope.SUBORDINATES)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster childDNs.add(cdn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Send the notifications
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("SMSEventListener::objectChanged: Sending " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "delete event of: " + dn + " to child nodes: " + childDNs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey for (String item : childDNs) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster objectChanged(item, event, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Send notifications to external listeners also if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // data store notification is not enabled
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!SMSNotificationManager.isDataStoreNotificationEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSNotificationManager.getInstance().sendNotifications(
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey item, event, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Send notifications to CachedSMSEntries
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey sendNotifications(nodeChanges.get(dn), odn, event);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Process sub-entry changed events, not interested in attribute mods
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((event == SMSObjectListener.ADD) ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (event == SMSObjectListener.DELETE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Send notifications to CachedSubEntries
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("SMSEventListener::entry changed for: " + dn +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " sending notifications to its parents");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey sendNotifications(subNodeChanges.get(DN.valueOf(dn).parent().toString().toLowerCase()), odn, event);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void allObjectsChanged() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("SMSEventListenerManager::allObjectsChanged called");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Collect all the DNs from "nodeChanges" and send notifications
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington Set<String> dns = new HashSet<>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (nodeChanges) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington for (String item : nodeChanges.keySet()) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington dns.add(item);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Send MODIFY notifications
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington for (String item : dns) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington objectChanged(item, SMSObjectListener.MODIFY);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Registers notification for changes to nodes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey static String registerForNotifyChangesToNode(String dn, SMSEventListener eventListener) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey initialize();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String ndn = DN.valueOf(dn).toString().toLowerCase();
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey return (addNotificationObject(nodeChanges, ndn, eventListener));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Registers notification for changes to its sub-nodes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey static String registerForNotifyChangesToSubNodes(String dn, SMSEventListener eventListener) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey initialize();
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String ndn = DN.valueOf(dn).toString().toLowerCase();
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey return (addNotificationObject(subNodeChanges, ndn, eventListener));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes notification objects
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey static void removeNotification(String notificationID) {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington NotificationObject no = notificationObjects.get(notificationID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (no != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster no.set.remove(no);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster notificationObjects.remove(notificationID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Adds notification method to the map
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private static String addNotificationObject(Map<String, Set<NotificationObject>> nChangesMap, String dn,
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey SMSEventListener eventListener) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Set<NotificationObject> nObjects;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (nChangesMap) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey nObjects = nChangesMap.get(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (nObjects == null) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey nObjects = Collections.synchronizedSet(new HashSet<NotificationObject>());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nChangesMap.put(dn, nObjects);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey NotificationObject no = new NotificationObject(eventListener, nObjects);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nObjects.add(no);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster notificationObjects.put(no.getID(), no);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (no.getID());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sends notification to methods and objects within the set
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private static void sendNotifications(Set<NotificationObject> nObjects, String dn, int event) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((nObjects == null) || (nObjects.isEmpty())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Set<NotificationObject> nobjs = new HashSet<>(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (nObjects) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nobjs.addAll(nObjects);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey for (NotificationObject no : nobjs) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey no.notifyEvent(dn, event);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey debug.error("SMSEvent notification: Unable to send notification: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static class NotificationObject {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String id;
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey SMSEventListener eventListener;
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey Set<NotificationObject> set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey NotificationObject(SMSEventListener eventListener, Set<NotificationObject> s) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey this.id = SMSUtils.getUniqueID();
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey this.eventListener = eventListener;
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey this.set = s;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String getID() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (id);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int hashCode() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int hash = 3;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster hash = 13 * hash + (id != null ? id.hashCode() : 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return hash;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey @Override
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean equals(Object o) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (o instanceof NotificationObject) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster NotificationObject no = (NotificationObject) o;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (id.equals(no.id));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (false);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey private void notifyEvent(String dn, int event) {
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey eventListener.notifySMSEvent(dn, event);
083ce1f7c46d83d177124cf39bf2e25b15c70745Tom Rumsey }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}