Search in sources :

Example 1 with NamingEvent

use of javax.naming.event.NamingEvent in project wildfly by wildfly.

the class NamingEventCoordinator method fireEvent.

/**
     * Fire a naming event.  An event will be created with the provided information and sent to each listener that matches
     * the target and scope information.
     *
     * @param context The event context generating the event.
     * @param name The target name the event represents
     * @param existingBinding The existing binding at the provided name
     * @param newBinding The new binding at the provided name
     * @param type The event type
     * @param changeInfo The change info for the event
     * @param scopes The scopes this event should be fired against
     */
void fireEvent(final EventContext context, final Name name, final Binding existingBinding, final Binding newBinding, int type, final String changeInfo, final Integer... scopes) {
    final String target = name.toString();
    final Set<Integer> scopeSet = new HashSet<Integer>(Arrays.asList(scopes));
    final NamingEvent event = new NamingEvent(context, type, newBinding, existingBinding, changeInfo);
    final Set<ListenerHolder> holdersToFire = new HashSet<ListenerHolder>();
    // Check for OBJECT_SCOPE based listeners
    if (scopeSet.contains(EventContext.OBJECT_SCOPE)) {
        final TargetScope targetScope = new TargetScope(target, EventContext.OBJECT_SCOPE);
        final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
        if (holders != null) {
            for (ListenerHolder holder : holders) {
                holdersToFire.add(holder);
            }
        }
    }
    // Check for ONELEVEL_SCOPE based listeners
    if (scopeSet.contains(EventContext.ONELEVEL_SCOPE) && !name.isEmpty()) {
        final TargetScope targetScope = new TargetScope(name.getPrefix(name.size() - 1).toString(), EventContext.ONELEVEL_SCOPE);
        final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
        if (holders != null) {
            for (ListenerHolder holder : holders) {
                holdersToFire.add(holder);
            }
        }
    }
    // Check for SUBTREE_SCOPE based listeners
    if (scopeSet.contains(EventContext.SUBTREE_SCOPE) && !name.isEmpty()) {
        for (int i = 1; i < name.size(); i++) {
            final Name parentName = name.getPrefix(i);
            final TargetScope targetScope = new TargetScope(parentName.toString(), EventContext.SUBTREE_SCOPE);
            final List<ListenerHolder> holders = holdersByTarget.get(targetScope);
            if (holders != null) {
                for (ListenerHolder holder : holders) {
                    holdersToFire.add(holder);
                }
            }
        }
    }
    executor.execute(new FireEventTask(holdersToFire, event));
}
Also used : NamingEvent(javax.naming.event.NamingEvent) HashSet(java.util.HashSet) Name(javax.naming.Name)

Example 2 with NamingEvent

use of javax.naming.event.NamingEvent in project jdk8u_jdk by JetBrains.

the class EventQueue method run.

/**
     * Pull events off the queue and dispatch them.
     */
public void run() {
    QueueElement qe;
    try {
        while ((qe = dequeue()) != null) {
            EventObject e = qe.event;
            Vector<NamingListener> v = qe.vector;
            for (int i = 0; i < v.size(); i++) {
                if (e instanceof NamingEvent) {
                    ((NamingEvent) e).dispatch(v.elementAt(i));
                // An exception occurred: if notify all naming listeners
                } else if (e instanceof NamingExceptionEvent) {
                    ((NamingExceptionEvent) e).dispatch(v.elementAt(i));
                } else if (e instanceof UnsolicitedNotificationEvent) {
                    ((UnsolicitedNotificationEvent) e).dispatch((UnsolicitedNotificationListener) v.elementAt(i));
                }
            }
            qe = null;
            e = null;
            v = null;
        }
    } catch (InterruptedException e) {
    // just die
    }
}
Also used : NamingListener(javax.naming.event.NamingListener) UnsolicitedNotificationEvent(javax.naming.ldap.UnsolicitedNotificationEvent) NamingEvent(javax.naming.event.NamingEvent) NamingExceptionEvent(javax.naming.event.NamingExceptionEvent) EventObject(java.util.EventObject)

Aggregations

NamingEvent (javax.naming.event.NamingEvent)2 EventObject (java.util.EventObject)1 HashSet (java.util.HashSet)1 Name (javax.naming.Name)1 NamingExceptionEvent (javax.naming.event.NamingExceptionEvent)1 NamingListener (javax.naming.event.NamingListener)1 UnsolicitedNotificationEvent (javax.naming.ldap.UnsolicitedNotificationEvent)1