Domanda

I have OSGi modular system in which i have the following components:

  • Some specific protocol instance implementation, which represent a connection via specfic protocol to the specific server (instantiated per connection service)
  • Some specific protocol instances manager service, creating and pre-configuring instances on demand (multiple singletone services from, normally, different bundles)
  • Connection manager which aggregates protocol manager services and asking them to provide protocol instances when needed (single singletone service)

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 ProtocolInstances 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?

È stato utile?

Soluzione

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:

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top