Added cubby-holes for new projects.
diff --git a/utils/osgi/pom.xml b/utils/osgi/pom.xml
new file mode 100644
index 0000000..ccf3385
--- /dev/null
+++ b/utils/osgi/pom.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.onlab.onos</groupId>
+ <artifactId>onos-utils</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-utils-osgi</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>OSGI utilities</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
new file mode 100644
index 0000000..b53b5fa
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/DefaultServiceDirectory.java
@@ -0,0 +1,19 @@
+package org.onlab.osgi;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * Default implementation of the service directory using OSGi framework utilities.
+ */
+public class DefaultServiceDirectory implements ServiceDirectory {
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
+ T impl = bc.getService(bc.getServiceReference(serviceClass));
+ if (impl == null) {
+ throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
+ }
+ return impl;
+ }
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java
new file mode 100644
index 0000000..ee33fa2
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/ServiceDirectory.java
@@ -0,0 +1,18 @@
+package org.onlab.osgi;
+
+/**
+ * Simple abstraction of a service directory where service implementations can
+ * be found by the class name of the interfaces they provide.
+ */
+public interface ServiceDirectory {
+
+ /**
+ * Returns implementation of the specified service class.
+ * @param serviceClass service class
+ * @param <T> type of service
+ * @return implementation class
+ * @throws ServiceNotFoundException if no implementation found
+ */
+ <T> T get(Class<T> serviceClass);
+
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java b/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java
new file mode 100644
index 0000000..4a79622
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/ServiceNotFoundException.java
@@ -0,0 +1,31 @@
+package org.onlab.osgi;
+
+/**
+ * Represents condition where some service is not found or not available.
+ */
+public class ServiceNotFoundException extends RuntimeException {
+
+ /**
+ * Creates a new exception with no message.
+ */
+ public ServiceNotFoundException() {
+ }
+
+ /**
+ * Creates a new exception with the supplied message.
+ * @param message error message
+ */
+ public ServiceNotFoundException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new exception with the supplied message and cause.
+ * @param message error message
+ * @param cause cause of the error
+ */
+ public ServiceNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java b/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java
new file mode 100644
index 0000000..2915d4b
--- /dev/null
+++ b/utils/osgi/src/main/java/org/onlab/osgi/TestServiceDirectory.java
@@ -0,0 +1,30 @@
+package org.onlab.osgi;
+
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.MutableClassToInstanceMap;
+
+/**
+ * Service directory implementation suitable for testing.
+ */
+public class TestServiceDirectory implements ServiceDirectory {
+
+ private ClassToInstanceMap<Object> services = MutableClassToInstanceMap.create();
+
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ return services.getInstance(serviceClass);
+ }
+
+ /**
+ * Adds a new service to the directory.
+ *
+ * @param serviceClass service class
+ * @param service service instance
+ * @return self
+ */
+ public TestServiceDirectory add(Class serviceClass, Object service) {
+ services.putInstance(serviceClass, service);
+ return this;
+ }
+
+}
diff --git a/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html b/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html
new file mode 100644
index 0000000..b833050
--- /dev/null
+++ b/utils/osgi/src/main/javadoc/org/onlab/osgi/package.html
@@ -0,0 +1,3 @@
+<body>
+Facilities for building testable components in OSGi independent fashion.
+</body>
\ No newline at end of file