From 97eb6477d7967146f788a0247a75048202281dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 17 Sep 2015 22:41:52 +0200 Subject: [PATCH] Component state - Accessors for driver-related information --- .../info/ebenoit/ebul/cmp/ComponentState.java | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main/java/info/ebenoit/ebul/cmp/ComponentState.java b/src/main/java/info/ebenoit/ebul/cmp/ComponentState.java index 1689b91..a124dad 100644 --- a/src/main/java/info/ebenoit/ebul/cmp/ComponentState.java +++ b/src/main/java/info/ebenoit/ebul/cmp/ComponentState.java @@ -60,7 +60,7 @@ public final class ComponentState *

* 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 *

* 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 null 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 true if the component was initialised, false if it wasn't (or if it was * destroyed) @@ -231,7 +262,7 @@ public final class ComponentState *

* 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. *

* 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 *

* 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 *

* 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. *

* 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 *

* 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 *

* 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 *

* 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