introduction to osgi +actorframe surya bahadur kathayat

16
Introduction to OSGi +ActorFrame Surya Bahadur Kathayat [email protected]

Upload: lee-dalton

Post on 19-Jan-2018

224 views

Category:

Documents


0 download

DESCRIPTION

What is the OSGi service platform? Java based service platform that can be remotely managed Applications and components (coming in the form of bundles for deployment) can be remotely installed, started, stopped, updated and uninstalled without requiring a reboot

TRANSCRIPT

Page 1: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Introduction to OSGi

+ActorFrameSurya Bahadur [email protected]

Page 2: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Presentation includes

What is the OSGi service platform? Why the OSGi service platform?

ActorFrame and OSGi

Some hands on exercise

Page 3: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

What is the OSGi service platform? Java based service platform

that can be remotely managed

Applications and components (coming in the form of bundles for deployment) can be remotely installed, started, stopped, updated and uninstalled without requiring a reboot

Page 4: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

OSGi Framework Bundles - Bundles are the OSGi

components made by the developers.

Services - The services layer connects bundles in a dynamic way by offering a publish-find-bind model for plain old Java objects.

Life-Cycle - The API to install, start, stop, update, and uninstall bundles.

Modules - The layer that defines how a bundle can import and export code.

Security - The layer that handles the security aspects.

Execution Environment - Defines what methods and classes are available in a specific platform.

Ref:http://www.osgi.org/About/WhatIsOSGi

Page 5: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Why the OSGi service platform? Components are smaller

Easier to make Components are not coupled to other components

Gives reusability Excellent model for the myriad of customizations

and variation that are required of today’s devices Collaborative model

Allows reuse of other components for most problems More on - http://www.osgi.org/About/WhyOSGi

Page 6: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

ActorFrame and OSGi

Core component is the ActorRouter bundle contains forward table –

info about in which bundle (visible) actor is running

carries messages between the actors running on different java containers

actors send actor messages to each other

Page 7: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Hands on..

OSGi Bundle How to create simple service OSGi bundle? How to create OSGi bundle with Ramses?

You will need Java, ActorFrame, Ramses, Eclipse, Knopflerfish OSGi

Page 8: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Creating and testing simple OSGi bundle Install Ramses plugin for eclipse 3.4 (classical version)

Update site: http://w3.item.ntnu.no/ramses/updates/ Import org.isisproject.actorframeosgi project in eclipse: New|Other|

Examples|Import ActorFrrame OSGi Libraries from Tellu Create java project – lets name it ExampleBundle Add org.isisproject.actorframeosgi project in the Build path of

ExampleBundle project (or alternatively add framework.jar in the build path)

Create src/META-INF/MANIFEST.MF file in the ExampleBundle project

Create Activator.java, and test java class say HelloWorld.java in the src/ folder

Export the src as a java jar in eclipse chosing created manifest file

Thats all.....test it dragging it to the knopflerfish OSGi console

More on http://www.knopflerfish.org/tutorials/osgi_tutorial.pdf

Page 9: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Java Files package no.ntnu.item.examplebundle;

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

public class Activator implements BundleActivator { public static BundleContext bc = null;

private HelloWorld thread = null;

public void start(BundleContext bc) throws Exception {System.out.println("SimpleBundle starting...");

Activator.bc = bc;

this.thread = new HelloWorld(); this.thread.start(); }

public void stop(BundleContext bc) throws Exception { System.out.println("SimpleBundle stopping...");

this.thread.stopThread(); this.thread.join();

Activator.bc = null; } }

package no.ntnu.item.examplebundle;

public class HelloWorld extends Thread { private boolean running = true; public HelloWorld() { } public void run() { while (running) { System.out.println("Hello World!"); try { Thread.sleep(5000); } catch (InterruptedException e) { System.out.println("HelloWorld ERROR: " + e); } } } public void stopThread() { this.running = false; } }

•No services/application implemented yet•Threading just for some debugging

Page 10: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Manifest File Manifest-Version: 1.0 Bundle-Description: Bundle-Name: Example Bundle-Classpath: . Bundle-Activator:

no.ntnu.item.examplebundle.Activator

Import-Package: org.osgi.framework

Bundle-ManifestVersion: 2 Bundle-Vendor: NTNU Bundle-SymbolicName:

MyExampleBundle Bundle-Version: 1.0.1

Page 11: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Lets see..

Page 12: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Creating a simple Service

Create service interface and service implementation

Register the service from the start method in Activator class

Add service package to Export-Package property in the MANIFEST file, in order to make your service accessible to other services

Export as a java jar bundle and deploy

Page 13: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Lets see..

Page 14: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Creating a simple Service client Get the service reference from the start

method in Activator class Add service package to Import-Package

property in the MANIFEST file, in order to declare that your service need to have access ot this package

Export as a java jar bundle and deploy

Page 15: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

Lets see..

Page 16: Introduction to OSGi +ActorFrame Surya Bahadur Kathayat

OSGi Bundles with ActorFrame/Ramses Create Java Project

and extend it to Ramses Project type

Design your services/actors – UML model

Generate code and create OSGi bundle – just with one click

http://www.item.ntnu.no/academics/courses/ttm3/faq