Component state - Accessors for driver-related information
This commit is contained in:
parent
7cfb53c60e
commit
97eb6477d7
1 changed files with 47 additions and 16 deletions
|
@ -60,7 +60,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* This constructor obtains the component itself (either directly or by calling the supplier from the registration
|
* This constructor obtains the component itself (either directly or by calling the supplier from the registration
|
||||||
* information), determines the component's name, and fetches autostart and lifecycle actions information.
|
* information), determines the component's name, and fetches autostart and lifecycle actions information.
|
||||||
*
|
*
|
||||||
* @param registry
|
* @param registry
|
||||||
* the registry generating this state record
|
* the registry generating this state record
|
||||||
* @param ci
|
* @param ci
|
||||||
|
@ -87,7 +87,7 @@ public final class ComponentState
|
||||||
this.component = component;
|
this.component = component;
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
ThrowingFunction< Object , String > np = (ThrowingFunction< Object , String >) ci.getNameProvider( );
|
final ThrowingFunction< Object , String > np = (ThrowingFunction< Object , String >) ci.getNameProvider( );
|
||||||
String name;
|
String name;
|
||||||
if ( np != null ) {
|
if ( np != null ) {
|
||||||
try {
|
try {
|
||||||
|
@ -117,7 +117,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* The description generated by this method includes the name of the component, if there is one, as well as its
|
* The description generated by this method includes the name of the component, if there is one, as well as its
|
||||||
* type.
|
* type.
|
||||||
*
|
*
|
||||||
* @return the component's description
|
* @return the component's description
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -172,7 +172,7 @@ public final class ComponentState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the state records for the component's dependencies to a collection
|
* Adds the state records for the component's dependencies to a collection
|
||||||
*
|
*
|
||||||
* @param output
|
* @param output
|
||||||
* the collection to add the records to
|
* the collection to add the records to
|
||||||
*/
|
*/
|
||||||
|
@ -193,7 +193,7 @@ public final class ComponentState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the state records for the component's reverse dependencies to a collection
|
* Adds the state records for the component's reverse dependencies to a collection
|
||||||
*
|
*
|
||||||
* @param output
|
* @param output
|
||||||
* the collection to add the records to
|
* the collection to add the records to
|
||||||
*/
|
*/
|
||||||
|
@ -203,6 +203,37 @@ public final class ComponentState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the component for which this component is a driver, or <code>null</code> if this component is not another
|
||||||
|
* component's driver
|
||||||
|
*/
|
||||||
|
public ComponentState getMainComponent( )
|
||||||
|
{
|
||||||
|
return this.mainComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an unmodifiable set listing this component's drivers
|
||||||
|
*/
|
||||||
|
public Set< ComponentState > getDrivers( )
|
||||||
|
{
|
||||||
|
return Collections.unmodifiableSet( this.drivers );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the state records for the component's drivers to a collection
|
||||||
|
*
|
||||||
|
* @param output
|
||||||
|
* the collection to add the records to
|
||||||
|
*/
|
||||||
|
public void getDrivers( final Collection< ComponentState > output )
|
||||||
|
{
|
||||||
|
output.addAll( this.drivers );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return <code>true</code> if the component was initialised, <code>false</code> if it wasn't (or if it was
|
* @return <code>true</code> if the component was initialised, <code>false</code> if it wasn't (or if it was
|
||||||
* destroyed)
|
* destroyed)
|
||||||
|
@ -231,7 +262,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* If these actions succeed, the component will be marked as active. Then, if the component has drivers, they will
|
* If these actions succeed, the component will be marked as active. Then, if the component has drivers, they will
|
||||||
* be started as well.
|
* be started as well.
|
||||||
*
|
*
|
||||||
* @throws ComponentStartupException
|
* @throws ComponentStartupException
|
||||||
* if an exception occurs while running the startup action for this component or for one of its
|
* if an exception occurs while running the startup action for this component or for one of its
|
||||||
* dependencies
|
* dependencies
|
||||||
|
@ -263,7 +294,7 @@ public final class ComponentState
|
||||||
* the configured shutdown action, if there is one. If both steps succeed, it will mark the component as inactive.
|
* the configured shutdown action, if there is one. If both steps succeed, it will mark the component as inactive.
|
||||||
* <p>
|
* <p>
|
||||||
* If the method is called on an inactive component, nothing will happen.
|
* If the method is called on an inactive component, nothing will happen.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
* @throws IllegalStateException
|
||||||
* if the registry has failed.
|
* if the registry has failed.
|
||||||
* @throws ComponentShutdownException
|
* @throws ComponentShutdownException
|
||||||
|
@ -299,7 +330,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* This method attempts to restart a component. It will stop the component and its reverse dependencies, then start
|
* This method attempts to restart a component. It will stop the component and its reverse dependencies, then start
|
||||||
* all components that were previously active.
|
* all components that were previously active.
|
||||||
*
|
*
|
||||||
* @throws IllegalStateException
|
* @throws IllegalStateException
|
||||||
* if the registry has failed
|
* if the registry has failed
|
||||||
* @throws ComponentShutdownException
|
* @throws ComponentShutdownException
|
||||||
|
@ -321,7 +352,7 @@ public final class ComponentState
|
||||||
* This method attempts to initialise a component. It makes sure that all of the component's dependencies have been
|
* This method attempts to initialise a component. It makes sure that all of the component's dependencies have been
|
||||||
* initialised, then executes the lifecycle action for the {@link LifecycleStage#INITIALISE INITIALISE} stage. Then,
|
* initialised, then executes the lifecycle action for the {@link LifecycleStage#INITIALISE INITIALISE} stage. Then,
|
||||||
* if the component has drivers, it initialises them.
|
* if the component has drivers, it initialises them.
|
||||||
*
|
*
|
||||||
* @throws ComponentInitialisationException
|
* @throws ComponentInitialisationException
|
||||||
* if an error occurs while executing an initialisation action
|
* if an error occurs while executing an initialisation action
|
||||||
*/
|
*/
|
||||||
|
@ -349,7 +380,7 @@ public final class ComponentState
|
||||||
* This method attempts to destroy a component. It makes sure that all of the component's reverse dependencies have
|
* This method attempts to destroy a component. It makes sure that all of the component's reverse dependencies have
|
||||||
* been destroyed (starting with "normal" reverse dependencies, then processing the drivers), then executes the
|
* been destroyed (starting with "normal" reverse dependencies, then processing the drivers), then executes the
|
||||||
* lifecycle action for the {@link LifecycleStage#DESTROY DESTROY} stage.
|
* lifecycle action for the {@link LifecycleStage#DESTROY DESTROY} stage.
|
||||||
*
|
*
|
||||||
* @throws ComponentDestructionException
|
* @throws ComponentDestructionException
|
||||||
* if an error occurs while executing a destruction action
|
* if an error occurs while executing a destruction action
|
||||||
* @throws IllegalStateException
|
* @throws IllegalStateException
|
||||||
|
@ -383,7 +414,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* This internal method (called by {@link ComponentRegistry}) adds a new dependency to the current record. It also
|
* This internal method (called by {@link ComponentRegistry}) adds a new dependency to the current record. It also
|
||||||
* updates the dependency's record, adding the current record as a reverse dependency.
|
* updates the dependency's record, adding the current record as a reverse dependency.
|
||||||
*
|
*
|
||||||
* @param dep
|
* @param dep
|
||||||
* the state record of the dependency to add
|
* the state record of the dependency to add
|
||||||
*/
|
*/
|
||||||
|
@ -399,7 +430,7 @@ public final class ComponentState
|
||||||
* Sets a component as the one this component is a driver for.
|
* Sets a component as the one this component is a driver for.
|
||||||
* <p>
|
* <p>
|
||||||
* This will also update the main component to add this component as a driver.
|
* This will also update the main component to add this component as a driver.
|
||||||
*
|
*
|
||||||
* @param main
|
* @param main
|
||||||
* the main component
|
* the main component
|
||||||
*/
|
*/
|
||||||
|
@ -417,7 +448,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* This method attempts to execute the lifecycle action for a specified lifecycle stage. If no action is configured,
|
* This method attempts to execute the lifecycle action for a specified lifecycle stage. If no action is configured,
|
||||||
* it does nothing.
|
* it does nothing.
|
||||||
*
|
*
|
||||||
* @param stage
|
* @param stage
|
||||||
* the lifecycle stage whose action must be executed
|
* the lifecycle stage whose action must be executed
|
||||||
* @throws ComponentLifecycleException
|
* @throws ComponentLifecycleException
|
||||||
|
@ -437,7 +468,7 @@ public final class ComponentState
|
||||||
} catch ( final FunctionException e ) {
|
} catch ( final FunctionException e ) {
|
||||||
throw e.getCause( );
|
throw e.getCause( );
|
||||||
}
|
}
|
||||||
} catch ( Throwable t ) {
|
} catch ( final Throwable t ) {
|
||||||
if ( t instanceof ComponentLifecycleException ) {
|
if ( t instanceof ComponentLifecycleException ) {
|
||||||
throw (ComponentLifecycleException) t;
|
throw (ComponentLifecycleException) t;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +492,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* This method implements the actions behind {@link #start()}, but it doesn't check if the record and registry are
|
* This method implements the actions behind {@link #start()}, but it doesn't check if the record and registry are
|
||||||
* in legal states.
|
* in legal states.
|
||||||
*
|
*
|
||||||
* @throws ComponentStartupException
|
* @throws ComponentStartupException
|
||||||
* if an exception occurs while running the startup action for this component or for one of its
|
* if an exception occurs while running the startup action for this component or for one of its
|
||||||
* dependencies
|
* dependencies
|
||||||
|
@ -493,7 +524,7 @@ public final class ComponentState
|
||||||
* <p>
|
* <p>
|
||||||
* Attempts to restart a component if it was active before {@link #restart()} was called. Calls the start action
|
* Attempts to restart a component if it was active before {@link #restart()} was called. Calls the start action
|
||||||
* first, then restart the drivers, then other reverse dependencies.
|
* first, then restart the drivers, then other reverse dependencies.
|
||||||
*
|
*
|
||||||
* @throws ComponentStartupException
|
* @throws ComponentStartupException
|
||||||
* if an exception occurs while running the startup action for this component or for one of its reverse
|
* if an exception occurs while running the startup action for this component or for one of its reverse
|
||||||
* dependencies
|
* dependencies
|
||||||
|
|
Loading…
Reference in a new issue