You probably want to use Java SE ServiceLoader, and then on the provider
and consumer bundles apply Service Loader Mediator [1] metadata.

This means your code is Java SE compliant as a library, but when deployed
in OSGi will get treated and backed by service registry and be wired in a
OSGi safe manner.

Check the Apache Aries SpiFly implementation of SLM [2].

[1] https://osgi.org/specification/osgi.cmpn/7.0.0/service.loader.html
[2] http://aries.apache.org/modules/spi-fly.html

On Thu, Jul 12, 2018 at 11:03 AM, João Assunção via osgi-dev <
osgi-dev@mail.osgi.org> wrote:

> Hello all,
>
> I'm currently trying to implement a facade for a metrics library and one
> of the objectives is to make its usage agnostic of the runtime environment.
> At my place, we have some components that are mainly used in the context of
> an OSGi container but can also be used in plain Java applications. I want
> to have three implementations of the facade where one makes use of an
> OSGi service, the other is a plain java library and the third a no-op.  In
> essence, I want the usage of this facade to be similar to SLF4J. While
> replicating the mechanism used in SLF4J I remembered someone in this
> mailing list saying that the way SLF4J binds to the implementations is a
> hack and not recommended. I agree with the hack part but to me, as a user,
> it works quite well.
> If anyone could suggest better approaches I would be very grateful.
>
> PS:
> This is what I'm trying to achieve:
>
> ....
>> private final Counter aCounter = MetricsFactory.getCounter("aCounter");
>> ...
>
>
>
> Thank you.
>
> João Assunção
>
> Email: joao.assun...@exploitsys.com
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com
>
>
>
> _______________________________________________
> OSGi Developer Mail List
> osgi-dev@mail.osgi.org
> https://mail.osgi.org/mailman/listinfo/osgi-dev
>



-- 
*Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile>
 (@rotty3000)
Senior Software Architect *Liferay, Inc.* <http://www.liferay.com>
 (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> (@OSGiAlliance)
_______________________________________________
OSGi Developer Mail List
osgi-dev@mail.osgi.org
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to