oconnor0
oconnor0

Reputation: 3234

Different configuration/run "modes" under OSGi?

I have a Java application built with OSGi that I want to run in different modes, say a remote & local data source. I would like to be able to build and deploy a single version so that I could run the app as a service in remote mode and then stop the service & try different things in local mode.

I am using declarative services.

Would there be a way to do this?

# app -remote
Starting app in remote mode
Disabling com.example.data.local.FileStoreDao
Enabling com.example.data.remote.MySqlDao
...

And conversely:

# app -local
Starting app in localmode
Disabling com.example.data.remote.MySqlDao
Enabling com.example.data.local.FileStoreDao
...

Or something similar.

Upvotes: 0

Views: 272

Answers (2)

Neil Bartlett
Neil Bartlett

Reputation: 23948

To quote Richard Hall:

The configuration of your application == The set of installed bundles.

The best and most maintainable solution will be to install a (slightly) different set of bundles for each of your runtime "modes". So for example, most of the bundles would be the same but you deploy either the MySqlDao bundle or the FileStoreDao. Using a tool or launcher that allows to you easily setup and launch different combinations of bundles will be critical.

If you really want to do this without changing the set of bundles, you could package both MySqlDao and FileStoreDao into a single bundle and use DS to enable/disable one or the other based on config data coming from Config Admin.

Upvotes: 3

Andres Olarte
Andres Olarte

Reputation: 4380

Not sure what framework you're using, but in Equinox, you can pass a different config file with a command line swich:

http://www.eclipse.org/equinox/documents/quickstart-framework.php

You could have two config files, and have a wrapper (java or batch file?) around the OSGi bootstrapper to select the proper config file. I have done something like this, but in my case I ended up going with two distros with different plugins, as it was simpler and it was all that I needed. Hope this helps

Upvotes: 1

Related Questions