osgi is shiny

16

Click here to load reader

Upload: talios

Post on 07-Jul-2015

1.603 views

Category:

Technology


0 download

DESCRIPTION

Short lightening talk/intro on OSGi

TRANSCRIPT

Page 1: Osgi Is Shiny

OSGI IS A SHINY THINGSHINY THINGS HAVE SHARP EDGES

SHARP EDGES ARE OFTEN PAINFUL

AT LEAST I FEEL SOMETHING

Page 2: Osgi Is Shiny

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

Page 3: Osgi Is Shiny

THE PROBLEM

SMALL SYSTEMS BECOME LARGE COMPLEX SYSTEMS

MONOLITHIC BEASTS OF BURDEN

HIGHLY COUPLED

HARD TO TEST

HARDER TO DEPLOY

Page 4: Osgi Is Shiny

DOESN’T MAVEN/IVY SOLVE THAT?

MAVEN PROVIDES BUILD TIME MODULARITY

OSGI PROVIDES DEPLOY/RUN TIME MODULARITY

OSGI SUPPORTS MULTIPLE VERSIONS OF MODULES

Page 5: Osgi Is Shiny

THE SOLUTION

LIVE DEPLOYMENT OF BUNDLES AT RUNTIME

MULTIPLE VERSIONS OF BUNDLES CONCURRENTLY

DIFFERENT BUNDLES -CAN- SEE DIFFERENT VERSIONS

BUNDLE LIFECYCLE

Page 6: Osgi Is Shiny

WHAT DOES IT LOOK LIKE?

BORROWED FROM WIKIPEDIA

Page 7: Osgi Is Shiny

REMEMBER KERRYQUEUE?

SIMPLE THREAD BASED QUEUE

JOBS GO IN

JOBS COME OUT

COMMAND LINE DRIVEN

Page 8: Osgi Is Shiny

LETS BUNDLE IT!

BUILD A DISTRIBUTABLE JAR FILE

DEPLOY IT TO FELIX

W00T - BUT IT DOES NOTHING!

Page 9: Osgi Is Shiny

TIME FOR ACTIVATION

IMPLEMENT THE BUNDLE ACTIVATOR INTERFACE

ADD A MANIFEST TO THE JAR

Page 10: Osgi Is Shiny

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); } }}

Page 11: Osgi Is Shiny

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(); }}

Page 12: Osgi Is Shiny

MANIFEST

Import-Package: org.osgi.frameworkBundle-Activator: kerryQueue.KerryActivator

Page 13: Osgi Is Shiny

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") }}

Page 14: Osgi Is Shiny

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>

Page 15: Osgi Is Shiny

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>

Page 16: Osgi Is Shiny

LINKS

HTTP://WWW.OSGI.ORG

HTTP://EN.WIKIPEDIA.ORG/WIKI/OSGI

HTTP://FELIX.APACHE.ORG

HTTP://NEILBARTLETT.NAME/BLOG/OSGIBOOK/