Skip to content
/ pojosr Public

A service registry that enables OSGi style service registry programs

Notifications You must be signed in to change notification settings

lefou/pojosr

Repository files navigation

A service registry that enables OSGi style service registry programs

PojoSR is service registry that enables OSGi style service registry programs without using an OSGi framework.

This is a clone of https://code.google.com/p/pojosr/ which looks pretty much abandoned.

Please note that PojoSR is now integrated in Apache Felix as Felix Connect. Unfortunately, there is almost no developement activity and also no documentation yet, so most of the docs you can find here, might help you to use Felix Connect too.

Introduction

The idea is to create something that would make the service and parts of the life cycle layer of OSGi available in environments where it typically isn’t.

The current implementation is based in parts on Apache Felix and is a work in progress. Feel free to play with it and let me know what is missing and if it is useful for something - if this is going somewhere I’ll try to merge it back to felix (probably as a new subproject). The reason that it is here in the first place is that I’m not sure it will go anywhere.

That said, what is there is a service registry that you can use from normal java (including access to a bundle context so you can continue using e.g., ServiceTracker) and a framework that installs and starts bundles found on the classpath and still provides global visibility to the classes. However, it is not a full OSGi framework and doesn’t provide all of the features of one.

It works rather well with well-designed bundles including getting scr, dependencymanager, and ipojo based services to work. People used it on the Google App Engine (GAE), Amazon Elastic Beanstalk, and inside JEE containers (it has a mode to run without creating threads and doesn’t create a bundle cache — hence, works on the GAE alas, a lot of bundles don’t because they in turn create threads).

Finally, this is not intended to be a replacement for osgi but rather as a way to enable bundles in environments where they otherwise couldn’t run and as a start to OSGi development. Use at your own risk.

Usage

There are various ways to use pojosr:

  • As a service registry

  • As a OSGi "light" framework

  • As a test environment to test bundle behaviour

As a Service registry

You can get a service registry like this:

ServiceLoader<PojoServiceRegistryFactory> loader = ServiceLoader.load(PojoServiceRegistryFactory.class);

PojoServiceRegistry registry = loader.iterator().next().newPojoServiceRegistry(new HashMap());

the interface looks like:

public interface PojoServiceRegistry {
        public BundleContext getBundleContext();

        public void addServiceListener(ServiceListener listener, String filter)
                        throws InvalidSyntaxException;

        public void addServiceListener(ServiceListener listener);

        public void removeServiceListener(ServiceListener listener);

        public ServiceRegistration registerService(String[] clazzes,
                        Object service, @SuppressWarnings("rawtypes") Dictionary properties);

        public ServiceRegistration registerService(String clazz, Object service,
                        @SuppressWarnings("rawtypes") Dictionary properties);

        public ServiceReference[] getServiceReferences(String clazz, String filter)
                        throws InvalidSyntaxException;

        public ServiceReference getServiceReference(String clazz);

        public Object getService(ServiceReference reference);

        public boolean ungetService(ServiceReference reference);
}

As a OSGi "light" framework

Via PojoServiceRegistry

Either use the PojoServiceRegistry with bundles form the classpath installed and started by using the provided classpathscanner like this (or standalone):

Map config = new HashMap();
config.put(PojoServiceRegistryFactory.BUNDLE_DESCRIPTORS, new ClasspathScanner().scanForBundles());

ServiceLoader<PojoServiceRegistryFactory> loader = ServiceLoader.load(PojoServiceRegistryFactory.class);

PojoServiceRegistry registry = loader.iterator().next().newPojoServiceRegistry(config);

Standalone

A main method is provided as well e.g. the following gives us a working gogo shell by just putting the gogo bundles on the classpath and running the framework,

java -cp target/de.kalpatec.pojosr.framework-0.1.0-SNAPSHOT.jar:org.apache.felix.gogo.runtime-0.8.0.jar:org.apache.felix.gogo.shell-0.8.0.jar:org.apache.felix.gogo.command-0.8.0.jar de.kalpatec.pojosr.framework.PojoSR
...
Starting: org.apache.felix.gogo.runtime
Starting: org.apache.felix.gogo.shell
Starting: org.apache.felix.gogo.command
g! lb
START LEVEL 1
   ID|State      |Level|Name
    0|Active     |    1|System Bundle (0.0.1)
    1|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/classes.jar!/ (0.0.0)
    2|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks/JavaRuntimeSupport.framework/Versions/A/Resources/Java/JavaRuntimeSupport.jar!/ (0.0.0)
    3|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/ui.jar!/ (0.0.0)
    4|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/laf.jar!/ (0.0.0)
    5|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jsse.jar!/ (0.0.0)
    6|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/jce.jar!/ (0.0.0)
    7|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Classes/charsets.jar!/ (0.0.0)
    8|Active     |    1|jar:file:/Library/Java/Extensions/RXTXcomm.jar!/ (0.0.0)
    9|Active     |    1|jar:file:/System/Library/Java/Extensions/AppleScriptEngine.jar!/ (0.0.0)
   10|Active     |    1|jar:file:/System/Library/Java/Extensions/CoreAudio.jar!/ (0.0.0)
   11|Active     |    1|jar:file:/System/Library/Java/Extensions/dns_sd.jar!/ (0.0.0)
   12|Active     |    1|jar:file:/System/Library/Java/Extensions/j3daudio.jar!/ (0.0.0)
   13|Active     |    1|jar:file:/System/Library/Java/Extensions/j3dcore.jar!/ (0.0.0)
   14|Active     |    1|jar:file:/System/Library/Java/Extensions/j3dutils.jar!/ (0.0.0)
   15|Active     |    1|jar:file:/System/Library/Java/Extensions/jai_codec.jar!/ (0.0.0)
   16|Active     |    1|jar:file:/System/Library/Java/Extensions/jai_core.jar!/ (0.0.0)
   17|Active     |    1|jar:file:/System/Library/Java/Extensions/mlibwrapper_jai.jar!/ (0.0.0)
   18|Active     |    1|jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/ (0.0.0)
   19|Active     |    1|jar:file:/System/Library/Java/Extensions/QTJava.zip!/ (0.0.0)
   20|Active     |    1|jar:file:/System/Library/Java/Extensions/vecmath.jar!/ (0.0.0)
   21|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/apple_provider.jar!/ (0.0.0)
   22|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/dnsns.jar!/ (0.0.0)
   23|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/js-engine.jar!/ (0.0.0)
   24|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/js.jar!/ (0.0.0)
   25|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/localedata.jar!/ (0.0.0)
   26|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/sunjce_provider.jar!/ (0.0.0)
   27|Active     |    1|jar:file:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext/sunpkcs11.jar!/ (0.0.0)
   28|Active     |    1|Apache Felix Gogo Runtime (0.8.0)
   29|Active     |    1|Apache Felix Gogo Shell (0.8.0)
   30|Active     |    1|Apache Felix Gogo Command (0.8.0)
g!

GAE and other "no user thread" frameworks

The GAE doesn’t allow threads so there is a property to deliver all events synchronous:

-Dde.kalpatec.pojosr.framework.events.sync=true

Services

There is a PackageAdmin and a StartLevel service but they don’t do anything (just published because quite some interesting bundles have dependencies on them).

Updates

2012-11-07

Download the new bare version 0.2.1 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework.bare:0.2.1 or from the downloads section.

2012-11-07

Download version 0.2.1 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework:0.2.1 or from the downloads section.

2012-11-04

Download version 0.2.0 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework:0.2.0 or from the downloads section.

2011-10-12

Download version 0.1.8 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework:0.1.8 or from the downloads section.

2011-10-12

Download version 0.1.6 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework:0.1.6 or from the downloads section.

2011-08-30

Download version 0.1.4 from maven: com.googlecode.pojosr:de.kalpatec.pojosr.framework:0.1.4.

2011-08-29

Download version 0.1.4 from the downloads section.

About

A service registry that enables OSGi style service registry programs

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages