Search in sources :

Example 6 with Notification

use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.

the class DirectoryManagerImpl method processEntryChanged.

// Implementation to process entry changed events
protected static void processEntryChanged(String method, String name, int type, Set attrNames) {
    debug.message("DirectoryManagerImpl.processEntryChaged method " + "processing");
    initializeCacheSize();
    // Construct the XML document for the event change
    StringBuilder sb = new StringBuilder(100);
    sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(name).append("</Value></AttributeValuePair>");
    if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
        sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
        if (method.equalsIgnoreCase("objectsChanged")) {
            sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
            for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
                String attr = (String) items.next();
                sb.append("<Value>").append(attr).append("</Value>");
            }
            sb.append("</AttributeValuePair>");
        }
    }
    sb.append("</EventNotification>");
    if (cacheSize > 0) {
        Set<String> modDNs = getCachedValues(cache);
        // Add to cache
        modDNs.add(sb.toString());
        if (debug.messageEnabled()) {
            debug.message("DirectoryManagerImpl::processing entry change: " + sb.toString());
        }
    }
    if (debug.messageEnabled()) {
        debug.message("DirectoryManagerImpl = notificationURLS" + notificationURLs.values());
    }
    // If notification URLs are present, send notifications
    NotificationSet ns = null;
    synchronized (notificationURLs) {
        for (Map.Entry<String, URL> entry : notificationURLs.entrySet()) {
            String id = entry.getKey();
            URL url = entry.getValue();
            // Construct NotificationSet
            if (ns == null) {
                Notification notification = new Notification(sb.toString());
                ns = new NotificationSet(com.iplanet.am.sdk.remote.RemoteServicesImpl.SDK_SERVICE);
                ns.addNotification(notification);
            }
            try {
                PLLServer.send(url, ns);
                if (debug.messageEnabled()) {
                    debug.message("DirectorManagerImpl:sentNotification " + "URL: " + url + " Data: " + ns);
                }
            } catch (SendNotificationException ne) {
                if (debug.warningEnabled()) {
                    debug.warning("DirectoryManagerImpl: failed sending " + "notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
                }
                // Remove the URL from Notification List
                notificationURLs.remove(id);
            }
        }
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification)

Example 7 with Notification

use of com.iplanet.services.comm.share.Notification in project OpenAM by OpenRock.

the class IdRepoJAXRPCObjectImpl method processEntryChanged_idrepo.

// Implementation to process entry changed events
protected static void processEntryChanged_idrepo(String method, String name, int type, Set attrNames) {
    if (idRepoDebug.messageEnabled()) {
        idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged " + "method processing method: " + method + " name: " + name + " type: " + type + " attrName: " + attrNames);
    }
    initializeCacheSize();
    // Return if cache size is 0 or there are no remote clients
    if (cacheSize == 0 && idRepoNotificationURLs.isEmpty()) {
        if (idRepoDebug.messageEnabled()) {
            idRepoDebug.message("IdRepoJAXRPCObjectImpl." + "processEntryChaged No registered notification URLs: " + idRepoNotificationURLs + " and cache size is: " + cacheSize);
        }
        return;
    }
    // Construct the XML document for the event change
    StringBuilder sb = new StringBuilder(100);
    sb.append("<EventNotification><AttributeValuePair>").append("<Attribute name=\"method\" /><Value>").append(method).append("</Value></AttributeValuePair>").append("<AttributeValuePair><Attribute name=\"entityName\" />").append("<Value>").append(XMLUtils.escapeSpecialCharacters(name)).append("</Value></AttributeValuePair>");
    if (method.equalsIgnoreCase("objectChanged") || method.equalsIgnoreCase("objectsChanged")) {
        sb.append("<AttributeValuePair><Attribute name=\"eventType\" />").append("<Value>").append(type).append("</Value></AttributeValuePair>");
        if (method.equalsIgnoreCase("objectsChanged")) {
            sb.append("<AttributeValuePair><Attribute ").append("name=\"attrNames\"/>");
            for (Iterator items = attrNames.iterator(); items.hasNext(); ) {
                String attr = (String) items.next();
                sb.append("<Value>").append(attr).append("</Value>");
            }
            sb.append("</AttributeValuePair>");
        }
    }
    sb.append("</EventNotification>");
    // Update cache for polling by remote clients
    if (cacheSize > 0) {
        Set<String> modDNs = getCachedValues(idrepoCache);
        // Add to cache
        modDNs.add(sb.toString());
        if (idRepoDebug.messageEnabled()) {
            idRepoDebug.message("IdRepoJAXRPCObjectImpl.processing " + "entry change:" + sb.toString());
        }
    }
    // If notification URLs are present, send notifications
    if (idRepoDebug.messageEnabled()) {
        idRepoDebug.message("IdRepoJAXRPCObjectImpl.processEntryChaged =" + " notificationURLS " + idRepoNotificationURLs.values());
    }
    NotificationSet ns = null;
    synchronized (idRepoNotificationURLs) {
        for (Map.Entry<String, URL> entry : idRepoNotificationURLs.entrySet()) {
            String id = entry.getKey();
            URL url = entry.getValue();
            // Construct NotificationSet
            if (ns == null) {
                Notification notification = new Notification(sb.toString());
                ns = new NotificationSet(IDREPO_SERVICE);
                ns.addNotification(notification);
            }
            try {
                PLLServer.send(url, ns);
                if (idRepoDebug.messageEnabled()) {
                    idRepoDebug.message("IdRepoJAXRPCObjectImpl:" + "sentNotification URL: " + url + " Data: " + ns);
                }
            } catch (SendNotificationException ne) {
                if (idRepoDebug.warningEnabled()) {
                    idRepoDebug.warning("IdRepoJAXRPCObjectImpl: failed " + "sending notification to: " + url + "\nRemoving " + "URL from notification list.", ne);
                }
                // Remove the URL from Notification List
                idRepoNotificationURLs.remove(id);
            }
        }
    }
}
Also used : NotificationSet(com.iplanet.services.comm.share.NotificationSet) SendNotificationException(com.iplanet.services.comm.server.SendNotificationException) Iterator(java.util.Iterator) HashMap(java.util.HashMap) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) URL(java.net.URL) Notification(com.iplanet.services.comm.share.Notification)

Aggregations

Notification (com.iplanet.services.comm.share.Notification)7 NotificationSet (com.iplanet.services.comm.share.NotificationSet)6 SendNotificationException (com.iplanet.services.comm.server.SendNotificationException)5 URL (java.net.URL)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 CaseInsensitiveHashMap (com.sun.identity.common.CaseInsensitiveHashMap)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 PolicyException (com.sun.identity.policy.PolicyException)1 PolicyNotification (com.sun.identity.policy.remote.PolicyNotification)1 PolicyService (com.sun.identity.policy.remote.PolicyService)1