Package net.officefloor.frame.util
Class ManagedObjectUserStandAlone
- java.lang.Object
-
- net.officefloor.frame.util.ManagedObjectUserStandAlone
-
- All Implemented Interfaces:
AsynchronousContext
,ManagedObjectContext
,ObjectRegistry
,ManagedObjectUser
public class ManagedObjectUserStandAlone extends java.lang.Object implements ManagedObjectUser, ManagedObjectContext, AsynchronousContext, ObjectRegistry
Implementation of aManagedObjectUser
to source an object from aManagedObjectSource
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description ManagedObjectUserStandAlone()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends java.lang.Throwable>
voidcomplete(AsynchronousOperation<T> operation)
Indicates that theAsynchronousManagedObject
has completed and is ready for another operation.java.lang.String
getBoundName()
Obtains the name thisManagedObject
is bound under.java.util.logging.Logger
getLogger()
Obtains theLogger
for theManagedObject
.java.lang.Object
getObject(int index)
Obtains the dependencyObject
by its index.java.lang.Object
getObject(java.lang.Enum key)
Obtains the dependencyObject
for the dependency key.void
mapDependency(int index, java.lang.Object dependency)
Maps the dependency for theCoordinatingManagedObject
.void
mapDependency(java.lang.Enum<?> key, java.lang.Object dependency)
Maps the dependency for theCoordinatingManagedObject
.<R,T extends java.lang.Throwable>
Rrun(ProcessSafeOperation<R,T> operation)
Undertakes aProcessSafeOperation
.void
setAsynchronousListener(AsynchronousContext listener)
Allows overriding theAsynchronousContext
to initialise anAsynchronousManagedObject
.void
setBoundManagedObjectName(java.lang.String boundManagedObjectName)
Specifies the bound name for aContextAwareManagedObject
.void
setFailure(java.lang.Throwable cause)
Indicates failure to obtain theManagedObject
.void
setManagedObject(ManagedObject managedObject)
Specifies theManagedObject
to be used.void
setObjectRegistry(ObjectRegistry<?> objectRegistry)
Allows overriding theObjectRegistry
to initialise aCoordinatingManagedObject
.void
setSourceTimeout(long sourceTimeout)
Specifies the timeout to source theManagedObject
.ManagedObject
sourceManagedObject(ManagedObjectSource<?,?> source)
Sources theManagedObject
from theManagedObjectSource
.ManagedObject
sourceManagedObject(ManagedObjectSource<?,?> source, boolean isWait)
Sources theManagedObject
from theManagedObjectSource
.<T extends java.lang.Throwable>
voidstart(AsynchronousOperation<T> operation)
Undertakes anAsynchronousOperation
.
-
-
-
Method Detail
-
setSourceTimeout
public void setSourceTimeout(long sourceTimeout)
Specifies the timeout to source theManagedObject
.- Parameters:
sourceTimeout
- Timeout to source theManagedObject
.
-
setBoundManagedObjectName
public void setBoundManagedObjectName(java.lang.String boundManagedObjectName)
Specifies the bound name for aContextAwareManagedObject
.- Parameters:
boundManagedObjectName
- Bound name for aContextAwareManagedObject
.
-
setAsynchronousListener
public void setAsynchronousListener(AsynchronousContext listener)
Allows overriding theAsynchronousContext
to initialise anAsynchronousManagedObject
.- Parameters:
listener
-AsynchronousContext
.
-
setObjectRegistry
public void setObjectRegistry(ObjectRegistry<?> objectRegistry)
Allows overriding theObjectRegistry
to initialise aCoordinatingManagedObject
.- Parameters:
objectRegistry
-ObjectRegistry
.
-
mapDependency
public void mapDependency(int index, java.lang.Object dependency)
Maps the dependency for theCoordinatingManagedObject
.- Parameters:
index
- Index of the dependency.dependency
- Dependency.
-
mapDependency
public void mapDependency(java.lang.Enum<?> key, java.lang.Object dependency)
Maps the dependency for theCoordinatingManagedObject
.- Parameters:
key
- Key of the dependency.dependency
- Dependency.
-
sourceManagedObject
public ManagedObject sourceManagedObject(ManagedObjectSource<?,?> source) throws java.lang.Throwable
Sources theManagedObject
from theManagedObjectSource
.- Parameters:
source
-ManagedObjectSource
.- Returns:
ManagedObject
from theManagedObjectSource
.- Throws:
java.lang.Throwable
- If fails to source theManagedObject
.
-
sourceManagedObject
public ManagedObject sourceManagedObject(ManagedObjectSource<?,?> source, boolean isWait) throws java.lang.Throwable
Sources theManagedObject
from theManagedObjectSource
.- Parameters:
source
-ManagedObjectSource
.isWait
- Flags to wait forManagedObjectSource
to provide theManagedObject
.- Returns:
ManagedObject
from theManagedObjectSource
ornull
if not waiting and not sourced immediately.- Throws:
java.lang.Throwable
- If fails to source theManagedObject
.
-
setManagedObject
public void setManagedObject(ManagedObject managedObject)
Description copied from interface:ManagedObjectUser
Specifies the
ManagedObject
to be used.This will be called by the
ManagedObjectSource.sourceManagedObject(ManagedObjectUser)
method to provide theManagedObject
to thisManagedObjectUser
.- Specified by:
setManagedObject
in interfaceManagedObjectUser
- Parameters:
managedObject
-ManagedObject
to be used.
-
setFailure
public void setFailure(java.lang.Throwable cause)
Description copied from interface:ManagedObjectUser
Indicates failure to obtain theManagedObject
.- Specified by:
setFailure
in interfaceManagedObjectUser
- Parameters:
cause
- Cause of the failure.
-
getBoundName
public java.lang.String getBoundName()
Description copied from interface:ManagedObjectContext
Obtains the name this
ManagedObject
is bound under.This is useful to have a unique name identifying the
ManagedObject
.- Specified by:
getBoundName
in interfaceManagedObjectContext
- Returns:
- Name this
ManagedObject
is bound under.
-
getLogger
public java.util.logging.Logger getLogger()
Description copied from interface:ManagedObjectContext
Obtains theLogger
for theManagedObject
.- Specified by:
getLogger
in interfaceManagedObjectContext
- Returns:
Logger
for theManagedObject
.
-
run
public <R,T extends java.lang.Throwable> R run(ProcessSafeOperation<R,T> operation) throws T extends java.lang.Throwable
Description copied from interface:ManagedObjectContext
Undertakes aProcessSafeOperation
.- Specified by:
run
in interfaceManagedObjectContext
- Type Parameters:
R
- Return type from operationT
- PossibleThrowable
type from operation.- Parameters:
operation
-ProcessSafeOperation
.- Returns:
- Return value.
- Throws:
T
- PossibleThrowable
.T extends java.lang.Throwable
-
start
public <T extends java.lang.Throwable> void start(AsynchronousOperation<T> operation)
Description copied from interface:AsynchronousContext
Undertakes anAsynchronousOperation
.- Specified by:
start
in interfaceAsynchronousContext
- Type Parameters:
T
- Possible exception type fromAsynchronousOperation
.- Parameters:
operation
- Optional operation to be undertaken, once theAsynchronousManagedObject
is registered as started an asynchronous operation. May benull
.
-
complete
public <T extends java.lang.Throwable> void complete(AsynchronousOperation<T> operation)
Description copied from interface:AsynchronousContext
Indicates that theAsynchronousManagedObject
has completed and is ready for another operation.- Specified by:
complete
in interfaceAsynchronousContext
- Type Parameters:
T
- Possible exception type fromAsynchronousOperation
.- Parameters:
operation
- Optional operation to be undertaken, once theAsynchronousManagedObject
is unregistered from undertaking an asynchronous operation. May benull
.
-
getObject
public java.lang.Object getObject(java.lang.Enum key)
Description copied from interface:ObjectRegistry
Obtains the dependencyObject
for the dependency key.- Specified by:
getObject
in interfaceObjectRegistry
- Parameters:
key
- Key identifying the dependencyObject
.- Returns:
- Dependency
Object
for the key.
-
getObject
public java.lang.Object getObject(int index)
Description copied from interface:ObjectRegistry
Obtains the dependency
Object
by its index.This enables a dynamic number of dependencies for the
ManagedObject
.- Specified by:
getObject
in interfaceObjectRegistry
- Parameters:
index
- Index identifying the dependencyObject
.- Returns:
- Dependency
Object
for the index.
-
-