You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2022/08/11 23:55:04 UTC
[brooklyn-server] 05/09: add created and destroying lifecycle hooks
This is an automated email from the ASF dual-hosted git repository.
heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit bb1e5ac48a6ede94021ed13e8b54a9ed9c8394c8
Author: Alex Heneveld <al...@cloudsoft.io>
AuthorDate: Thu Aug 11 14:33:33 2022 +0100
add created and destroying lifecycle hooks
---
.../brooklyn/core/entity/AbstractEntity.java | 29 +++++++++++++++++++++-
.../mgmt/internal/EntityManagementSupport.java | 9 ++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
index c047ee6ecb..30a96f1ec2 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractEntity.java
@@ -1767,7 +1767,19 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
if (displayNameAutoGenerated) displayName.set(getAutogeneratedDefaultDisplayName());
}
}
-
+
+ /**
+ * Invoked by {@link EntityManagementSupport} when this entity is first created and almost fully managed,
+ * visible to other entities through the management context, for the very first time.
+ * It will be followed by a call to {@link #onManagementStarted()},
+ * but will not be called on subsequent rebindings.
+ *
+ * This is called by {@link org.apache.brooklyn.core.mgmt.internal.LocalEntityManager#createEntity(Map, Class)}
+ * just after its call to {@link org.apache.brooklyn.core.objs.proxy.InternalEntityFactory#createEntity(EntitySpec, String)}
+ * and immediately before the call to {@link #onManagementStarted()}.
+ */
+ public void onManagementCreated() {}
+
/**
* Invoked by {@link EntityManagementSupport} when this entity is fully managed and visible to other entities
* through the management context.
@@ -1790,6 +1802,21 @@ public abstract class AbstractEntity extends AbstractBrooklynObject implements E
@Deprecated
public void onManagementNoLongerMaster() {}
+ /**
+ * Invoked by {@link EntityManagementSupport} when this entity is being unmanaged.
+ * This may be because this entity is being removed, or because management is stopping.
+ * If this entity is being removed, there will be a subsequent call to {@link #onManagementDestroying()}
+ */
+ public void onManagementStopping() {
+ }
+
+ /**
+ * Invoked by {@link EntityManagementSupport} when this entity is being permanently removed from management.
+ * This call is synchronous and still has access to submit and block on tasks, so can be used for cleanup.
+ */
+ public void onManagementDestroying() {
+ }
+
/**
* Invoked by {@link EntityManagementSupport} when this entity is fully unmanaged.
* <p>
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
index 4ffa12699a..7e71a9cc57 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/EntityManagementSupport.java
@@ -273,6 +273,7 @@ public class EntityManagementSupport {
if (!isReadOnly()) {
entity.onManagementBecomingMaster();
+ if (info.getMode().isCreating()) entity.onManagementCreated();
entity.onManagementStarted();
}
@@ -340,8 +341,14 @@ public class EntityManagementSupport {
nonDeploymentManagementContext.setMode(NonDeploymentManagementContextMode.MANAGEMENT_STOPPING);
}
}
-
+
+ if (!wasDryRun && !isReadOnly()) {
+ entity.onManagementStopping();
+ if (info.getMode().isDestroying()) entity.onManagementDestroying();
+ }
+
if (wasDryRun || (!isReadOnly() && info.getMode().isDestroying())) {
+
// ensure adjuncts get a destroy callback
// note they don't get any alert if the entity is being locally unmanaged to run somewhere else.
// framework should introduce a call for that ideally, but in interim if needed they