Author: matthijsh
Date: Tue Jan 31 11:53:16 2012
New Revision: 2034

Log:
AMDATU-264 Deprecate and purge generic utilities library

Added:
   trunk/amdatu-libraries/osgisupport/
   trunk/amdatu-libraries/osgisupport/pom.xml
   trunk/amdatu-libraries/osgisupport/src/
   trunk/amdatu-libraries/osgisupport/src/main/
   trunk/amdatu-libraries/osgisupport/src/main/java/
   trunk/amdatu-libraries/osgisupport/src/main/java/org/
   trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/
   trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/libraries/
   trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/libraries/osgi/
   
trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/libraries/osgi/ServiceDependentActivator.java
Modified:
   trunk/amdatu-libraries/pom.xml
   trunk/amdatu-libraries/utilities/

Added: trunk/amdatu-libraries/osgisupport/pom.xml
==============================================================================
--- (empty file)
+++ trunk/amdatu-libraries/osgisupport/pom.xml  Tue Jan 31 11:53:16 2012
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright (c) 2010, 2011 The Amdatu Foundation
+
+  Licensed 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.verning 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.amdatu.libraries</groupId>
+    <artifactId>org.amdatu.libraries</artifactId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>org.amdatu.libraries.osgi</artifactId>
+  <packaging>jar</packaging>
+  <name>Amdatu Libraries - OSGI support</name>
+  <description>Contains the supporting class 
ServiceDependentActivator</description>
+</project>

Added: 
trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/libraries/osgi/ServiceDependentActivator.java
==============================================================================
--- (empty file)
+++ 
trunk/amdatu-libraries/osgisupport/src/main/java/org/amdatu/libraries/osgi/ServiceDependentActivator.java
   Tue Jan 31 11:53:16 2012
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010, 2011 The Amdatu Foundation
+ * 
+ * Licensed 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.amdatu.libraries.osgi;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Helper class to create an activator that needs other services to be 'up' 
before the rest
+ * of the activator is executed.
+ * The most prominent use case for this activator is the use of 'marker' 
interface that state
+ * the availability of some non-OSGi service.
+ */
+public abstract class ServiceDependentActivator extends 
DependencyActivatorBase {
+    @Override
+    public final void init(BundleContext context, DependencyManager manager) 
throws Exception {
+        Object watcher = new SpiWatcher();
+
+        Component spiWatcherComponent = 
createComponent().setImplementation(watcher);
+        for (Class<?> spiService : getRequiredServices()) {
+            
spiWatcherComponent.add(createServiceDependency().setService(spiService).setRequired(true));
+        }
+
+        manager.add(spiWatcherComponent);
+    }
+
+    /**
+     * Gets an array of all services that should be 'up' before the rest of 
activator is started.
+     * Once the rest of the activator is started, you will not have access to 
these services by default.
+     */
+    protected abstract Class<?>[] getRequiredServices();
+
+    public abstract void initWithDependencies(BundleContext context, 
DependencyManager manager) throws Exception;
+
+   private class SpiWatcher {
+        private volatile DependencyManager m_dependencyManager;
+        private volatile BundleContext m_bundleContext;
+        private AtomicBoolean m_started = new AtomicBoolean(false);
+
+        @SuppressWarnings("unused")
+        public void start() throws Exception {
+            if (m_started.compareAndSet(false, true)) {
+                initWithDependencies(m_bundleContext, m_dependencyManager);
+            }
+        }
+    }
+}

Modified: trunk/amdatu-libraries/pom.xml
==============================================================================
--- trunk/amdatu-libraries/pom.xml      (original)
+++ trunk/amdatu-libraries/pom.xml      Tue Jan 31 11:53:16 2012
@@ -40,7 +40,7 @@
   </repositories>
 
   <modules>
-    <module>utilities</module>
+    <module>osgisupport</module>
     <module>fsstorage</module>
     <module>warsupport</module>
   </modules>
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to