Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSGI service vs. Singleton?

Tags:

osgi

I am a beginner to OSGI and I am wondering if someone can enlighten me about the difference between creating OSGI service vs singleton pattern. For example, suppose I have a bundle core which provides IService, and multiple bundles that needs to access this. I can:

  1. register a service in the core-bundle, in which the plugins can access
  2. provide a singleton class, which provides the service

Using OSGI service seems to be quite cumbersome; and since the plugins have to depend on Core anyways (to get the interface), what's the advantage of using OSGI service?

like image 649
Adrian Pang Avatar asked Sep 27 '12 17:09

Adrian Pang


1 Answers

You can manage the life cycle (deploy new version of the service, concurrently run multiple versions etc) of a service but you can't manage the life cycle of singleton without restarting the JVM (even with restart you can just have 1 version available at any point of time).

like image 194
Aravind Yarram Avatar answered Dec 07 '22 13:12

Aravind Yarram