[jboss-dev-forums] [JBoss AS7 Development] - Re: META-INF/services for module extensions - question/issue
David Lloyd
do-not-reply at jboss.com
Thu Sep 8 09:59:38 EDT 2011
David Lloyd [http://community.jboss.org/people/dmlloyd] created the discussion
"Re: META-INF/services for module extensions - question/issue"
To view the discussion, visit: http://community.jboss.org/message/625522#625522
--------------------------------------------------------------
> Dan Sirbu wrote:
>
> Hi Brian,
>
> I have taken a break from the subject and after giving multiple taughts I still think there is a "flaw". Here is my view based on my current understanding:
>
> I can have, let's say, two kind of modules: one that implements the module ifc thus an extension && one that does not. Let's name : ModuleExtension the one that has defined an interface towards the : org.jboss.as.controller.Extension ifc; and let's name Module the one that does not have such a definition.
> What I understand is that the ModuleExtension by design should not have any other service defined - which is OK. And if it does it is discarded - which again is OK.
That's not really true. Neither JBoss Modules nor JBoss AS will actively browse modules for services as this would be a significant performance drain to little advantage. So services are never "discarded", they're simply ignored until someone asks for them.
> Dan Sirbu wrote:
>
> What I also understand is that the Module by design can have a service defined. Now the service defined into Module is available to any war, rar, etc... file that is deployed and have somehow a dependecy defined towards that Module (see prev dicussions on how one can achieve that). And the war file, for example, uses the 'regular' Service.load instead of using the jboss-module one - which is what one would expect.
> So far so good.
I see a couple items of confusion here. First any module which provides an AS extension must be in the static module repository, because extensions are initialized during AS boot and there are no deployments at this early stage. Second, the ServiceActivator interface (which is what I assume you're referring to as having a "service defined") is only read by deployment descriptors, so any ServiceActivators in a static modue will be ignored. *However*, an extension module can define services through other APIs so this is not really a limitation.
> Dan Sirbu wrote:
>
> Now, let's say that ModuleExtension needs Module for whaterver reason. Then one would go into "module.xml" of ModuleExtension and add a dependency towards that Module. Then, what I would expect as behaviour is that the Module service should be available to ModuleExtension via the 'regular' Service.load and not via the jboss-module service loader !
Okay here's another point of confusion. The JBoss Modules service loader *is* the "regular" ServiceLoader, just wrapped up in a helper which provides the module's class loader for you. This point of confusion seems to be masking the *real* problem. If you want your extension module to "see" the service provided by its module dependency, you simply add 'services="import"' to the dependency element for that dependency. If you want other modules which import the extension module to "see" the services provided by that dependency, then instead use 'services="export"'. That's it; this will make it work whether you're using Module.loadService() or ServiceLoader.
> Dan Sirbu wrote:
>
> Hi Brian,
>
> Since Module is not defined as a jboss-module extension, then the ModuleExtension should be able to have access to the Module service interface via the 'regular' Service.load and that because, to me, the Module should be in the classpath of the ModuleExtension one such a dependency has been created. There is no real need to go towards jboss-module service loader - at least I do not see one.
As I have said, the two are one and the same.
> Dan Sirbu wrote:
>
> If a war file, for example, would need access to ModuleExtension it would add a dependecy towards it. The dependency should ensure that the objects defined with the ModuleExtension become visible to the war file including the ones from the Module meaning that the classpath of the ModuleExtension would be made available to the war. At least that is I think a dependency should do.
This is only done when the service is explicitly declared like above. If we did not filter these by default, then every module would see tons and tons of extra services which may or may not actually be desired and might actually be completely wrong. However we *do* allow services to be shared across dependencies already as I've described, which neatly solves the problem.
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/625522#625522]
Start a new discussion in JBoss AS7 Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20110908/a399b012/attachment.html
More information about the jboss-dev-forums
mailing list