/*  Listeners defined in traits are bound in order of appearance, so you can
utilize built-in e.stopImmediatePropagation () semantics for the flow control.
--------------------------------------------------------------------
541586
function () {

        $assertEveryCalled (function (blockChangeEventCalled) {

            var textarea = new ($component ({

                    $traits: [DOMReference,
                              DOMEvents,
                              $trait ({ blockChangeEvent: $on ('change', function (e) { blockChangeEventCalled (); e.stopImmediatePropagation () }) }),
                              $trait ({ shouldNotCall:    $on ('change', function (e) { $fail }) }) ],

                    init: function () { this.domReady (
                                            N.textarea.insertMeAfter (document.body.lastChild)) } })) ()

                textarea.dispatchEvent ('change')
                textarea.destroy () }) }
413240
private void fireTreeStructureChanged()
   {
      // Guaranteed to return a non-null array
      Object[] listeners = m_listenerList.getListenerList();
      TreeModelEvent e = null;
      // Process the listeners last to first, notifying
      // those that are interested in this event
      for (int i = listeners.length - 2; i >= 0; i -= 2)
      {
         if (listeners[i] == TreeModelListener.class)
         {
            // Lazily create the event:
            if (e == null)
            {
               e = new TreeModelEvent(getRoot(), new Object[]
               {
                  getRoot()
               }, null, null);
            }
            ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e);
         }
      }
   }
1020912
function() {
		var bindingState = this._bindingState;
		var options = this._options;

		// Turn off the parent listener
		if (bindingState.parent === true && this._parentToChild === true) {
			bindingState.parent = false;
			turnOffListeningAndUpdate(options.parent, options.child, this._updateChild, options.queue);
		}

		// Turn off the child listener
		if (bindingState.child === true && this._childToParent === true) {
			bindingState.child = false;
			turnOffListeningAndUpdate(options.child, options.parent, this._updateParent, options.queue);
		}
	}
339858
public void doAddListener(BaseListener listener)
    {
        if (m_listener != null)
            m_listener.doAddListener((FileListener)listener);
        else
            m_listener = (FileListener)listener;
        boolean bOldState = listener.setEnabledListener(false);   // To disable recursive forever loop!
        listener.setOwner(this);
        listener.setEnabledListener(bOldState);        // Renable the listener to eliminate echos
    }
247763
function(argument, event_args, listener_args) {

		var value = this._style_bindings[listener_args.name].getValue() || '';
		if (this._is_inDOM) Firestorm.Element.setStyle(this.getDOMElement(), listener_args.name, value.toString().trim());

	}
740712
function (event, type) {
        if (!this.getMap()) {
            return;
        }
        const eventType = type || this._getEventTypeToFire(event);
        if (eventType === 'contextmenu' && this.listens('contextmenu')) {
            stopPropagation(event);
            preventDefault(event);
        }
        const params = this._getEventParams(event);
        this._fireEvent(eventType, params);
    }
1321984
public void initListeners() {
        instanceStateChangedListener.watch(ChangedType.UPDATED);
        dataSourceStateChangedListener.watch(ChangedType.UPDATED, ChangedType.DELETED);
    }
809662
public synchronized void addStateListener(@Nonnull EndpointStateListener<VALUE_TYPE, ARG_TYPE> listener) throws IllegalArgumentException {
        checkListenerNonNull(listener);
        fieldStateListeners.add(listener);
        if (informStateListenerOnAdd) {
            informStateListener(getStateAndValue(), listener);
        }
    }
291136
private void notifyListeners(LifecycleState oldState, LifecycleState newState)
  {
    notifyWait();
    
    // initial must be outside synchronized to avoid any blocking
    // for fail-safe shutdown
    if (_listeners == null) {
      return;
    }
    
    ArrayList<LifecycleListener> listeners = null;
    
    synchronized (this) {
      notifyAll();

      if (_listeners != null) {
        for (int i = 0; i < _listeners.size(); i++) {
          LifecycleListener listener = _listeners.get(i).get();

          if (listener != null) {
            if (listeners == null) {
              listeners = new ArrayList<LifecycleListener>();
            }
            
            listeners.add(listener);
          }
          else {
            _listeners.remove(i);
            i--;
          }
        }
      }
    }

    if (listeners != null) {
      for (LifecycleListener listener : listeners) {
        listener.lifecycleEvent(oldState, newState);
      }
    }
  }
1149787
function (event) {
            // duplicate,in case detach itself in one observer
            var observers = [].concat(this.observers), ret, gRet, len = observers.length, i;
            for (i = 0; i < len && !event.isImmediatePropagationStopped(); i++) {
                ret = observers[i].notify(event, this);
                if (gRet !== false && ret !== undefined) {
                    gRet = ret;
                }
            }
            return gRet;
        }
317016
@SuppressWarnings("unchecked")
    private void prepareListeners() {
        if (preparedListeners != null && preparedUnspecifiedListeners != null) {
            // Already created, skip
            return;
        }
        preparedListeners = new ConcurrentHashMap<>();
        Stream<Class<? extends GloballyAttachableListener>> eventTypes = Stream.concat(
                listeners.keySet().stream(),
                Stream.concat(listenerSuppliers.keySet().stream(),
                        listenerFunctions.keySet().stream())
        ).distinct();
        eventTypes.forEach(type -> {
            ArrayList<Function<DiscordApi, GloballyAttachableListener>> typeListenerFunctions = new ArrayList<>();
            listeners.getOrDefault(type, Collections.emptyList()).forEach(
                    listener -> typeListenerFunctions.add(api -> listener)
            );
            listenerSuppliers.getOrDefault(type, Collections.emptyList()).forEach(
                    supplier -> typeListenerFunctions.add(api -> supplier.get())
            );
            listenerFunctions.getOrDefault(type, Collections.emptyList()).forEach(
                    function -> typeListenerFunctions.add((Function<DiscordApi, GloballyAttachableListener>) function)
            );
            preparedListeners.put(type, typeListenerFunctions);
        });
        // Unspecified Listeners
        preparedUnspecifiedListeners = new CopyOnWriteArrayList<>(unspecifiedListenerFunctions);
        unspecifiedListenerSuppliers.forEach(supplier -> preparedUnspecifiedListeners.add((api) -> supplier.get()));
        unspecifiedListeners.forEach(listener -> preparedUnspecifiedListeners.add((api) -> listener));
    }
331217
private synchronized void initializeListeners()
    {
        if (this.listenersByName == null) {
            this.listenersByEvent = new ConcurrentHashMap<>();
            this.listenersByName = new ConcurrentHashMap<>();

            // Can be null in unit tests
            if (this.componentManager != null) {
                try {
                    for (EventListener listener : this.componentManager
                        .<EventListener>getInstanceList(EventListener.class)) {
                        addListener(listener);
                    }
                } catch (ComponentLookupException e) {
                    this.logger.error("Failed to lookup listeners", e);
                }
            }
        }
    }
1139294
public synchronized static void init(final NewExtensionListener _listener)
    {
        PeerMonitor.listener = _listener;

        if (PeerMonitor.self == null)
        {
            PeerMonitor.self = new PeerMonitor();
        }
        else if (_listener != null)
        {
            logger.error("Call to PeerMonitor.init, but it's already initialized. Listener will not be set");
        }
    }
1214504
public boolean doInnerCallback(ModificationQueue modificationQueue, SecurityContext securityContext, ErrorBuffer errorBuffer) throws FrameworkException {

		// check for modification propagation along the relationships
		if ((status & STATE_PROPAGATING_MODIFICATION) == STATE_PROPAGATING_MODIFICATION && object instanceof AbstractNode) {

			Set<AbstractNode> nodes = ((AbstractNode)object).getNodesForModificationPropagation();
			if (nodes != null) {

				for (AbstractNode node : nodes) {

					modificationQueue.propagatedModification(node);
				}
			}

		}

		// examine only the last 4 bits here
		switch (status & 0x000f) {

			case 15:
			case 14:
			case 13:
			case 12:
			case 11:
			case 10:
			case  9:
			case  8: // since all values >= 8 mean that the object was passively deleted, no action has to be taken
				 // (no callback for passive deletion!)
				break;

			case 7:	// created, modified, deleted, poor guy => no callback
				break;

			case 6: // created, modified => only creation callback will be called
				object.onCreation(securityContext, errorBuffer);
				break;

			case 5: // created, deleted => no callback
				break;

			case 4: // created => creation callback
				object.onCreation(securityContext, errorBuffer);
				break;

			case 3: // modified, deleted => deletion callback
				object.onDeletion(securityContext, errorBuffer, removedProperties);
				break;

			case 2: // modified => modification callback
				object.onModification(securityContext, errorBuffer, modificationQueue);
				break;

			case 1: // deleted => deletion callback
				object.onDeletion(securityContext, errorBuffer, removedProperties);
				break;

			case 0:	// no action, no callback
				break;

			default:
				break;
		}

		// mark as finished
		modified = false;

		return !errorBuffer.hasError();
	}
84159
@PostConstruct
    public void init() {
        validatedText.focusedProperty().addListener((o, oldVal, newVal) -> {
            if (!newVal) {
                validatedText.validate();
            }
        });
        validatedPassowrd.focusedProperty().addListener((o, oldVal, newVal) -> {
            if (!newVal) {
                validatedPassowrd.validate();
            }
        });
        jfxTextArea.focusedProperty().addListener((o, oldVal, newVal) -> {
            if (!newVal) {
                jfxTextArea.validate();
            }
        });
    }
369110
public void removeListener(BaseListener listener, boolean bFreeListener)
    {
        if (m_listener != null)
        {
            if (m_listener == listener)
            {
                m_listener = (FieldListener)listener.getNextListener();
                listener.unlink(bFreeListener);     // remove theBehavior from the linked list
            }
            else
                m_listener.removeListener(listener, bFreeListener);
        } // Remember to free the listener after removing it!
    }
149703
public boolean syncClonedListener(BaseField field, FieldListener listener, boolean bInitCalled)
    {
        if (!bInitCalled)
        {
            BaseField fldTarget = this.getSyncedListenersField(m_fldTarget, listener);
            ((InitOnChangeHandler)listener).init(null, fldTarget);
        }
        return super.syncClonedListener(field, listener, true);
    }