osgi and eclipse rcp

42
OSGi & Eclipse RCP Eric Jain Seattle Java User Group, November 15, 2011

Upload: eric-jain

Post on 27-May-2015

755 views

Category:

Technology


4 download

DESCRIPTION

Slides for a talk at the Seattle Java User Group about building a workflow management application for a biomedical lab on top of the OSGi module system and the Eclipse Rich Client Platform.

TRANSCRIPT

Page 1: OSGi and Eclipse RCP

OSGi & Eclipse RCPEric JainSeattle Java User Group, November 15, 2011

Page 2: OSGi and Eclipse RCP
Page 3: OSGi and Eclipse RCP

1 acctggat...2 acctgaat...3 acctggag...

Page 4: OSGi and Eclipse RCP

1 A*24:36N2 A*02:01:213 A*03:20/A*11:86

Page 5: OSGi and Eclipse RCP

1 A*24:36N2 A*02:01:213 A*03:20/A*11:86

Samples

Extraction

Quantification

Other Workflows

Normalization

Sequencing

SNP-Calling GenotypingAmplification

Resolution

QC Failure / Repeat

Page 6: OSGi and Eclipse RCP
Page 7: OSGi and Eclipse RCP
Page 8: OSGi and Eclipse RCP
Page 9: OSGi and Eclipse RCP
Page 10: OSGi and Eclipse RCP
Page 11: OSGi and Eclipse RCP
Page 12: OSGi and Eclipse RCP
Page 13: OSGi and Eclipse RCP
Page 14: OSGi and Eclipse RCP
Page 15: OSGi and Eclipse RCP
Page 16: OSGi and Eclipse RCP

h2

fs

ui

core

logging

fs-proxy

pg

fs-http

standalone client

server

exec

Page 17: OSGi and Eclipse RCP

Amplification

Sequencing1.0.0

Sequencing2.0.0

SNPDiscovery

SNPCalling

Workflow B

Workflow A (v2)

Workflow A(v1)

Page 18: OSGi and Eclipse RCP

Manifest-Version: 1.0Bundle-ManifestVersion: 2Bundle-Name: Demo BundleBundle-SymbolicName: org.seajug.demoBundle-Version: 1.0.0Import-Package: com.google.common.base;version="[10.0.0,11.0.0)", com.google.common.collect;version="[10.0.0,11.0.0)", com.google.common.io;version="[10.0.0,11.0.0)"Export-Package: org.seajug.demo;version="1.0.0", org.seajug.demo.ui;version="1.0.0"Bundle-ClassPath: lib/jxl.jar, conf/, .Bundle-Activator: org.seajug.demo.ActivatorBundle-RequiredExecutionEnvironment: JavaSE-1.6

META-INF/MANIFEST.MF

Page 19: OSGi and Eclipse RCP

Bootstrap CL

Extensions CL

System Classpath CL

Context 3Context 1 Context 2

Page 20: OSGi and Eclipse RCP

Bootstrap CL

Extensions CL

System Classpath CL

Bundle 3Bundle 1

Bundle 2

Fragment A

Bundle 4

Page 21: OSGi and Eclipse RCP
Page 22: OSGi and Eclipse RCP

osgi> ss

Framework is launched.

id State Bundle0 ACTIVE org.eclipse.osgi_3.7.1.R37x_v20110808-1106

Fragments=11 RESOLVED org.eclipse.equinox.weaving.hook_1.0.0.v20100108

Master=02 ACTIVE org.eclipse.equinox.simpleconfigurator_1.0.200.v201105023 RESOLVED ch.qos.logback.classic_0.9.29

Fragments=984 RESOLVED ch.qos.logback.core_0.9.295 RESOLVED com.google.guava_10.0.0...53 <<LAZY>> org.eclipse.emf.ecore_2.7.0.v20110912-0920...78 RESOLVED org.eclipse.swt_3.7.1.v3738a

Fragments=7979 RESOLVED org.eclipse.swt.win32.win32.x86_64_3.7.1.v3738a

Master=78...

Page 23: OSGi and Eclipse RCP

From: Creating Modular Applications in Java. Manning, 2011.

Page 24: OSGi and Eclipse RCP

package org.seajug.demo;

import org.osgi.framework.BundleActivator;import org.osgi.framework.BundleContext;import org.osgi.framework.ServiceReference;

public class Activator implements BundleActivator {

@Override public void start(BundleContext context) { context.registerService(Foo.class, new Foo(), null); ServiceReference<Bar> ref = context.getServiceReference(Bar.class); Bar bar = (Bar) context.getService(ref); ... }

@Override public void stop(BundleContext context) { }}

Activator.java

Page 25: OSGi and Eclipse RCP

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="...">

<osgi:reference id="foo" interface="org.seajug.demo.Foo"/>

<bean id="bar" class="org.seajug.demo.internal.BarImpl"/>

<osgi:service ref="bar" interface="org.seajug.demo.Bar"/>

<context:annotation-config/>

</beans>

META-INF/spring-context.xml

Page 26: OSGi and Eclipse RCP
Page 27: OSGi and Eclipse RCP

<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.1.0</version> <configuration> <instructions> <module>com.google.inject</module> <Bundle-Copyright>Copyright (C) 2006 Google Inc.</Bundle-Copyright> <Bundle-DocURL>http://code.google.com/p/google-guice/</Bundle-DocURL> <Bundle-Name>${project.artifactId}</Bundle-Name> <Bundle-SymbolicName>$(module)</Bundle-SymbolicName> <Bundle-RequiredExecutionEnvironment> J2SE-1.5,JavaSE-1.6 </Bundle-RequiredExecutionEnvironment> <Import-Package>!com.google.inject.*,*</Import-Package> <_versionpolicy> [$(version;==;$(@)),$(version;+;$(@))) </_versionpolicy> </instructions> </configuration> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>manifest</goal> </goals> </execution> </executions></plugin>

pom.xml

Page 28: OSGi and Eclipse RCP

module com.greetings @ 0.1 { requires jdk.base; // default to the highest available version requires org.astro @ 1.[1.1.1]+; class com.greetings.Hello;}}

module-info.java

http://openjdk.java.net/projects/jigsaw/

Page 29: OSGi and Eclipse RCP

package org.seajug.demo;

import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableItem;

public class TableDemo {

public void show(String[] values, Composite parent) { Table table = new Table(parent, SWT.BORDER | SWT.V_SCROLL); for (String value : values) { TableItem item = new TableItem(table, SWT.NONE); item.setText(value); } }}

TableDemo.java

Page 30: OSGi and Eclipse RCP

package org.seajug.demo;

import org.eclipse.jface.viewers.ArrayContentProvider;import org.eclipse.jface.viewers.LabelProvider;import org.eclipse.jface.viewers.TableViewer;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Composite;

public class TableViewerDemo {

public void show(String[] values, Composite parent) { TableViewer viewer = new TableViewer(parent, SWT.BORDER | SWT.V_SCROLL); viewer.setLabelProvider(new LabelProvider()); viewer.setContentProvider(new ArrayContentProvider()); viewer.setInput(values); }}

TableViewerDemo.java

Page 31: OSGi and Eclipse RCP

package org.seajug.demo;

import org.eclipse.jface.viewers.TableViewer;import org.eclipse.swt.widgets.Composite;import org.eclipse.ui.IViewSite;import org.eclipse.ui.PartInitException;import org.eclipse.ui.part.ViewPart;

public class DemoViewPart extends ViewPart {

private TableViewer viewer;

@Override public void init(IViewSite site) throws PartInitException { super.init(site); }

@Override public void createPartControl(Composite parent) { viewer = new TableViewer(parent, SWT.BORDER | SWT.V_SCROLL); ... }

@Override public void setFocus() { viewer.getControl().setFocus(); }

@Override public void dispose() { super.dispose(); }}

TableViewPartDemo.java

Page 32: OSGi and Eclipse RCP

<extension point="org.eclipse.ui.views"> <view id="demoView" name="Demo" class="org.seajug.demo.DemoViewPart" /></extension>

plugin.xml

Page 33: OSGi and Eclipse RCP

<extension point="org.eclipse.ui.commands"> <command id="openItem" name="Open Item"/></extension>

<extension point="org.eclipse.ui.handlers"> <handler class="org.seajug.demo.OpenItemHandler" commandId="openItem"> <activeWhen> <with variable="activePartId"> <equals value="demoView"/> </with> </activeWhen> <enabledWhen> <with variable="selection"> <and> <count value="1"/> <iterate> <instanceof value="org.seajug.demo.Item"/> </iterate> </and> </with> </enabledWhen> </handler></extension>

<extension point="org.eclipse.ui.menus"> <menuContribution locationURI="toolbar:demoView"> <command commandId="openItem" icon="icons/open.png" style="push"/> </menuContribution></extension>

plugin.xml

Page 34: OSGi and Eclipse RCP
Page 35: OSGi and Eclipse RCP
Page 36: OSGi and Eclipse RCP

package org.fhcrc.gems.ui;

import org.eclipse.core.runtime.IProgressMonitor;import org.eclipse.core.runtime.IStatus;import org.eclipse.core.runtime.Status;import org.eclipse.core.runtime.jobs.Job;

public class JobDemo {

public void run() { new Job("Genotyping") { @Override protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("Reticulating splines", 100); for (int i = 0; i < 100; ++i) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } ... } monitor.done(); return Status.OK_STATUS; } }.schedule(); }}

Page 37: OSGi and Eclipse RCP
Page 38: OSGi and Eclipse RCP

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0">

<modelVersion>4.0.0</modelVersion>

<groupId>org.seajug.demo</groupId> <artifactId>parent</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging>

<properties> <tycho-version>0.13.0</tycho-version> </properties>

<modules> <module>product</module> <module>org.seajug.demo.core</module> <module>org.seajug.demo.feature</module> <module>org.seajug.demo.test</module> <module>target-definition</module> </modules>

<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-maven-plugin</artifactId> <version>${tycho-version}</version> <extensions>true</extensions> </plugin> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho-version}</version> <configuration> <resolver>p2</resolver> <target> <artifact> <groupId>org.seajug.demo</groupId> <artifactId>target-definition</artifactId> <version>1.0.0-SNAPSHOT</version> <classifier>build</classifier> </artifact> </target> </configuration> </plugin> </plugins> </build>

</project>

pom.xml

Page 39: OSGi and Eclipse RCP

<project xmlns="http://maven.apache.org/POM/4.0.0">

<modelVersion>4.0.0</modelVersion>

<groupId>org.seajug.demo</groupId> <artifactId>org.seajug.demo.core</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>eclipse-plugin</packaging>

<parent> <groupId>org.seajug.demo</groupId> <artifactId>parent</artifactId> <version>1.0.0-SNAPSHOT</version> </parent>

</project>

org.seajug.demo.core/pom.xml

Page 40: OSGi and Eclipse RCP
Page 41: OSGi and Eclipse RCP
Page 42: OSGi and Eclipse RCP