I have OSGi modular system in which i have the following components:
They are packaged into OSGi bundles as follows:
`-ConnectionManager
`-ConnectionManager.class
`-IrcProtocol
`-IrcProtocolManagerService.class
`-IrcProtocolInstance.class
`-XMPPProtocol
`-XMPPProtocolManagerService.class
`-XMPPProtocolInstance.class
The ConnectionManager
is annotated with
@Provides
@Instantiate
@Component
And implements Subscriber
interface, which enbles it with ability to send and listen on messages delivered trhough some sort of typed Event Admin
.
Each *ProtocolManager
is annotated with
@Provides
@Instantiate
@Component
And implements ProtocolManager
interface which enables it's discovery by ConnectionManager
service listener.
Each *ProtocolInstance
is annoteted with
@Provides
@Component
And implements Subscriber
interface. Also it implements ProtocolInstance
interface, which offers such generic connection operations as connect()
and disconnect()
.
The problem here is that ProtocolInstance
s are created by hand, with new
operator, inside of ProtocolManager
, not by @Instantiate
annotation trigger, and because of that - do not participate in iPOJO service publishing, despite it's @Provides
annotation.
The question: how to correctly (and preferably declaratively, with annotations) publish this programmatically created ProtocolListener
services without manually diving into raw OSGi service publication (at least outside some sort of factory, maybe)? Or, probably, how to re-structure my system in order to have it better playing along with the unspoken iPOJO guidelines?
iPOJO does not support creating object with 'new'. Indeed, an iPOJO instance is not only this objects, but also the container wrapping it.
However, you have two solutions: