Miroslav Nachev wrote:
Hello Clement,
In traditional way if I have some OSGi Service which have to be used
in some class (POJO Bean) I MUST pass this service to one or more
classes as parameter. Then when the time for using of that service is
on the service can be unavailable. Similar problem I will have when I
want to stop my bundle. That's why if iPOJO Annotations allow some
service to be used inside of the bundle will be perfect. This can be
done with Proxy. When I create some new object with new JavaClass(...)
and in that object I am declared some OSGi Service using iPOJO
Annotation, that service will point to some Proxy which proxy will try
to get the service on request. This will guarantee that the service is
actual independently how much the service is restarted and updated. In
traditional way the application must track all service states and etc.
Passing the service as parameter complicate the things.
Did you have some plans iPOJO to support the above scenario?
I am not totally sure I understand your scenario, but it sounds like you
want a proxy that only tries to get the service when someone tries to
use it. iPOJO does not support this type of scenario automatically, but
it is fairly easy to achieve. Assume you have the following service:
public interface Foo {
void doFoo();
}
You could create a component like this:
import org.apache.felix.ipojo.temporal.Requires;
public class MyFooProxy implements Foo {
@Requires
private Foo m_foo;
public void doFoo() {
m_foo.doFoo();
}
}
The dependency on m_foo is declared to be temporal, which means that it
will only try to get the service when it is used. If one is not
available, it will eventually timeout and throw an exception. Now you
should be able to pass this "proxy" component to you components and they
will be able to use the service on demand.
-> richard
Regards,
Miro.
clement escoffier wrote:
2008/10/14 Stuart McCulloch <[EMAIL PROTECTED]>
2008/10/14 Miroslav Nachev <[EMAIL PROTECTED]>
Hi,
This is very interesting and I will try it but this answer is half
of my
question. I am interesting how to get some service in my code, not in
another service. For example:
public class SomePOJOBean
{
@Requires
??? how to pass some parameters to the service (passive, dynamics)
private FooService foo;
}
How can be implemented the above scenario?
So, as I understand, you don't want (global) services but your own
(customized) service. As you're configuring the service, this service
should
not be available to other consumers. In iPOJO you can do this by using
composites (the new documentation is coming soon). Composites assert
that
your service is isolated. However, composites does not allows you to
declare
those services in your code.
Well, iPOJO injects components - but these are not necessarily
services.
Clement's example happened to provide a service, but this isn't
mandatory.
You do need to tell iPOJO about your code somehow, and in iPOJO this is
done
by marking them as components which iPOJO injects as necessary. (I'm
sure
Clement can explain this better than me!)
Service providing is (of course) not necessary. Your component can be a
component that does not provide a service (like a GUI).
Clement
There are also alternative ways to inject OSGi services, using
(non-OSGi)
dependency injection frameworks:
* Spring has the Spring-DM extension, but I don't know if it fully
supports
configuration via annotation.
http://www.springframework.org/osgi/
* Guice has the peaberry extension, which I work on - in this case the
service configuration is done in the binding module, not the
annotation (I
did look at doing annotation configuration, but this rapidly becomes a
management nightmare)
http://code.google.com/p/peaberry/
HTH
Regards,
Miro.
clement escoffier wrote:
Hi,
iPOJO provides such annotations as:
@Component
@Provides // Provides a service
public class Foo implements Service {
@Requires // Service dependency
private HelloService hello;
...
}
You can find further info at
http://felix.apache.org/site/how-to-use-ipojo-annotations.html
About parameters, the iPOJO's way is to inject instance property.
Those
fields will be set before the execution of your constructor
(between the
super constructor invocation and the constructor code), and your
constructor
can use those fields, such as in:
@Component
@Provides // Provides a service
public class Foo implements Service {
@Property
private String myString;
@Requires // Service dependency
private HelloService hello;
public Foo() {
// Can use myString here as well as hello
}
...
}
Regards,
Clement
2008/10/14 Miroslav Nachev <[EMAIL PROTECTED]>
Hi,
I would like to ask you about some way in Felix to export
services in
more
easy way only with annotation like in EJB3.x: @Stateful, @Stateless,
@Remote, @Local, @EJB, etc.
In my opinion the best way this to be done is inside of the OSGi
framework.
Then all resources (services) can be exported to the framework just
with
annotation. The same for needed services. What about if before to
get
some
service we have to pass some parameters to the constructor?
Regards,
Miro.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Cheers, Stuart
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]