@Override public ComponentImpl add(ComponentStateListener listener) { getExecutor().execute(() -> { m_listeners.add(listener); switch (m_lastStateDeliveredToListeners) { case STARTING: // this new listener missed the starting cb listener.changed(ComponentImpl.this, STARTING); break; case TRACKING_OPTIONAL: // this new listener missed the starting/started cb listener.changed(ComponentImpl.this, STARTING); listener.changed(ComponentImpl.this, TRACKING_OPTIONAL); break; case STOPPING: // this new listener missed the starting/started/stopping cb listener.changed(ComponentImpl.this, STARTING); listener.changed(ComponentImpl.this, TRACKING_OPTIONAL); listener.changed(ComponentImpl.this, STOPPING); break; case STOPPED: // no need to call missed listener callbacks break; default: break; } }); return this; }
private void notifyListeners(ComponentState state) { if (m_scope == ServiceScope.SINGLETON) { m_lastStateDeliveredToListeners = state; for (ComponentStateListener l : m_listeners) { try { l.changed(this, state); } catch (Exception e) { m_logger.log(Logger.LOG_ERROR, "Exception caught while invoking component state listener", e); } } } }