Class CompositeSideEffect
- All Implemented Interfaces:
ISideEffect
ISideEffect
that is composed of a bunch of component
ISideEffect
s. It has the following properties:
- Disposing the composite will dispose all of the children.
- If the composite is paused, all of the children will be paused as well.
Children may belong to multiple composites. When this occurs, all of its parent composites must be resumed in order for the child to execute and the child will be disposed the first time any of its parents are disposed.
Children may be removed from a composite. When this occurs, the child may be resumed immediately if the composite was paused and disposing the composite will no longer have any effect on the removed child.
Disposing a child will automatically remove it from its parent composite(s).
The main use of this class is to manage a group of side-effects that share the same life-cycle. For example, all side-effects used to populate widgets within a workbench part would likely be paused and resumed when the part is made visible or invisible, and would all be disposed together when the part is closed.
- Since:
- 1.6
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(ISideEffect sideEffect) Adds the givenISideEffect
instance from the composite.void
addDisposeListener
(Consumer<ISideEffect> disposalConsumer) Adds a listener that will be invoked when thisISideEffect
instance is disposed.void
dispose()
Disposes the side-effect, detaching all listeners and deallocating all memory used by the side-effect.boolean
Returns true if this side-effect has been disposed.void
pause()
Increments the count of the number of times theISideEffect
has been paused.void
remove
(ISideEffect sideEffect) Removes the givenISideEffect
instance from the composite.void
removeDisposeListener
(Consumer<ISideEffect> disposalConsumer) Removes a dispose listener from thisISideEffect
instance.void
resume()
Increments the count of the number of times theISideEffect
has been resumed.void
Increments the count of the number of times theISideEffect
has been resumed.void
Causes the side effect to run synchronously if and only if it is currently dirty (that is, if one of its dependencies has changed since the last time it ran).
-
Constructor Details
-
CompositeSideEffect
public CompositeSideEffect()Default constructor of an CompositeSideEffect.
-
-
Method Details
-
dispose
public void dispose()Description copied from interface:ISideEffect
Disposes the side-effect, detaching all listeners and deallocating all memory used by the side-effect. The side-effect will not execute again after this method is invoked.This method may be invoked more than once.
- Specified by:
dispose
in interfaceISideEffect
-
isDisposed
public boolean isDisposed()Description copied from interface:ISideEffect
Returns true if this side-effect has been disposed. A disposed side-effect will never execute again or retain any strong references to the observables it uses. A side-effect which has not been disposed has some possibility of executing again in the future and of retaining strong references to observables.- Specified by:
isDisposed
in interfaceISideEffect
- Returns:
- true if this side-effect has been disposed.
-
addDisposeListener
Description copied from interface:ISideEffect
Adds a listener that will be invoked when thisISideEffect
instance is disposed. The listener will not be invoked if the receiver has already been disposed at the time when the listener is attached.- Specified by:
addDisposeListener
in interfaceISideEffect
- Parameters:
disposalConsumer
- a consumer which will be notified once thisISideEffect
is disposed.
-
removeDisposeListener
Description copied from interface:ISideEffect
Removes a dispose listener from thisISideEffect
instance. Has no effect if no such listener was previously attached.- Specified by:
removeDisposeListener
in interfaceISideEffect
- Parameters:
disposalConsumer
- a consumer which is supposed to be removed from the dispose listener list.
-
pause
public void pause()Description copied from interface:ISideEffect
Increments the count of the number of times theISideEffect
has been paused. If the side-effect has been paused a greater number of times than it has been resumed, it enters the paused state.When a
ISideEffect
is paused, this prevents it from running again until it is resumed. Note that the side-effect will continue listening to its dependencies while it is paused. If a dependency changes while theISideEffect
is paused, theISideEffect
will run again after it is resumed.A side-effect may be paused and resumed any number of times. You should use pause instead of dispose if there is a chance you may want to resume the SideEffect later.
- Specified by:
pause
in interfaceISideEffect
-
resume
public void resume()Description copied from interface:ISideEffect
Increments the count of the number of times theISideEffect
has been resumed. If the side-effect has been resumed an equal number of times than it has been paused, it leaves the paused state and enters the resumed state. It is an error to resumeISideEffect
more often than it has been paused.When a
ISideEffect
is resumed, it starts reacting to changes in tracked getters invoked by its runnable. It will continue to react to changes until it is either paused or disposed. If theISideEffect
is dirty, it will be run at the earliest opportunity after this method returns.- Specified by:
resume
in interfaceISideEffect
-
resumeAndRunIfDirty
public void resumeAndRunIfDirty()Description copied from interface:ISideEffect
Increments the count of the number of times theISideEffect
has been resumed. If the side-effect has been resumed an equal or greater number of times than it has been paused, it leaves the paused state and enters the resumed state.When a
ISideEffect
is resumed, it starts reacting to changes in TrackedGetters invoked by its runnable. It will continue to react to changes until it is either paused or disposed. If theISideEffect
is dirty, it will be run synchronously.This is a convenience method which is fully equivalent to calling
ISideEffect.resume()
followed byISideEffect.runIfDirty()
, but slightly faster.- Specified by:
resumeAndRunIfDirty
in interfaceISideEffect
-
runIfDirty
public void runIfDirty()Description copied from interface:ISideEffect
Causes the side effect to run synchronously if and only if it is currently dirty (that is, if one of its dependencies has changed since the last time it ran). Does nothing if theISideEffect
is currently paused.- Specified by:
runIfDirty
in interfaceISideEffect
-
add
Adds the givenISideEffect
instance from the composite.- Parameters:
sideEffect
-ISideEffect
-
remove
Removes the givenISideEffect
instance from the composite. This has no effect if the given side-effect is not part of the composite.- Parameters:
sideEffect
-ISideEffect
-