This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch pnoltes/feature/update_component_and_pattern_documentation in repository https://gitbox.apache.org/repos/asf/celix.git
commit f66acd6b03d01e0302776af3b4cfdb59a786d3b4 Author: Pepijn Noltes <[email protected]> AuthorDate: Tue May 17 18:02:22 2022 +0200 Updates component lifecycle state diagram --- documents/diagrams/bundles_lifecycle.png | Bin 35564 -> 25453 bytes documents/diagrams/bundles_lifecycle.puml | 3 +- documents/diagrams/component_lifecycle.png | Bin 49622 -> 61347 bytes documents/diagrams/component_lifecycle.puml | 4 +++ libs/framework/src/dm_component_impl.c | 48 +++++++++++++++------------- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/documents/diagrams/bundles_lifecycle.png b/documents/diagrams/bundles_lifecycle.png index cf621a40..679568a1 100644 Binary files a/documents/diagrams/bundles_lifecycle.png and b/documents/diagrams/bundles_lifecycle.png differ diff --git a/documents/diagrams/bundles_lifecycle.puml b/documents/diagrams/bundles_lifecycle.puml index f883386f..5ba61e8d 100644 --- a/documents/diagrams/bundles_lifecycle.puml +++ b/documents/diagrams/bundles_lifecycle.puml @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. @startuml +hide empty description [*] -> Installed Installed -down-> Resolved Resolved -down-> Uninstalled @@ -30,4 +31,4 @@ state BundleActivation { Resolved -right-> BundleActivation BundleActivation -> Resolved -@enduml \ No newline at end of file +@enduml diff --git a/documents/diagrams/component_lifecycle.png b/documents/diagrams/component_lifecycle.png index 5af09ca1..ffaa8bc1 100644 Binary files a/documents/diagrams/component_lifecycle.png and b/documents/diagrams/component_lifecycle.png differ diff --git a/documents/diagrams/component_lifecycle.puml b/documents/diagrams/component_lifecycle.puml index 19db2876..5d99ab97 100644 --- a/documents/diagrams/component_lifecycle.puml +++ b/documents/diagrams/component_lifecycle.puml @@ -44,9 +44,13 @@ Deinitializing -down-> Inactive Initializing: <i>Calling <b>init</b> callback</i> Starting: <i>Calling <b>start</b> callback</i> +Starting: <i>Register provided services async</i> +Stopping: <i>Unregister provided services</i> Stopping: <i>Calling <b>stop</b> callback</i> Deinitializing: <i>Calling <b>deinit</b> callback</i> +Suspending: <i>Unregister provided services</i> Suspending: <i>Calling <b>stop</b> callback</i> Resuming: <i>Calling <b>start</b> callback</i> +Resuming: <i>Register provided services async</i> @enduml diff --git a/libs/framework/src/dm_component_impl.c b/libs/framework/src/dm_component_impl.c index 6fa7d716..a951efc1 100644 --- a/libs/framework/src/dm_component_impl.c +++ b/libs/framework/src/dm_component_impl.c @@ -528,37 +528,39 @@ celix_status_t celix_private_dmComponent_handleEvent(celix_dm_component_t *compo static celix_status_t celix_dmComponent_suspend(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency) { celix_status_t status = CELIX_SUCCESS; - if (component->callbackStop != NULL) { - celixThreadMutex_lock(&component->mutex); + celixThreadMutex_lock(&component->mutex); + celix_dmComponent_logTransition(component, celix_dmComponent_currentState(component), + CELIX_DM_CMP_STATE_SUSPENDING); + celix_dmComponent_setCurrentState(component, CELIX_DM_CMP_STATE_SUSPENDING); + celix_dmComponent_unregisterServices(component, false); + if (component->callbackStop != NULL ) { + status = component->callbackStop(component->implementation); + } + if (status == CELIX_SUCCESS) { celix_dmComponent_logTransition(component, celix_dmComponent_currentState(component), - CELIX_DM_CMP_STATE_SUSPENDING); - celix_dmComponent_setCurrentState(component, CELIX_DM_CMP_STATE_SUSPENDING); - celix_dmComponent_unregisterServices(component, false); - status = component->callbackStop(component->implementation); - if (status == CELIX_SUCCESS) { - celix_dmComponent_logTransition(component, celix_dmComponent_currentState(component), - CELIX_DM_CMP_STATE_SUSPENDED); - celix_dmComponent_setCurrentState(component, CELIX_DM_CMP_STATE_SUSPENDED); - } else { - celix_bundleContext_log(component->context, CELIX_LOG_LEVEL_ERROR, - "Error stopping component %s (uuid=%s) using the stop callback. Disabling component.", - component->name, - component->uuid); - celix_dmComponent_disableDirectly(component); - } - celixThreadMutex_unlock(&component->mutex); - } + CELIX_DM_CMP_STATE_SUSPENDED); + celix_dmComponent_setCurrentState(component, CELIX_DM_CMP_STATE_SUSPENDED); + } else { + celix_bundleContext_log(component->context, CELIX_LOG_LEVEL_ERROR, + "Error stopping component %s (uuid=%s) using the stop callback. Disabling component.", + component->name, + component->uuid); + celix_dmComponent_disableDirectly(component); + } + celixThreadMutex_unlock(&component->mutex); return status; } static celix_status_t celix_dmComponent_resume(celix_dm_component_t *component, celix_dm_service_dependency_t *dependency) { celix_status_t status = CELIX_SUCCESS; - celixThreadMutex_lock(&component->mutex); - if (celix_dmComponent_currentState(component) == CELIX_DM_CMP_STATE_SUSPENDED) { + if (celix_dmComponent_currentState(component) == CELIX_DM_CMP_STATE_SUSPENDED) { + celixThreadMutex_lock(&component->mutex); celix_dmComponent_logTransition(component, celix_dmComponent_currentState(component), CELIX_DM_CMP_STATE_RESUMING); celix_dmComponent_setCurrentState(component, CELIX_DM_CMP_STATE_RESUMING); - status = component->callbackStart(component->implementation); + if (component->callbackStart != NULL) { + status = component->callbackStart(component->implementation); + } if (status == CELIX_SUCCESS) { celix_dmComponent_registerServices(component, false); component->nrOfTimesResumed += 1; @@ -574,8 +576,8 @@ static celix_status_t celix_dmComponent_resume(celix_dm_component_t *component, celix_dmComponent_disableDirectly(component); celixThreadMutex_unlock(&component->mutex); } + celixThreadMutex_unlock(&component->mutex); } - celixThreadMutex_unlock(&component->mutex); return status; }
