felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Clement Escoffier <clement.escoff...@gmail.com>
Subject Re: Proxy as iPOJO fallback service
Date Thu, 17 Oct 2013 19:10:54 GMT
Hi,

On 17 oct. 2013, at 19:32, Hendrik Nunner <hendrik.nunner@next-audience.com> wrote:

> Dear Felix Team,
> 
> we came across an unsupported feature we would like to use, while using iPOJO service
injection. When defining a service via the @Requires annotation it is possible to define a
fallback service at the same time ("defaultclass" being a Class object). When this property
is left out, iPOJO provides a default service using a Java Proxy (org.apache.felix.ipojo.handlers.dependency.NullableObject).
This proxy delivers hard-coded default values (0 or false) according to the requested return
type.
> 
> Our goal is to use a custom Proxy as fallback service. This proxy can generically handle
methods for different use cases. This would be great, for example, for services that are not
able to provide certain aspects of their functionality by throwing an exception, whereas other
aspects can be implemented by returning a default value different to 0 or false.

Isn't this 'default-implementation' (http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html#optional-scalar-dependencies-no-service-actions)
? Default-implementation are an implementation of the service interface used when no provider
are available. This implementation is specified in the @Requires annotation. Unlike nullable
object, default-implementation can contain code. 

For example:

@Requires(optional=true, nullable=true)
private LogService nullableLog;

@Requires(optional=true, default_implementation=MyImplementationOfLogService.class)
private LogService diLog;

//...

nullableLog.log(LogService.INFO, "message"); // does nothing, a nullable do not have a real
logic
diLog.log(LogService.INFO, "message"); // Can, for example, print the message on System.out



> 
> One idea to achieve this, could be by implementing a new iPOJO interface extending InvocationHandler
(with org.apache.felix.ipojo.handlers.dependency.NullableObject being a subclass of). Another
idea would be by defining another property for the @Requires annotation, which will be checked
and handled inside org.apache.felix.ipojo.handlers.dependency.Dependency.start().
> 
> Maybe you guys came across this request before and came up with a solution already. Or
mabye you have different ideas to achieve this feature. We would be more than happy to discuss
this idea with you or implement this feature ourselves.
> 

I think that what' you are trying to implement is close to default-implementation. 

However, I recently discussed with another iPOJO user about the ability to customize the object
injected when no services are available. This request have been postponed until we analyze
more deeply the use cases. If you come up with such use case, we would be very happy to discuss
such feature.

Best regards,

Clement


> Best regards,
> Hendrik Nunner


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message