OSGi based Janus Applications

Janus is compatible with OSGi and it can be run on top of any OSGi compatible framework.

The following Janus artifacts are OSGi bundles :

  • kernel
  • network

This means that you can directly depend on these bundles and then obtain a Kernel instances using Kernels.get().

However this mechanism can be a little tricky. The main problem is that some your bundles may not know which KernelAgentFactory to use and the first one to request the kernel will create it.

The janus osgi artifact provides a whiteboard model to make this integration easier.

In order to use this model, add the following to your pom:

<dependency>
	<groupId>org.janus-project.kernel</groupId>
	<artifactId>osgi</artifactId>
	<version>${janus.verion.osgi}</version>
</dependency>

The property janus.version.osgi is the OGSi-ified version number of Janus. Let say that you want to use Janus 0.6, then the OSGi-ified version number is 0.6.0. We add a third component always equal to zero to the version number of the platform. In case you want to use a daily-build version, say 1.0-SNASPHOT, the OSGi-ified number becomes 1.0.0.SNAPSHOT.

Applications and Modules

The janus OSGi module uses two types of services :

  • JanusApplication: It is mandatory that you define one and only one applicatoin instance. It defines all the need configuration to start a janus kernel properly. The most important are :
    • the KernelAgentFactory that define what type of kernel you what to use. For instance a network enabled kernel vs a custom kernel implementation.
    • The IKernelAuthority is used by the platform to authorize certain kernel operations like stopping the platform.
  • JanusModule: Modules are self-contained MAS that are re-usable by more than one application. For instance, you can create a TextChatModule that start all agents to allow users to chat with other users.

Additionally you may register:

To register these services use the BundleContext passed to the BundleActivator. For instance:

public void start(BundleContext context) throws Exception {
	application = new Application(context);
	context.registerService(JanusApplication.class.getName(),application , null);
	context.registerService(JanusModule.class.getName(),new Module() , null);
}


Once you have registered your JanusApplication, when the janus-osgi bundle is activated it will use it to start a janus kernel using the configuration you defined. Additionally, if your application enabled janus modules to be started automatically it find and start all janus modules.

IMPORTANT: You should register your Janus Application only once! Do not register the JanusApplication as an Application AND as a JanusModule.

Starting Modules programmatically

The Janus Applications can enable the platform to start all registered modules automatically. However some applications might want to do this by hand (e.g. for security reasons).

To do so, first you need to disable the automatic start of modules by returning false in you JanusApplication implementation.

Then use the application's or module's start method start other modules one by one.

 
  Credentials credentials = ... ;
  kernel.startModule(MyModule.class.getName(), credentials);

The operations will be validated against the IKernelAuthority if any or approved if no authority was provided.

Tested OSGi frameworks

2016-01-24SARL 0.3.1 and Janus 2.0.3.1 are available.
2015-11-30SARL 0.3.0 and Janus 2.0.3.0 are available.
This page was last modified on 23 May 2013, at 22:15. This page has been accessed 11,552 times.
Copyright 2010-2017 © Janus Core Developers - Privacy policy