Monday, April 20, 2009

RHQ and Jopr plugins: What about <T> ?

When writing a Plugin for RHQ, JBoss ON and Jopr (or for completeness: Embedded Jopr, you will run into Generic types for ResourceComponent and ResourceDiscoveryComponent. And I am sure you have often wondered what the T in ResourceComponent<T> should be.

The following diagram tries to help here. We have two ResourceTypes that from a Parent-Child relationship e.g. a Database and a DatabaseTable.

If you don't know what parent you will run in, you can just leave the generic bit away, as in ParentDiscovery and Parent in the diagram. This is usually the case for ResourceTypes of the Server category that live in their own plugin. One could also use the platform component as parent if its clear that the plugin will only run as a child of the platform, but never e.g. within another resource like a JBossAS.


Children of this server Parent will set the T to the parent component. This allows them to e.g. access the parent ResourceContext.

For examples of all this, check the Jopr source code, which contains many examples.

No comments: