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 2009/08/11 15:55:19 UTC
svn commit: r803124 - in /sling/trunk/installer/osgi/installer/src:
main/java/org/apache/sling/osgi/installer/
main/java/org/apache/sling/osgi/installer/impl/
main/java/org/apache/sling/osgi/installer/impl/tasks/
test/java/org/apache/sling/osgi/install...
Author: bdelacretaz
Date: Tue Aug 11 13:55:18 2009
New Revision: 803124
URL: http://svn.apache.org/viewvc?rev=803124&view=rev
Log:
SLING-1078 - more code cleanup
Added:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReader.java
- copied, changed from r803108, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DictionaryReader.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReaderTest.java
- copied, changed from r803116, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryReaderTest.java
Removed:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DictionaryReader.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EventsCounter.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EventsCounterImpl.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryReaderTest.java
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Activator.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Storage.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
Added: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java?rev=803124&view=auto
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java (added)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java Tue Aug 11 13:55:18 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.osgi.installer;
+
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.log.LogService;
+
+/** Proxy for services that might not be always available, allows
+ * classes which are not OSGi services to access such services easily.
+ * Should normally be part of the implementation package, but it is
+ * used in tests to find out when the controller is ready.
+ */
+public interface OsgiControllerServices {
+ ConfigurationAdmin getConfigurationAdmin();
+ LogService getLogService();
+}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Activator.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Activator.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Activator.java Tue Aug 11 13:55:18 2009
@@ -24,14 +24,18 @@
import org.apache.sling.osgi.installer.OsgiControllerServices;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
-public class Activator implements BundleActivator {
+public class Activator implements BundleActivator, FrameworkListener, BundleListener {
private static String PACKAGE_ADMIN_NAME = PackageAdmin.class.getName();
private static String START_LEVEL_NAME = StartLevel.class.getName();
@@ -42,8 +46,8 @@
private ServiceTracker logServiceTracker;
private OsgiControllerImpl osgiControllerService;
private ServiceRegistration osgiControllerServiceReg;
- private EventsCounterImpl eventsCounter;
- private ServiceRegistration eventsCounterServiceReg;
+
+ private static long eventsCount;
/**
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
@@ -56,6 +60,10 @@
this.packageAdminTracker.open();
this.logServiceTracker.open();
+ // listen to framework and bundle events
+ context.addFrameworkListener(this);
+ context.addBundleListener(this);
+
// register OsgiController service
{
final Hashtable<String, String> props = new Hashtable<String, String>();
@@ -79,12 +87,6 @@
final Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling EventsCounter Service");
props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
-
- this.eventsCounter = new EventsCounterImpl(context);
- final String [] serviceInterfaces = {
- EventsCounter.class.getName()
- };
- eventsCounterServiceReg = context.registerService(serviceInterfaces, eventsCounter, props);
}
}
@@ -100,14 +102,9 @@
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- if( this.eventsCounterServiceReg != null) {
- this.eventsCounterServiceReg.unregister();
- this.eventsCounterServiceReg = null;
- }
- if( this.eventsCounter != null) {
- this.eventsCounter.deactivate();
- this.eventsCounter = null;
- }
+ context.removeBundleListener(this);
+ context.removeFrameworkListener(this);
+
if ( this.osgiControllerServiceReg != null ) {
this.osgiControllerServiceReg.unregister();
this.osgiControllerServiceReg = null;
@@ -129,4 +126,18 @@
this.logServiceTracker = null;
}
}
+
+ public static long getTotalEventsCount() {
+ return eventsCount;
+ }
+
+ public void frameworkEvent(FrameworkEvent arg0) {
+ // we'll retry as soon as any FrameworkEvent or BundleEvent happens
+ eventsCount++;
+ }
+
+ public void bundleChanged(BundleEvent arg0) {
+ // we'll retry as soon as any FrameworkEvent or BundleEvent happens
+ eventsCount++;
+ }
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Storage.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Storage.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Storage.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/Storage.java Tue Aug 11 13:55:18 2009
@@ -39,7 +39,6 @@
public class Storage {
private final File dataFile;
private final Map<String, Map<String, Object>> data;
- private final OsgiControllerServices ocs;
/** {@link Storage} key for the bundle ID */
public static final String KEY_BUNDLE_ID = "bundle.id";
@@ -49,7 +48,6 @@
@SuppressWarnings("unchecked")
Storage(File dataFile, OsgiControllerServices ocs) throws IOException {
this.dataFile = dataFile;
- this.ocs = ocs;
ObjectInputStream ois = null;
Map<String, Map<String, Object>> loadedData = null;
Throwable loadException = null;
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java Tue Aug 11 13:55:18 2009
@@ -20,13 +20,11 @@
import java.text.DecimalFormat;
-import org.apache.sling.osgi.installer.impl.EventsCounter;
+import org.apache.sling.osgi.installer.impl.Activator;
import org.apache.sling.osgi.installer.impl.OsgiControllerTask;
import org.apache.sling.osgi.installer.impl.OsgiControllerTaskContext;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
/** Task that starts a bundle */
@@ -94,9 +92,9 @@
// that warrants a retry), but for the next ones wait for at least one bundle
// event or framework event
if(retryCount == 0) {
- eventsCountForRetrying = getEventsCount(tctx.getBundleContext());
+ eventsCountForRetrying = Activator.getTotalEventsCount();
} else {
- eventsCountForRetrying = getEventsCount(tctx.getBundleContext()) + 1;
+ eventsCountForRetrying = Activator.getTotalEventsCount() + 1;
}
tctx.addTaskToNextCycle(this);
@@ -107,7 +105,7 @@
/** Do not execute this task if waiting for events */
public boolean isExecutable(OsgiControllerTaskContext tctx) {
- final long eventsCount = getEventsCount(tctx.getBundleContext());
+ final long eventsCount = Activator.getTotalEventsCount();
final boolean result = eventsCount >= eventsCountForRetrying;
if(!result) {
if(tctx.getOsgiControllerServices().getLogService() != null) {
@@ -117,17 +115,4 @@
}
return result;
}
-
- /** Return current events count */
- protected long getEventsCount(BundleContext bc) {
- final ServiceReference sr = bc.getServiceReference(EventsCounter.class.getName());
- if(sr == null) {
- throw new IllegalStateException("EventsCounter service not found");
- }
- final EventsCounter ec = (EventsCounter)bc.getService(sr);
- if(ec == null) {
- throw new IllegalStateException("EventsCounter service not found, although its ServiceReference was found");
- }
- return ec.getTotalEventsCount();
- }
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java Tue Aug 11 13:55:18 2009
@@ -25,7 +25,6 @@
import org.apache.sling.osgi.installer.InstallableData;
import org.apache.sling.osgi.installer.OsgiControllerServices;
-import org.apache.sling.osgi.installer.impl.DictionaryReader;
import org.apache.sling.osgi.installer.impl.OsgiControllerTaskContext;
import org.osgi.service.cm.Configuration;
import org.osgi.service.log.LogService;
Copied: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReader.java (from r803108, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DictionaryReader.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReader.java?p2=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReader.java&p1=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DictionaryReader.java&r1=803108&r2=803124&rev=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/DictionaryReader.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReader.java Tue Aug 11 13:55:18 2009
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.osgi.installer.impl;
+package org.apache.sling.osgi.installer.impl.tasks;
import java.io.IOException;
import java.io.InputStream;
@@ -34,7 +34,7 @@
* syntax of the Properties class, enhanced to support
* multivalued properties and types supported by the PropertyConverter
*/
-public class DictionaryReader {
+class DictionaryReader {
private final PropertyConverter converter = new PropertyConverter();
/** Read Dictionary from the given InputStream,
Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/StorageTest.java Tue Aug 11 13:55:18 2009
@@ -18,6 +18,11 @@
*/
package org.apache.sling.osgi.installer.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.util.Map;
@@ -25,8 +30,6 @@
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.log.LogService;
-import static org.junit.Assert.*;
-
/** Test the Storage class */
public class StorageTest {
Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java?rev=803124&r1=803123&r2=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java Tue Aug 11 13:55:18 2009
@@ -19,7 +19,7 @@
package org.apache.sling.osgi.installer.impl;
import static org.junit.Assert.fail;
-import static org.junit.Assert.assertTrue;
+
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
Copied: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReaderTest.java (from r803116, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryReaderTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReaderTest.java?p2=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReaderTest.java&p1=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryReaderTest.java&r1=803116&r2=803124&rev=803124&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryReaderTest.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/DictionaryReaderTest.java Tue Aug 11 13:55:18 2009
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.osgi.installer.impl;
+package org.apache.sling.osgi.installer.impl.tasks;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;