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>
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* @param registry
|
||||
* the registry generating this state record
|
||||
* @param ci
|
||||
|
@ -87,7 +87,7 @@ public final class ComponentState
|
|||
this.component = component;
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
ThrowingFunction< Object , String > np = (ThrowingFunction< Object , String >) ci.getNameProvider( );
|
||||
final ThrowingFunction< Object , String > np = (ThrowingFunction< Object , String >) ci.getNameProvider( );
|
||||
String name;
|
||||
if ( np != null ) {
|
||||
try {
|
||||
|
@ -117,7 +117,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* The description generated by this method includes the name of the component, if there is one, as well as its
|
||||
* type.
|
||||
*
|
||||
*
|
||||
* @return the component's description
|
||||
*/
|
||||
@Override
|
||||
|
@ -172,7 +172,7 @@ public final class ComponentState
|
|||
|
||||
/**
|
||||
* Adds the state records for the component's dependencies to a collection
|
||||
*
|
||||
*
|
||||
* @param output
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* @param output
|
||||
* 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
|
||||
* destroyed)
|
||||
|
@ -231,7 +262,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* If these actions succeed, the component will be marked as active. Then, if the component has drivers, they will
|
||||
* be started as well.
|
||||
*
|
||||
*
|
||||
* @throws ComponentStartupException
|
||||
* if an exception occurs while running the startup action for this component or for one of its
|
||||
* 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.
|
||||
* <p>
|
||||
* If the method is called on an inactive component, nothing will happen.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if the registry has failed.
|
||||
* @throws ComponentShutdownException
|
||||
|
@ -299,7 +330,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* This method attempts to restart a component. It will stop the component and its reverse dependencies, then start
|
||||
* all components that were previously active.
|
||||
*
|
||||
*
|
||||
* @throws IllegalStateException
|
||||
* if the registry has failed
|
||||
* @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
|
||||
* initialised, then executes the lifecycle action for the {@link LifecycleStage#INITIALISE INITIALISE} stage. Then,
|
||||
* if the component has drivers, it initialises them.
|
||||
*
|
||||
*
|
||||
* @throws ComponentInitialisationException
|
||||
* 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
|
||||
* been destroyed (starting with "normal" reverse dependencies, then processing the drivers), then executes the
|
||||
* lifecycle action for the {@link LifecycleStage#DESTROY DESTROY} stage.
|
||||
*
|
||||
*
|
||||
* @throws ComponentDestructionException
|
||||
* if an error occurs while executing a destruction action
|
||||
* @throws IllegalStateException
|
||||
|
@ -383,7 +414,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* @param dep
|
||||
* 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.
|
||||
* <p>
|
||||
* This will also update the main component to add this component as a driver.
|
||||
*
|
||||
*
|
||||
* @param main
|
||||
* the main component
|
||||
*/
|
||||
|
@ -417,7 +448,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* This method attempts to execute the lifecycle action for a specified lifecycle stage. If no action is configured,
|
||||
* it does nothing.
|
||||
*
|
||||
*
|
||||
* @param stage
|
||||
* the lifecycle stage whose action must be executed
|
||||
* @throws ComponentLifecycleException
|
||||
|
@ -437,7 +468,7 @@ public final class ComponentState
|
|||
} catch ( final FunctionException e ) {
|
||||
throw e.getCause( );
|
||||
}
|
||||
} catch ( Throwable t ) {
|
||||
} catch ( final Throwable t ) {
|
||||
if ( t instanceof ComponentLifecycleException ) {
|
||||
throw (ComponentLifecycleException) t;
|
||||
}
|
||||
|
@ -461,7 +492,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* This method implements the actions behind {@link #start()}, but it doesn't check if the record and registry are
|
||||
* in legal states.
|
||||
*
|
||||
*
|
||||
* @throws ComponentStartupException
|
||||
* if an exception occurs while running the startup action for this component or for one of its
|
||||
* dependencies
|
||||
|
@ -493,7 +524,7 @@ public final class ComponentState
|
|||
* <p>
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* @throws ComponentStartupException
|
||||
* if an exception occurs while running the startup action for this component or for one of its reverse
|
||||
* dependencies
|
||||
|
|
Loading…
Reference in a new issue