You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/07/08 17:49:37 UTC
svn commit: r1689905 - in /sling/whiteboard/bdelacretaz/startup-stuff:
it-startup/ it-startup/src/test/java/org/apache/sling/launchpad/it/startup/
startup-sequencer/
startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/
startup-sequencer/...
Author: bdelacretaz
Date: Wed Jul 8 15:49:37 2015
New Revision: 1689905
URL: http://svn.apache.org/r1689905
Log:
SLING-4851 - add the StartLevelController (just a stub for now)
Added:
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelChangeBarrier.java
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/Activator.java
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/StartLevelControllerImpl.java
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/package-info.java
Modified:
sling/whiteboard/bdelacretaz/startup-stuff/it-startup/pom.xml
sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/IncrementalStartupIT.java
sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/P.java
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/pom.xml
sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelController.java
Modified: sling/whiteboard/bdelacretaz/startup-stuff/it-startup/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/it-startup/pom.xml?rev=1689905&r1=1689904&r2=1689905&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/it-startup/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/startup-stuff/it-startup/pom.xml Wed Jul 8 15:49:37 2015
@@ -183,5 +183,12 @@
<version>4.0.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.startup.sequencer</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/IncrementalStartupIT.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/IncrementalStartupIT.java?rev=1689905&r1=1689904&r2=1689905&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/IncrementalStartupIT.java (original)
+++ sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/IncrementalStartupIT.java Wed Jul 8 15:49:37 2015
@@ -25,6 +25,7 @@ import java.util.Map;
import javax.inject.Inject;
import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.startup.sequencer.StartLevelController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -48,6 +49,9 @@ public class IncrementalStartupIT {
protected BundleContext bundleContext;
@Inject
+ private StartLevelController startLevelController;
+
+ @Inject
private StartLevel startLevel;
@Inject
@@ -61,9 +65,10 @@ public class IncrementalStartupIT {
/** TODO this should be driven by the start level sequencer */
private void setStartLevel(final int to) {
log.info("Changing start level to {}", to);
- startLevel.setStartLevel(to);
+ startLevelController.setStartLevel(to);
WaitFor.randomWait(P.MAX_WAIT_BETWEEN_LEVELS);
-
+
+ // TODO shouldn't be needed once controller syncs with its clients
new WaitFor(DEFAULT_TIMEOUT) {
protected boolean condition() {
setInfo("Expecting start level to reach " + to);
Modified: sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/P.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/P.java?rev=1689905&r1=1689904&r2=1689905&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/P.java (original)
+++ sling/whiteboard/bdelacretaz/startup-stuff/it-startup/src/test/java/org/apache/sling/launchpad/it/startup/P.java Wed Jul 8 15:49:37 2015
@@ -45,6 +45,7 @@ public class P {
mavenBundle("org.apache.sling","org.apache.sling.installer.core").versionAsInProject(),
mavenBundle("org.slf4j","slf4j-api").versionAsInProject(),
mavenBundle("org.apache.sling","org.apache.sling.commons.log").versionAsInProject(),
+ mavenBundle("org.apache.sling","org.apache.sling.startup.sequencer").versionAsInProject(),
wrappedBundle(mavenBundle("org.apache.sling","org.apache.sling.commons.testing").versionAsInProject())
).getOptions();
}
Modified: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/pom.xml?rev=1689905&r1=1689904&r2=1689905&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/pom.xml Wed Jul 8 15:49:37 2015
@@ -41,6 +41,11 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Activator>org.apache.sling.startup.sequencer.impl.Activator</Bundle-Activator>
+ </instructions>
+ </configuration>
</plugin>
</plugins>
</build>
@@ -58,5 +63,9 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
</dependencies>
</project>
Added: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelChangeBarrier.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelChangeBarrier.java?rev=1689905&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelChangeBarrier.java (added)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelChangeBarrier.java Wed Jul 8 15:49:37 2015
@@ -0,0 +1,40 @@
+/*
+ * 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.startup.sequencer;
+
+import java.util.concurrent.CountDownLatch;
+
+/** The {@link StartLevelController} uses this to optionally
+ * wait after increasing the OSGi start level.
+ */
+public interface StartLevelChangeBarrier {
+
+ /** Optionally return a latch that must have
+ * a zero value before the start level change
+ * is considered complete. Called by the {@link StartLevelController}
+ * right after increasing the start level.
+ *
+ * @param startLevel the start level that was just switched to
+ * @return a latch or null if none is needed for this level
+ */
+ CountDownLatch getStartLevelLatch(int startLevel);
+
+ /** The textual description of this barrier */
+ String getDescription();
+}
Modified: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelController.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelController.java?rev=1689905&r1=1689904&r2=1689905&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelController.java (original)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/StartLevelController.java Wed Jul 8 15:49:37 2015
@@ -1,4 +1,31 @@
+/*
+ * 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.startup.sequencer;
-public class StartLevelController {
+/** Switch between OSGi start levels in a way that respects the constraints
+ * supplied by {@link StartLevelChangeBarrier} services - those can supply
+ * waiting conditions to avoid raising start levels faster than they'd like.
+ */
+public interface StartLevelController {
+ /** Change the OSGi start level to the supplied value, sequentially, taking
+ * into account the any active {@link StartLevelChangeBarrier} services when
+ * raising start levels.
+ */
+ void setStartLevel(int targetLevel);
}
Added: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/Activator.java?rev=1689905&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/Activator.java (added)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/Activator.java Wed Jul 8 15:49:37 2015
@@ -0,0 +1,40 @@
+/*
+ * 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.startup.sequencer.impl;
+
+import org.apache.sling.startup.sequencer.StartLevelController;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+
+ private ServiceRegistration reg;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ final StartLevelController c = new StartLevelControllerImpl(context);
+ reg = context.registerService(StartLevelController.class.getName(), c, null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ reg.unregister();
+ }
+}
Added: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/StartLevelControllerImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/StartLevelControllerImpl.java?rev=1689905&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/StartLevelControllerImpl.java (added)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/impl/StartLevelControllerImpl.java Wed Jul 8 15:49:37 2015
@@ -0,0 +1,55 @@
+/*
+ * 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.startup.sequencer.impl;
+
+import org.apache.sling.startup.sequencer.StartLevelController;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.startlevel.StartLevel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Switch between OSGi start levels in a way that respects the constraints
+ * supplied by {@link StartLevelChangeBarrier} services - those can supply
+ * waiting conditions to avoid raising start levels faster than they'd like.
+ */
+public class StartLevelControllerImpl implements StartLevelController {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private final BundleContext bundleContext;
+
+ public StartLevelControllerImpl(BundleContext ctx) {
+ this.bundleContext = ctx;
+ }
+
+ public void setStartLevel(int targetLevel) {
+ final ServiceReference ref = bundleContext.getServiceReference(StartLevel.class.getName());
+ if(ref == null) {
+ throw new IllegalStateException("StartLevel service not found");
+ }
+ final StartLevel sl = (StartLevel)bundleContext.getService(ref);
+
+ try {
+ // TODO increment levels one by one and wait at each step
+ log.info("Setting start level to {}", targetLevel);
+ sl.setStartLevel(targetLevel);
+ } finally {
+ bundleContext.ungetService(ref);
+ }
+ }
+}
Added: sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/package-info.java?rev=1689905&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/package-info.java (added)
+++ sling/whiteboard/bdelacretaz/startup-stuff/startup-sequencer/src/main/java/org/apache/sling/startup/sequencer/package-info.java Wed Jul 8 15:49:37 2015
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+@Version("1.0.0")
+package org.apache.sling.startup.sequencer;
+
+import aQute.bnd.annotation.Version;
\ No newline at end of file