Class Scopelet<S extends Scopelet<S>>
java.lang.Object
org.microbean.scopelet.Scopelet<S>
- Type Parameters:
S
- theScopelet
subtype 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
FieldsModifier and TypeFieldDescriptionstatic final Attributes
AnAttributes
identifying the (well-known and normal) application scope.static final Attributes
AnAttributes
identifying the (well-known) none pseudo-scope.static final Attributes
AnAttributes
identifying the scope designator.static final Attributes
AnAttributes
identifying the (well-known) singleton pseudo-scope.Fields inherited from interface org.microbean.bean.Aggregate
EMPTY_ASSIGNMENTS, EMPTY_DEPENDENCIES
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
active()
Returnstrue
if and only if thisScopelet
is active at the moment of the call.void
close()
protected final boolean
closed()
Returnstrue
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active).final S
Creates thisScopelet
by simply returning it.final boolean
destroys()
abstract <I> I
boolean
final S
Returns thisScopelet
if it has been created via thecreate(Creation)
method, ornull
if that method has not yet been invoked.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.microbean.bean.Aggregate
assign, dependencies
Methods inherited from interface org.microbean.bean.Factory
describeConstable, destroy
-
Field Details
-
SCOPE
AnAttributes
identifying the scope designator. -
SINGLETON_ID
AnAttributes
identifying the (well-known) singleton pseudo-scope.The
Attributes
constituting the singleton pseudo-scope identifier is attributed with the scope designator, the qualifier designator, and the primordial qualifier, indicating that the scope it identifies governs itself. -
APPLICATION_ID
AnAttributes
identifying the (well-known and normal) application scope. -
NONE_ID
AnAttributes
identifying the (well-known) none pseudo-scope.
-
-
Constructor Details
-
Scopelet
-
-
Method Details
-
create
-
singleton
-
destroys
-
active
-
instance
Checks to see if thisScopelet
is active and then returns a pre-existing or created-on-demand contextual instance suitable for the combination of identifier,Factory
andCreation
, ornull
- Type Parameters:
I
- the type of contextual instance- Parameters:
id
- an identifier that can identify a contextual instance; may benull
factory
- aFactory
; may benull
creation
- 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 thisScopelet
is not activeClassCastException
- ifcreation
is non-null
and does not implementDestruction
, a requirement of its contract- See Also:
-
remove
Checks to see if thisScopelet
is active and then removes any contextual instance stored under the suppliedid
, returningtrue
if 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:
true
if and only if removal actually occurred- Throws:
InactiveScopeletException
- if thisScopelet
is not active
-
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:
close
in interfaceAutoCloseable
- See Also:
-
closed
Returnstrue
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active).- Returns:
true
if and only if at the moment of invocation thisScopelet
is (irrevocably) closed (and therefore also not active)- See Also:
-