You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2020/09/04 13:29:19 UTC

[sling-whiteboard] 03/04: Add an instance-stopper module

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch feature/new-modules
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit 0f8a7cae79e91e456638f3cd5ad5bbcdeb49acdc
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Fri Sep 4 15:28:31 2020 +0200

    Add an instance-stopper module
---
 instance-stopper/README.md                         | 14 ++++++
 instance-stopper/pom.xml                           | 58 ++++++++++++++++++++++
 .../sling/is/impl/SystemReadyInstanceStopper.java  | 46 +++++++++++++++++
 3 files changed, 118 insertions(+)

diff --git a/instance-stopper/README.md b/instance-stopper/README.md
new file mode 100644
index 0000000..33f5e52
--- /dev/null
+++ b/instance-stopper/README.md
@@ -0,0 +1,14 @@
+[<img src="https://sling.apache.org/res/logos/sling.png"/>](https://sling.apache.org)
+
+# Apache Sling Instance Stopper
+
+This module is part of the [Apache Sling](https://sling.apache.org) project.
+
+The instance stopper allows an instance to the shut down as soon as it is considered ready.
+The main scenario is part of the tooling for setting up a [CompositeNodeStore](https://jackrabbit.apache.org/oak/docs/nodestore/compositens.html).
+
+The readiness check is delegated to the [Felix HealthChecks](https://github.com/apache/felix-dev/tree/master/healthcheck).
+
+## Usage
+
+Include the bundle in your deployment.
diff --git a/instance-stopper/pom.xml b/instance-stopper/pom.xml
new file mode 100644
index 0000000..1907c03
--- /dev/null
+++ b/instance-stopper/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+    license agreements. See the NOTICE file distributed with this work for additional 
+    information regarding copyright ownership. The ASF licenses this file to 
+    you under the Apache License, Version 2.0 (the "License"); you may not use 
+    this file except in compliance with the License. You may obtain a copy of 
+    the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+    by applicable law or agreed to in writing, software distributed under the 
+    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+    OF ANY KIND, either express or implied. See the License for the specific 
+    language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling-bundle-parent</artifactId>
+        <version>39</version>
+        <relativePath />
+    </parent>
+    <artifactId>org.apache.sling.instance-stopper</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Apache Sling Instance Stopper</name>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-baseline-maven-plugin</artifactId>
+                <configuration>
+                    <failOnMissing>false</failOnMissing>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.cmpn</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.healthcheck.api</artifactId>
+            <version>2.0.4</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java b/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java
new file mode 100644
index 0000000..e4adae5
--- /dev/null
+++ b/instance-stopper/src/main/java/org/apache/sling/is/impl/SystemReadyInstanceStopper.java
@@ -0,0 +1,46 @@
+/*-
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.is.impl;
+
+import org.apache.felix.hc.api.condition.SystemReady;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+/**
+ * Component that shuts down the system as soon as it is ready
+ *
+ */
+@Component
+public class SystemReadyInstanceStopper {
+    
+    @Reference
+    private SystemReady systemReady;
+    
+    public void activate(BundleContext ctx) throws BundleException {
+        
+        ctx.getBundle(Constants.SYSTEM_BUNDLE_ID)
+            .adapt(Framework.class)
+            .stop();
+    }
+    
+}