/** * Notify the listener about a change. If this is due to adding a new listener rather than * being an update, only notify the listener if this is the first notification sent to it. * * @param changeNotification the change notification to send * @param newListener call is triggered by adding a listener rather than an update */ private void notifyListener(ChangeNotification<T> changeNotification, boolean newListener) { lock.lock(); try { checkNotNull(changeNotification, "changeNotification"); final Listener<T> listener = listenerRef.get(); if (listener != null) { try { final boolean notified = listenerNotified.getAndSet(true); if (!(newListener && notified)) { listener.onChange(changeNotification); } } catch (Throwable e) { log.error("Change notification listener threw exception", e); } } } finally { lock.unlock(); } }
/** * Notify the listener about a change. If this is due to adding a new listener rather than * being an update, only notify the listener if this is the first notification sent to it. * * @param changeNotification the change notification to send * @param newListener call is triggered by adding a listener rather than an update */ private void notifyListener(ChangeNotification<T> changeNotification, boolean newListener) { lock.lock(); try { checkNotNull(changeNotification, "changeNotification"); final Listener<T> listener = listenerRef.get(); if (listener != null) { try { final boolean notified = listenerNotified.getAndSet(true); if (!(newListener && notified)) { listener.onChange(changeNotification); } } catch (Throwable e) { log.error("Change notification listener threw exception", e); } } } finally { lock.unlock(); } }