declarative-services

Dynamically setting target property in OSGi Reference annotatation

拜拜、爱过 提交于 2020-01-06 02:32:05
问题 After reading an article on Reference target (and corresponding properties), I still don't understand how to retrieve a service, when target is set at runtime (typically target and properties are set at compile time and evaluated by SCR at runtime). Let's say there are three service implementations defining @Property(name="type", value="csv") , @Property(name="type", value="xls") and @Property(name="type", value="pdf") , respectively. And one consumer with: //@Reference(target="(type=%runtime

Activating an OSGI LogListener before other services?

▼魔方 西西 提交于 2020-01-04 11:41:40
问题 I am writing a OSGI-based desktop application, using Apache Felix, Declarative Services and Maven. It's going to use JavaFX, so I'm using Drombler FX too. In the bundles I develop, I'd like to use an appropriate logging mechanism, and I'm currently trying to make Apache Felix Log work. I have no problem getting a LogService but this is not sufficient to make output appear on the console. The word on the net is that Everit's osgi-loglistener-slf4j will do the job and – sure enough – after osgi

Activating an OSGI LogListener before other services?

回眸只為那壹抹淺笑 提交于 2020-01-04 11:40:05
问题 I am writing a OSGI-based desktop application, using Apache Felix, Declarative Services and Maven. It's going to use JavaFX, so I'm using Drombler FX too. In the bundles I develop, I'd like to use an appropriate logging mechanism, and I'm currently trying to make Apache Felix Log work. I have no problem getting a LogService but this is not sufficient to make output appear on the console. The word on the net is that Everit's osgi-loglistener-slf4j will do the job and – sure enough – after osgi

How to override bnd Require-Capability generated from DS annotation?

半世苍凉 提交于 2019-12-24 05:49:26
问题 I have a bundle with an "optional" Component : It should be started if at leat one service of type X exist, and deactivated when the last service is unregistered. This component is "optional": It doesn't matter if X is registered or not, or if my component is activated or not. It's just an helper for managing instances of X. My component is declared like this : @Component public class MyManager { @Reference(cardinality=AT_LEAST_ONE) public void addService(X service) { .. } } However, bnd

OSGi: What happens if not to unget service

时光怂恿深爱的人放手 提交于 2019-12-23 16:28:09
问题 This is the way how I get OSGi service: ServiceReference reference = bundleContext.getServiceReference(Foo.class.getName()); Foo foo=(Foo) bundleContext.getService(reference); What happens if I don't do bunldeContext.ungetSerivice(reference) when I finished with service: If I registered service manually, for example in activator If I use declarative service and it is Singleton 回答1: The OSGi framework maintains a use count of each service for your bundle. If your bundle does not unget the

Programmatically adding declarative services

删除回忆录丶 提交于 2019-12-23 15:26:17
问题 Is it possible to add declarative services using some kind of api? A little background: I have a server application based on dynamic scripts (they can be added, edited or removed at any time). Those scripts have dependencies to OSGi services and possibly each other. Whenever a script gets edited, the script gets compiled to javascript, and its dependencies are detected. At that point, I'd like to (re)register it as a declarative service, so it will be activated / deactivated when its

Eclipse RCP 4 use bundle via declarative service

断了今生、忘了曾经 提交于 2019-12-22 06:55:33
问题 I have written an OSGi bundle to use it in my eclipse 4 rcp application. The usage of the service works fine if I add the dependencies, register these service in my activator and inject it in my class. In activator IUserService service = new TestUserService(); context.registerService(IUserService.class.getName(), service, null); In my class @Inject IUserService service; service.getSth(); I read that using bundles via declarative services should be the better way. So changed my implementation.

How do you properly implement a ManagedServiceFactory as Decalarative Service in OSGi?

风格不统一 提交于 2019-12-21 21:39:11
问题 I have services that need to be created on a per-configuration base, each of which relies on an external resource and thus should manage it's own lifcycle (i.e. (de)register the service). Thus implementing these as DS and let SCR spawn multiple instances does not work. One can implement a bundle that registers a ManagedServiceFactory to accomplish this task perfectly (see my previous post). But as a consequence, if the factory depends on several other services, you need to start tracking

Dynamic target for declarative service in OSGI

橙三吉。 提交于 2019-12-20 04:13:43
问题 Given a consumer which uses a service, how can this consumer select a specific provider dynamically using declarative service ? Example Service.java public interface Service { public void do(); } Provider1.java public class Provider1 implements Service { @Override public void do(){ //a way } } Provider2.java public class Provider2 implements Service { @Override public void do(){ //another way } } Consumer.java public class Consumer { private Service myService; protected void bindService

Osgi Equinox enable component from external bundle

不想你离开。 提交于 2019-12-13 04:33:28
问题 Given this scenario: Bundle A: component 1A (enabled:false) Bundle B: component 2B How can i enable component 1A from Bundle B or Component 2B? I've tried to do it by using componentContext, dsContext.enableComponent("1A"); but it seems to work only with services in the same bundle. 回答1: Your using a mechanism that is intended for management and it seems you want to use it on application level. Declarative services should be enabled/disabled through their dependencies, or through a domain