Commits

Charles Miller [Atlassian] (closed) committed bc98e06

Initial commit

Comments (0)

Files changed (24)

+=== Demo Script for OSGi Presentation
+
+    Talk-Keynote.zip -- Keynote version of the presentation file
+    demoscript.txt -- runthrough of the demo sections of the preso
+    osgiplay/ -- run sbt console in here
+    everything-else/ -- source for demo plugins. Copy build jars into osgiplay/jars if you change anything
+
+=== How to give the preso
+
+The general shape of the presentation is:
+
+1. Give a command-line demo of an aspect of OSGi functionality
+2. Explain in slides what was going on during the demo, and why
+3. GOTO 1.
+

Talk-Keynote.zip

Binary file added.
+Script 1:
+=========
+
+import scala.collection.JavaConversions._
+import org.osgi.framework._
+
+val felix = new org.apache.felix.framework.Felix(new java.util.HashMap())
+
+felix.isInstanceOf[launch.Framework]
+felix.isInstanceOf[Bundle]
+
+felix.getState == Bundle.INSTALLED
+
+felix.start
+felix.getState == Bundle.ACTIVE
+
+felix.getHeaders.foreach { case (k, v) => println(k + ": " + v + "\n") }
+
+felix.getBundleContext.installBundle("file:jars/osgidemo-simple-1.0-SNAPSHOT.jar")
+
+val bundle = felix.getBundleContext.getBundle(2)
+
+bundle.getState = Bundle.INSTALLED
+bundle.getHeaders.foreach { case (k, v) => println(k + ": " + v)}
+
+bundle.start
+bundle.stop
+bundle.start
+
+felix.stop
+felix.start
+
+(look in osgi-cache dir)
+
+felix.getBundleContext.getBundles
+felix.getBundleContext.getBundle(2).uninstall
+
+Script 2:
+=========
+
+val be = felix.getBundleContext.installBundle("file:jars/osgidemo-exporter-1.0-SNAPSHOT.jar")
+val bi = felix.getBundleContext.installBundle("file:jars/osgidemo-importer-1.0-SNAPSHOT.jar")
+
+bi.start
+bi.stop
+bi.start
+bi.stop
+
+(note - never started be!)
+
+be.getState == Bundle.RESOLVED
+
+be.uninstall
+
+bi.start
+bi.stop
+
+felix.stop
+felix.start
+
+(could use felix.update)
+
+bi.start
+
+be.uninstall
+
+Script 3:
+=========
+
+felix.getBundleContext.installBundle("file:jars/osgidemo-servicepub-1.0-SNAPSHOT.jar")
+resxx.start
+
+felix.getBundleContext.getServiceReference("java.lang.Runnable")
+felix.getBundleContext.getServiceReferences("java.lang.Runnable", "(Fish-Name=Carlfish)")
+felix.getBundleContext.getServiceReferences("java.lang.Runnable", "(Fish-Name=Bruce)")
+
+resxx.getPropertyKeys
+resxx.getProperty("service.id")
+resxx.getProperty("Fish-Name")
+
+val svc = felix.getBundleContext.getService(resxx)
+svc.asInstanceOf[Runnable].run
+
+resxx.stop
+svc.asInstanceOf[Runnable].run
+
+felix.getBundleContext.ungetService(resxx)
+
+felix.getBundleContext.getServiceReference("java.lang.Runnable")

osgidemo-exporter/nbactions.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+    <action>
+        <actionName>run</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>debug</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</vm.args>
+            <jpda.listen>true</jpda.listen>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>profile</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>${profiler.args}</vm.args>
+            <!-- XXX <java jvm="${profiler.java}" ...> -->
+            <profiler.action>profile</profiler.action>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+</actions>

osgidemo-exporter/pom.xml

+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.atlassian.osgidemo</groupId>
+    <artifactId>osgidemo-exporter</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>osgidemo-exporter OSGi Bundle</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Export-Package>com.atlassian.osgidemo.counter</Export-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

osgidemo-exporter/src/main/assembly/felix.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+ <id>all</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <dependencySets>
+    <dependencySet>
+        <useProjectArtifact>false</useProjectArtifact>
+        <outputDirectory>modules</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+  <files>
+    <file>
+      <source>${project.build.directory}/${project.build.finalName}.jar</source>
+      <outputDirectory>modules</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/felix.jar</source>
+      <outputDirectory>bin</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/config.properties</source>
+      <outputDirectory>conf</outputDirectory>
+    </file>
+  </files>
+</assembly>

osgidemo-exporter/src/main/java/com/atlassian/osgidemo/counter/Counter.java

+package com.atlassian.osgidemo.counter;
+
+public class Counter {
+	private static int c = 0;
+
+	public static int next() {
+		return ++c;
+	}
+}

osgidemo-importer/nbactions.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+    <action>
+        <actionName>run</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>debug</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</vm.args>
+            <jpda.listen>true</jpda.listen>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>profile</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>${profiler.args}</vm.args>
+            <!-- XXX <java jvm="${profiler.java}" ...> -->
+            <profiler.action>profile</profiler.action>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+</actions>

osgidemo-importer/pom.xml

+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.atlassian.osgidemo</groupId>
+    <artifactId>osgidemo-importer</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>osgidemo-exporter OSGi Bundle</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.osgidemo</groupId>
+            <artifactId>osgidemo-exporter</artifactId>
+            <version>1.0-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>com.atlassian.osgidemo.importer.Activator</Bundle-Activator>
+                        <Export-Package/>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

osgidemo-importer/src/main/assembly/felix.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+ <id>all</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <dependencySets>
+    <dependencySet>
+        <useProjectArtifact>false</useProjectArtifact>
+        <outputDirectory>modules</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+  <files>
+    <file>
+      <source>${project.build.directory}/${project.build.finalName}.jar</source>
+      <outputDirectory>modules</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/felix.jar</source>
+      <outputDirectory>bin</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/config.properties</source>
+      <outputDirectory>conf</outputDirectory>
+    </file>
+  </files>
+</assembly>

osgidemo-importer/src/main/java/com/atlassian/osgidemo/importer/Activator.java

+package com.atlassian.osgidemo.importer;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Bundle;
+import com.atlassian.osgidemo.counter.Counter;
+
+public class Activator implements BundleActivator {
+	@Override
+	public void start(BundleContext context) {
+		Bundle thisBundle = context.getBundle();
+
+		System.out.println(thisBundle.getSymbolicName() + 
+			" started. Counter is " + Counter.next());
+	}
+
+	@Override
+	public void stop(BundleContext context) {
+		Bundle thisBundle = context.getBundle();
+
+		System.out.println(thisBundle.getSymbolicName() + 
+			" stopped. Counter is " + Counter.next());
+	}
+
+}

osgidemo-servicepub/nbactions.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+    <action>
+        <actionName>run</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>debug</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</vm.args>
+            <jpda.listen>true</jpda.listen>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>profile</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>${profiler.args}</vm.args>
+            <!-- XXX <java jvm="${profiler.java}" ...> -->
+            <profiler.action>profile</profiler.action>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+</actions>

osgidemo-servicepub/pom.xml

+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.atlassian.osgidemo</groupId>
+    <artifactId>osgidemo-servicepub</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>osgidemo-servicepub OSGi Bundle</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>com.atlassian.osgidemo.servicepub.Activator</Bundle-Activator>
+                        <Export-Package/>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

osgidemo-servicepub/src/main/assembly/felix.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+ <id>all</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <dependencySets>
+    <dependencySet>
+        <useProjectArtifact>false</useProjectArtifact>
+        <outputDirectory>modules</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+  <files>
+    <file>
+      <source>${project.build.directory}/${project.build.finalName}.jar</source>
+      <outputDirectory>modules</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/felix.jar</source>
+      <outputDirectory>bin</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/config.properties</source>
+      <outputDirectory>conf</outputDirectory>
+    </file>
+  </files>
+</assembly>

osgidemo-servicepub/src/main/java/com/atlassian/osgidemo/servicepub/Activator.java

+package com.atlassian.osgidemo.servicepub;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+public class Activator implements BundleActivator {
+    public void start(BundleContext context) throws Exception {
+    	Dictionary<String, String> props = new Hashtable<String, String>();
+    	props.put("Fish-Name", "Carlfish");
+
+    	context.registerService("java.lang.Runnable", new Runnable() {
+    		public void run() {
+    			System.out.println("I am a fish");
+    		}
+    	}, props);
+    }
+
+    public void stop(BundleContext context) throws Exception {
+    	// Nothing
+    }
+
+}

osgidemo-simple/nbactions.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+    <action>
+        <actionName>run</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>debug</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</vm.args>
+            <jpda.listen>true</jpda.listen>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+    <action>
+        <actionName>profile</actionName>
+        <goals>
+            <goal>package</goal>
+            <goal>antrun:run</goal>
+        </goals>
+        <properties>
+            <vm.args>${profiler.args}</vm.args>
+            <!-- XXX <java jvm="${profiler.java}" ...> -->
+            <profiler.action>profile</profiler.action>
+        </properties>
+        <activatedProfiles>
+            <activatedProfile>run-on-felix</activatedProfile>
+        </activatedProfiles>
+    </action>
+</actions>

osgidemo-simple/pom.xml

+<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/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.atlassian.osgidemo</groupId>
+    <artifactId>osgidemo-simple</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>osgidemo-simple OSGi Bundle</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.3.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>com.atlassian.osgidemo.simple.Activator</Bundle-Activator>
+                        <Export-Package/>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

osgidemo-simple/src/main/assembly/felix.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<assembly>
+ <id>all</id>
+  <formats>
+    <format>zip</format>
+  </formats>
+  <dependencySets>
+    <dependencySet>
+        <useProjectArtifact>false</useProjectArtifact>
+        <outputDirectory>modules</outputDirectory>
+    </dependencySet>
+  </dependencySets>
+  <files>
+    <file>
+      <source>${project.build.directory}/${project.build.finalName}.jar</source>
+      <outputDirectory>modules</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/felix.jar</source>
+      <outputDirectory>bin</outputDirectory>
+    </file>
+    <file>
+      <source>${project.build.directory}/config.properties</source>
+      <outputDirectory>conf</outputDirectory>
+    </file>
+  </files>
+</assembly>

osgidemo-simple/src/main/java/com/atlassian/osgidemo/simple/Activator.java

+package com.atlassian.osgidemo.simple;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Bundle;
+
+public class Activator implements BundleActivator {
+	@Override
+	public void start(BundleContext context) {
+		Bundle thisBundle = context.getBundle();
+
+		System.out.println(thisBundle.getSymbolicName() + 
+			" started with ID: " + context.getBundle().getBundleId());
+	}
+
+	@Override
+	public void stop(BundleContext context) {
+		Bundle thisBundle = context.getBundle();
+
+		System.out.println(thisBundle.getSymbolicName() + 
+			" stopped with ID: " + context.getBundle().getBundleId());
+	}
+
+}

osgiplay/build.sbt

+name := "osgi-play"
+
+version := "1.0-SNAPSHOT"
+
+scalaVersion := "2.10.2"
+
+libraryDependencies ++= Seq(
+   "org.scalaz" %% "scalaz-core" % "7.0.2",
+   "org.scalaz" %% "scalaz-effect" % "7.0.2",
+   "org.specs2" %% "specs2" % "2.0" % "test",
+   "org.apache.felix" % "org.apache.felix.framework" % "4.2.1"
+)

osgiplay/jars/osgidemo-exporter-1.0-SNAPSHOT.jar

Binary file added.

osgiplay/jars/osgidemo-importer-1.0-SNAPSHOT.jar

Binary file added.

osgiplay/jars/osgidemo-servicepub-1.0-SNAPSHOT.jar

Binary file added.

osgiplay/jars/osgidemo-simple-1.0-SNAPSHOT.jar

Binary file added.