@Test public void purgeChangeListener() { final B entity = new B(); final B other = new B(); final EntityChangeBroker broker = new EntityChangeBroker(); final RecordingListener listener = new RecordingListener(); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); broker.addChangeListener( listener ); assertEntityRemovedMessageSent( entity, broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); broker.addChangeListener( B.class, listener ); assertEntityRemovedMessageSent( entity, broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); broker.addChangeListener( B.class, listener ); broker.addChangeListener( C.class, listener ); assertEntityRemovedMessageSent( entity, broker, listener ); assertEntityRemovedMessageSent( new C(), broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); assertEntityRemovedMessageNotSent( new C(), broker, listener ); broker.addChangeListener( entity, listener ); assertEntityRemovedMessageSent( entity, broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); broker.addChangeListener( entity, listener ); broker.addChangeListener( other, listener ); assertEntityRemovedMessageSent( entity, broker, listener ); assertEntityRemovedMessageSent( other, broker, listener ); broker.purgeChangeListener( listener ); assertEntityRemovedMessageNotSent( entity, broker, listener ); assertEntityRemovedMessageNotSent( other, broker, listener ); }
public void purgeChangeListener( @Nonnull final EntityChangeListener listener ) { if ( isSending() ) { _deferredListenerActions.add( new DeferredListenerAction( null, listener, ActionType.PURGE ) ); } else { final ListenerEntry entry = findEntryForListener( listener ); if ( null != entry ) { if ( entry.isGlobalListener() ) { removeChangeListener( listener ); } final Set<Class<?>> types = entry.interestedTypeSet(); final Set<Class<?>> typesToRemove = types.size() > 1 ? new HashSet<>( types ) : types; for ( final Class<?> type : typesToRemove ) { removeChangeListener( type, listener ); } final Set<Object> instances = entry.interestedInstanceSet(); final Set<Object> instancesToRemove = instances.size() > 1 ? new HashSet<>( instances ) : instances; for ( final Object instance : instancesToRemove ) { removeChangeListener( instance, listener ); } } } }
EntityChangeBroker { public void purgeChangeListener( @Nonnull final EntityChangeListener listener ) { if ( isSending() ) { _deferredListenerActions.add( new DeferredListenerAction( null, listener, ActionType.PURGE ) ); } else { final ListenerEntry entry = findEntryForListener( listener ); if ( null != entry ) { if ( entry.isGlobalListener() ) { removeChangeListener( listener ); } final Set<Class<?>> types = entry.interestedTypeSet(); final Set<Class<?>> typesToRemove = types.size() > 1 ? new HashSet<>( types ) : types; for ( final Class<?> type : typesToRemove ) { removeChangeListener( type, listener ); } final Set<Object> instances = entry.interestedInstanceSet(); final Set<Object> instancesToRemove = instances.size() > 1 ? new HashSet<>( instances ) : instances; for ( final Object instance : instancesToRemove ) { removeChangeListener( instance, listener ); } } } } }
EntityChangeBroker { public void purgeChangeListener( @Nonnull final EntityChangeListener listener ) { if ( isSending() ) { _deferredListenerActions.add( new DeferredListenerAction( null, listener, ActionType.PURGE ) ); } else { final ListenerEntry entry = findEntryForListener( listener ); if ( null != entry ) { if ( entry.isGlobalListener() ) { removeChangeListener( listener ); } final Set<Class<?>> types = entry.interestedTypeSet(); final Set<Class<?>> typesToRemove = types.size() > 1 ? new HashSet<>( types ) : types; for ( final Class<?> type : typesToRemove ) { removeChangeListener( type, listener ); } final Set<Object> instances = entry.interestedInstanceSet(); final Set<Object> instancesToRemove = instances.size() > 1 ? new HashSet<>( instances ) : instances; for ( final Object instance : instancesToRemove ) { removeChangeListener( instance, listener ); } } } } EntityChangeBroker(); }
EntityChangeBroker { public void purgeChangeListener( @Nonnull final EntityChangeListener listener ) { if ( isSending() ) { _deferredListenerActions.add( new DeferredListenerAction( null, listener, ActionType.PURGE ) ); } else { final ListenerEntry entry = findEntryForListener( listener ); if ( null != entry ) { if ( entry.isGlobalListener() ) { removeChangeListener( listener ); } final Set<Class<?>> types = entry.interestedTypeSet(); final Set<Class<?>> typesToRemove = types.size() > 1 ? new HashSet<>( types ) : types; for ( final Class<?> type : typesToRemove ) { removeChangeListener( type, listener ); } final Set<Object> instances = entry.interestedInstanceSet(); final Set<Object> instancesToRemove = instances.size() > 1 ? new HashSet<>( instances ) : instances; for ( final Object instance : instancesToRemove ) { removeChangeListener( instance, listener ); } } } } EntityChangeBroker(); void addChangeListener( @Nonnull final EntityChangeListener listener ); void addChangeListener( @Nonnull final Class<?> clazz,
                                 @Nonnull final EntityChangeListener listener ); void addChangeListener( @Nonnull final Object entity, @Nonnull final EntityChangeListener listener ); void removeChangeListener( @Nonnull final EntityChangeListener listener ); void removeChangeListener( @Nonnull final Object entity, @Nonnull final EntityChangeListener listener ); void removeAllChangeListeners( @Nonnull final Object object ); void removeChangeListener( @Nonnull final Class<?> clazz,
                                    @Nonnull final EntityChangeListener listener ); void purgeChangeListener( @Nonnull final EntityChangeListener listener ); @Nonnull EntityBrokerLock pause(); boolean isPaused(); boolean isEnabled(); }
EntityChangeBroker { public void purgeChangeListener( @Nonnull final EntityChangeListener listener ) { if ( isSending() ) { _deferredListenerActions.add( new DeferredListenerAction( null, listener, ActionType.PURGE ) ); } else { final ListenerEntry entry = findEntryForListener( listener ); if ( null != entry ) { if ( entry.isGlobalListener() ) { removeChangeListener( listener ); } final Set<Class<?>> types = entry.interestedTypeSet(); final Set<Class<?>> typesToRemove = types.size() > 1 ? new HashSet<>( types ) : types; for ( final Class<?> type : typesToRemove ) { removeChangeListener( type, listener ); } final Set<Object> instances = entry.interestedInstanceSet(); final Set<Object> instancesToRemove = instances.size() > 1 ? new HashSet<>( instances ) : instances; for ( final Object instance : instancesToRemove ) { removeChangeListener( instance, listener ); } } } } EntityChangeBroker(); void addChangeListener( @Nonnull final EntityChangeListener listener ); void addChangeListener( @Nonnull final Class<?> clazz,
                                 @Nonnull final EntityChangeListener listener ); void addChangeListener( @Nonnull final Object entity, @Nonnull final EntityChangeListener listener ); void removeChangeListener( @Nonnull final EntityChangeListener listener ); void removeChangeListener( @Nonnull final Object entity, @Nonnull final EntityChangeListener listener ); void removeAllChangeListeners( @Nonnull final Object object ); void removeChangeListener( @Nonnull final Class<?> clazz,
                                    @Nonnull final EntityChangeListener listener ); void purgeChangeListener( @Nonnull final EntityChangeListener listener ); @Nonnull EntityBrokerLock pause(); boolean isPaused(); boolean isEnabled();  }