Class Scopelet<S extends Scopelet<S>>
java.lang.Object
org.microbean.scopelet.Scopelet<S>
- Type Parameters:
S- theScopeletsubtype extending this class
- All Implemented Interfaces:
AutoCloseable, Constable, Aggregate, Factory<S>
- Direct Known Subclasses:
MapBackedScopelet, NoneScopelet
public abstract class Scopelet<S extends Scopelet<S>>
extends Object
implements AutoCloseable, Factory<S>
A manager of object lifespans on behalf of one or more notional scopes.
- Author:
- Laird Nelson
- See Also:
-
Field Summary
Fields inherited from interface Aggregate
EMPTY_ASSIGNMENTS, EMPTY_DEPENDENCIES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanactive()Returnstrueif and only if thisScopeletis active at the moment of the call.voidclose()protected final booleanclosed()Returnstrueif and only if at the moment of invocation thisScopeletis (irrevocably) closed (and therefore also not active).final SCreates thisScopeletby simply returning it.final voiddestroy(S me, Destruction creation) final booleandestroys()protected voidInforms any interested observers that thisScopelethas been irrevocably destroyed.protected voidInforms any interested observers that thisScopeletis about to be destroyed.protected voidInforms any interested observers that thisScopelethas just been initialized.abstract <I> Ibooleanbooleanremoves()final SReturns thisScopeletif it has been created via thecreate(Creation)method, ornullif that method has not yet been invoked.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Aggregate
assign, dependenciesMethods inherited from interface Factory
describeConstable
-
Constructor Details
-
Scopelet
-
-
Method Details
-
create
-
destroy
-
fireScopeletDestroying
Informs any interested observers that thisScopeletis about to be destroyed.- Parameters:
r- aReferencesSelector; must not benull- Throws:
NullPointerException- ifrisnull
-
fireScopeletDestroyed
Informs any interested observers that thisScopelethas been irrevocably destroyed.- Parameters:
r- aReferencesSelector; must not benull- Throws:
NullPointerException- ifrisnull
-
fireScopeletInitialized
Informs any interested observers that thisScopelethas just been initialized.- Parameters:
r- aReferencesSelector; must not benull- Throws:
NullPointerException- ifrisnull
-
singleton
-
destroys
-
active
-
instance
Checks to see if thisScopeletis active and then returns a pre-existing or created-on-demand contextual instance suitable for the combination of identifier,FactoryandCreation, ornull- Type Parameters:
I- the type of contextual instance- Parameters:
id- an identifier that can identify a contextual instance; may benullfactory- aFactory; may benullcreation- aCreation, typically the one in effect that is causing this method to be invoked in the first place; may benull- Returns:
- a contextual instance, possibly pre-existing, or possibly created just in time, or
null - Throws:
InactiveScopeletException- if thisScopeletis not activeClassCastException- if destruction is called for,creationis non-null, andcreationdoes not implementDestruction, a requirement of its contract- See Also:
-
remove
Checks to see if thisScopeletis active and then removes any contextual instance stored under the suppliedid, returningtrueif and only if removal actually took place.The default implementation of this method always returns
false. Subclasses are encouraged to override it as appropriate.- Parameters:
id- an identifier; may benull- Returns:
trueif and only if removal actually occurred- Throws:
InactiveScopeletException- if thisScopeletis not active
-
removes
Returnstrueif and only if thisScopeletstores contextual instances, and hence is capable of removing them.The default implementation of this method returns
false. Subclasses are encouraged to override it as appropriate.- Returns:
trueif and only if thisScopeletstores contextual instances, and hence is capable of removing them- Throws:
InactiveScopeletException- if thisScopeletis not active- See Also:
-
close
Irrevocably closes thisScopelet, and, by doing so, notionally makes it irrevocably closed and inactive.Overrides of this method must call
super.close()as part of their implementation or undefined behavior may result.- Specified by:
closein interfaceAutoCloseable- See Also:
-
closed
Returnstrueif and only if at the moment of invocation thisScopeletis (irrevocably) closed (and therefore also not active).- Returns:
trueif and only if at the moment of invocation thisScopeletis (irrevocably) closed (and therefore also not active)- See Also:
-