osgi is shiny
DESCRIPTION
Short lightening talk/intro on OSGiTRANSCRIPT
OSGI IS A SHINY THINGSHINY THINGS HAVE SHARP EDGES
SHARP EDGES ARE OFTEN PAINFUL
AT LEAST I FEEL SOMETHING
WHAT IS OSGI?
FORMERLY “OPEN STANDARDS GATEWAY INITIATIVE”
FOUNDED 1999 BY ERICSON, IBM, ORACLE, SUN MICROSYSTEMS
PROVIDES A STANDARD FOR SOFTWARE COMPONENTS AND EXECUTION ENVIRONMENT, WHICH IS BASED ON THE JAVA VIRTUAL MACHINE
THE PROBLEM
SMALL SYSTEMS BECOME LARGE COMPLEX SYSTEMS
MONOLITHIC BEASTS OF BURDEN
HIGHLY COUPLED
HARD TO TEST
HARDER TO DEPLOY
DOESN’T MAVEN/IVY SOLVE THAT?
MAVEN PROVIDES BUILD TIME MODULARITY
OSGI PROVIDES DEPLOY/RUN TIME MODULARITY
OSGI SUPPORTS MULTIPLE VERSIONS OF MODULES
THE SOLUTION
LIVE DEPLOYMENT OF BUNDLES AT RUNTIME
MULTIPLE VERSIONS OF BUNDLES CONCURRENTLY
DIFFERENT BUNDLES -CAN- SEE DIFFERENT VERSIONS
BUNDLE LIFECYCLE
WHAT DOES IT LOOK LIKE?
BORROWED FROM WIKIPEDIA
REMEMBER KERRYQUEUE?
SIMPLE THREAD BASED QUEUE
JOBS GO IN
JOBS COME OUT
COMMAND LINE DRIVEN
LETS BUNDLE IT!
BUILD A DISTRIBUTABLE JAR FILE
DEPLOY IT TO FELIX
W00T - BUT IT DOES NOTHING!
TIME FOR ACTIVATION
IMPLEMENT THE BUNDLE ACTIVATOR INTERFACE
ADD A MANIFEST TO THE JAR
ORGINAL ENTRY POINT
public class Main {
public Main(InterestingData interestingData) { this.interestingData = interestingData; }
public static void main(String[] args) { Main main = new Main(new InterestingData()); main.startWorkers(args[0]); }
private void startWorkers(String instance) { Thread workerThread = new Thread(new WorkerThread(interestingData)); workerThread.start();
int count = 20; for (Integer i = 0; i < count; i++) { interestingData.pushStuffIntoQueue(instance + "-" + i); } }}
BUNDLE ENTRY POINT
public class KerryActivator implements BundleActivator {
WorkerThread worker;
public void start(BundleContext bundleContext) throws Exception {
InterestingData interestingData = new InterestingData();
worker = new WorkerThread(interestingData); new Thread(worker).start();
int count = 20; for (Integer i = 0; i < count; i++) { interestingData.pushStuffIntoQueue( bundleContext.getBundle().getBundleId() + "-" + i); } }
public void stop(BundleContext bundleContext) throws Exception { System.out.println("So long... thanks for all the fish."); worker.terminate(); }}
MANIFEST
Import-Package: org.osgi.frameworkBundle-Activator: kerryQueue.KerryActivator
SCALA ANYONE?package com.theoryinpractise.scalabundle;
import org.osgi.framework.{BundleActivator,BundleContext}
class ScalaActivator extends BundleActivator { def start(bundleContext: BundleContext) = { System.out.println("Hello from scala") }
def stop(bundleContext: BundleContext) = { System.out.println("Goodbyte from scala") }}
SCALA ANYONE?<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> <groupId>com.theoryinpracise.scalabundle</groupId> <artifactId>scalabundle</artifactId> <packaging>bundle</packaging> <version>1.0-SNAPSHOT</version> <name>scalabundle</name>
<repositories> <repository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </repository> </repositories>
<pluginRepositories> <pluginRepository> <id>scala-tools.org</id> <name>Scala-tools Maven2 Repository</name> <url>http://scala-tools.org/repo-releases</url> </pluginRepository> </pluginRepositories>
<dependencies> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.core</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.7.1</version> </dependency> </dependencies>
SCALA ANYONE? <build> <sourceDirectory>src/main/scala</sourceDirectory> <testSourceDirectory>src/test/scala</testSourceDirectory> <plugins> <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> <configuration> <instructions> <Private-Package>com.theoryinpractise.scalabundle.*, scala.*</Private-Package> <Bundle-Activator>com.theoryinpractise.scalabundle.ScalaActivator</Bundle-Activator> </instructions> </configuration> </plugin>
</plugins> </build></project>
LINKS
HTTP://WWW.OSGI.ORG
HTTP://EN.WIKIPEDIA.ORG/WIKI/OSGI
HTTP://FELIX.APACHE.ORG
HTTP://NEILBARTLETT.NAME/BLOG/OSGIBOOK/