Definition of annotations streamlining the definition of GBeanInfos.

All annotations are in the org.apache.geronimo.gbean.annotation package.

@GBean

optional annotation defining the name and j2eeType of a GBean. If this annotation is not specified, then the default name is assumed to be
the class (simple) name and the default j2eeType is GBean.

@Priority

optionalannotation defining the priority of a GBean.

@ParamSpecial

annotation defining a GBean special attribute to be injected.

@ParamAttribute

annotation defining the GBean attribute to be injected.

@ParamReference

annotation defining the GBean reference to be injected.

@Persistent

annotation for setter methods turning the corresponding GBean attributes into persistent attributes.

@Reference

annotation for setter methods turning the corresponding GBean attribute into a GBean reference.

Note that at most one constructor must be annotated with @ParamSpecial, @ParamAttribute or @ParamReference.

Examples

@GBean
public class AuthConfigProviderGBean implements GBeanLifecycle {

    private final String registrationID;

    public AuthConfigProviderGBean(@ParamAttribute(name = "config") String config, @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) 
    throws AuthException, JAXBException, IOException, ParserConfigurationException, SAXException, XMLStreamException {

        ClassLoaderLookup classLoaderLookup = new ConstantClassLoaderLookup(classLoader);

        String messageLayer = null;
        String appContext = null;

        AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
        ConfigProviderType configProviderType = JaspiXmlUtil.loadConfigProvider(new StringReader(config));
        AuthConfigProvider authConfigProvider = JaspiUtil.wraptAuthConfigProvider(configProviderType, classLoaderLookup);
        registrationID = authConfigFactory.registerConfigProvider(authConfigProvider, messageLayer, appContext, null);
    }

    public void doStart() throws Exception {
    }

    public void doStop() throws Exception {
        AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
        authConfigFactory.removeRegistration(registrationID);
    }

    /**
     * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
     */
    public void doFail() {
    }
}
@GBean
public class JmxDiscoveryPublisher implements GBeanLifecycle {

    private final URI service;
    private final DiscoveryAgent discoveryAgent;

    public JmxDiscoveryPublisher(@ParamAttribute(name = "nodeName")String nodeName,
                                 @ParamAttribute(name = "clusterName")String clusterName,
                                 @ParamAttribute(name = "protocol")String protocol,
                                 @ParamAttribute(name = "urlPath")String urlPath,
                                 @ParamAttribute(name = "discoveryType")String discoveryType,
                                 @ParamReference(name = "DiscoveryAgent")DiscoveryAgent discoveryAgent,
                                 @ParamReference(name = "RMIRegistryService")RMIRegistryService rmiRegistryService
    ) throws URISyntaxException, IOException {
        this.discoveryAgent = discoveryAgent;
        String query = null;
        if (nodeName != null && nodeName.length() > 0) {
            query = "node=" + nodeName;
        }
        if (clusterName != null) {
            query = (query == null? "": query + "&") + "cluster=" + clusterName;
        }
        service = new URI(discoveryType + ":" + protocol, null,  rmiRegistryService.getHost(), rmiRegistryService.getPort(), "/" + urlPath , query, null);
        discoveryAgent.registerService(service);
    }

    public void doStart() throws Exception {
    }

    public void doStop() throws Exception {
        discoveryAgent.unregisterService(service);
    }

    public void doFail() {
        try {
            doStop();
        } catch (Exception e) {
            //ignore
        }
    }
}
  • No labels