Transcript Slide 1

Introduction to OSGi
+ActorFrame
Surya Bahadur Kathayat
[email protected]
Presentation includes

What is the OSGi service platform?
Why the OSGi service platform?

ActorFrame and OSGi

Some hands on exercise

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
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
Why the OSGi service platform?

Components are smaller


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


Easier to make
Allows reuse of other components for most problems
More on - http://www.osgi.org/About/WhyOSGi
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
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
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
Java Files

package no.ntnu.item.examplebundle;

package no.ntnu.item.examplebundle;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

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;
}
}



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;
}
}
•No services/application
implemented yet
•Threading just for some debugging
Manifest File










Manifest-Version: 1.0
Bundle-Description:
Bundle-Name: Example
Bundle-Classpath: .
Bundle-Activator:
no.ntnu.item.examplebundle.A
ctivator
Import-Package:
org.osgi.framework
Bundle-ManifestVersion: 2
Bundle-Vendor: NTNU
Bundle-SymbolicName:
MyExampleBundle
Bundle-Version: 1.0.1

Lets see..
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

Lets see..
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

Lets see..
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