osgi framework overview
TRANSCRIPT
![Page 2: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/2.jpg)
Bundle management portion GUI Bundle list un/install bundle Start/stop bundle Update/configre bundle
EV bundle portion one trigger function to broadcast “Emergency event!” once receive EV message, response it and show
incoming message. Port number and message should be able to modify
![Page 3: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/3.jpg)
PPT slice
Architectures
System design
Used module
Source code
Java code
Jar file
![Page 4: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/4.jpg)
Knopflerfish
http://www.knopflerfish.org/download.html
Apache Felix
http://felix.apache.org/site/downloads.cgi
Equinox
http://download.eclipse.org/equinox/
Prosyst mBedded Server Equinox Edition
http://dz.prosyst.com/oss/
![Page 5: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/5.jpg)
Install Use startinstall.bat
Start framework C:\mbs_equinox\bin\v
ms\jdk\server.bat
![Page 6: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/6.jpg)
install uninstall start stop refresh update status ss services
bundles bundle headers log gc sl exit init shutdown
![Page 7: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/7.jpg)
install file:../../../demo/bundles/httpdemo.jar start <bundle id> Check the bundle status is active
Visit http://<mbs_host>/images/imagination.jpg
![Page 8: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/8.jpg)
Stop <bundle id> Check the bundle status is resolved
Uninstall <bundle id>
![Page 9: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/9.jpg)
JDK 1.6.07 mBS Equinox edition 3.4 Eclipse
Configure build path…
Add external JARs… bundles/org.eclipse.osgi.jar
bundles/org.eclipse.osgi.services.jar
bundles/org.eclipse.osgi.util.jar
![Page 10: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/10.jpg)
1. Bundle implementation2. Bundle activator3. Compile and generate class file4. Manifest.mf file5. Generate bundle JAR file6. Install and start bundle
![Page 11: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/11.jpg)
HelloWorldThread.javapublic class HelloWorldThread extends Thread {
private boolean running = true;
public HelloWorldThread() {}
public void run() {
while (running) {
System.out.println("Hello World!");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
System.out.println("ERROR: " + e);
}
}
}
public void stopThread() {
this.running = false;
}
}
![Page 12: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/12.jpg)
Activator.javaimport org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
public static BundleContext bc = null;
private HelloWorldThread thread = null;
public void start(BundleContext bc) throws Exception {
System.out.println("Bundle starting...");
Activator.bc = bc;
this.thread = new HelloWorldThread();
this.thread.start();
}
public void stop(BundleContext bc) throws Exception {
System.out.println("Bundle stopping...");
this.thread.stopThread();
this.thread.join();
Activator.bc = null;
}
}
![Page 13: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/13.jpg)
Manifest.mfManifest-Version: 1.0
Bundle-Name: first bundle
Bundle-SymbolicName: firstbundle
Bundle-Version: 1.0.0
Bundle-Description: first Demo Bundle
Bundle-Vendor: vendorABC
Bundle-Activator: demo.Activator
Bundle-Category: demo
Import-Package: org.osgi.framework
Compile CMD
javac -classpath .;../bundles/org.eclipse.osgi.jar; *.java
Jar CMD
jar cmf ./manifest firstbundle.jar *.class
![Page 14: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/14.jpg)
Build.xml<?xml version="1.0"?>
<project name="simplebundle" default="all">
<target name="all" depends="init,compile,jar" />
<target name="init">
<mkdir dir="./classes" />
<mkdir dir="./bin" />
</target>
<target name="compile">
<javac destdir="./classes" debug="on" srcdir="./src">
</javac>
</target>
<target name="jar">
<jar basedir="./classes" jarfile="./bin/simplebundle.jar" compress="true"
includes="**/*" manifest="./meta-inf/MANIFEST.MF" />
</target>
<target name="clean">
<delete dir="./classes" />
<delete dir="./bin" />
</target>
</project>
![Page 15: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/15.jpg)
GetService.javaimport org.osgi.framework.ServiceReference;
import org.osgi.framework.BundleException;
public class GetService implements BundleActivator {
ServiceReference timeRef = null;
TimeService timeService = null;
public void start(BundleContext bc) throws BundleException {
timeRef = bc.getServiceReference(TimeService.class.getName());
if (timeRef != null) {
timeService = (TimeService) bc.getService(timeRef);
}
if (timeService == null) {
return;
}
}
public void stop(BundleContext bc) throws BundleException {
if (timeRef != null) {
bc.ungetService(timeRef);
timeRef = null;
timeService = null;
}
}
}
![Page 16: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/16.jpg)
public class PMPDemo implements BundleActivator {
static String SYSTEM = "com.prosyst.util.system.SystemService";
public void start(BundleContext bx) throws BundleException {
try {
ServiceReference sr = bx.getServiceReference(PMPService.class.getName());
if(sr == null) throw new BundleException("Can't get\\PMPService");
PMPService pmp = (PMPService)bx.getService(sr);if(pmp == null) throw new BundleException("Can't get\\
PMPService");
Hashtable props = new Hashtable (20);props.put("username", "admin");props.put("password", "admin");PMPConnection con = pmp.connect("socket://127.0.0.1:1449",\\
props);
RemoteObject rObject = con.getReference(SYSTEM, "");
![Page 17: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/17.jpg)
String [] str = {Byte.TYPE.getName()};
RemoteMethod rMethod = rObject.getMethod("getProperties", str);
rMethod.changeReturnType(ExternalizableDictionary.class);Dictionary obj = (ExternalizableDictionary)rMethod.invoke(new\\
Object[] {new Byte((byte) 3)}, true);Enumeration enum = obj.keys();while(enum.hasMoreElements()) {Object tmp = enum.nextElement();System.out.println(tmp + " " + obj.get(tmp));
}} catch (Exception e) {System.out.println(e);
}}
public void stop(BundleContext bx) {}
}
![Page 18: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/18.jpg)
Bundle Management portion
Use PMP (prosyst message protocol) to get a connection to remote framework.
1. request PMPService
2. obtain PMPConnection
3. call remote service method
![Page 19: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/19.jpg)
4. To make a service PMP-accessible, you should additionally implement the com.prosyst.util.io.Remoteinterface in the service class.
public class example implements Remote {
public Class[] remoteInterfaces() {
}
}
Ref: https://dz.prosyst.com/pdoc/mbs_equinox_3.4/um/framework/bundles/prosyst/rpc/pmp/pmpbundle.html
![Page 20: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/20.jpg)
See also:
com.prosyst.util.parser
▪ Parser Service
▪ https://dz.prosyst.com/pdoc/mbs_prof_6.2/um/framework/bundles/system/putil/putil_parser.html
mConsole APIs
▪ https://dz.prosyst.com/pdoc/mbs_prof_6.2/um/framework/admins/mConsole/mConsole_programmer.html
![Page 21: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/21.jpg)
EV bundle portion
Java.net.DatagramSocket
▪ SO_BROADCAST
▪ setBroadcast(boolean on)
▪ getBroadcast()
Java.net.DatagramPacket
▪ Use DatagramPacket(int port)
![Page 22: OSGi framework overview](https://reader031.vdocuments.site/reader031/viewer/2022021503/5a65f2b57f8b9ab21e8b4bad/html5/thumbnails/22.jpg)
https://dz.prosyst.com/pdoc/mbs_equinox_3.4/um/index.html
http://www.knopflerfish.org/tutorials.html