Hivemind for Beginners

hivemind configuration file location

Hivemind is configured through an xml file called hivemodule.xml. Tapestry configures hivemind to look for this file in three different places. All can be used simultaniously or alternatively:

  •  /META-INF 
    hivemind will load all
     /META-INF/hivemodule.xml 
    on the classpath. this includes all classes directories and jar files.
  •  <context>/WEB-INF/ 
  •  <context>/WEB-INF/<app-name>/ 
    practical if you have more than one tapestry application in the same context and you don't wish them to share certain hivemind configuration.

creating a service

Here is a simple example of the

 hivemodule.xml 

.

<?xml version="1.0"?>
<module id="moduleid" version ="1.0.0" package="package.name">
  <service-point id="ServiceId"   
    interface="interface.name.relative.to.package.or.absolute">
    <invoke-factory>

      <construct
     class="implementation.class.name.relative.to.package.or.absolute"/>

    </invoke-factory>
  </service-point>
</module>

alternativley, you can separate <service-point> as an empty element, and use the <invoke-factory> element in an...

<implementation service-id="ServiceId">
  <invoke-factory...
</implementation>

To use your service in tapestry components or pages you "inject" it, using the following syntax (in the .jwc or .page file)

<inject object="service:moduleid.ServiceId" property="nameOfProperty"/>

If you want to use annotations, use:

@InjectObject("service:moduleid.ServiceId")
public abstract ServiceInterface getXXX();

notes

  1. the above syntax creates a singleton service, which means, your service will be instanciated once and will be used from all threads of the application. Hivemind offers 4 instaciation models. To use them, use the model attribute of the <invoke-factory> element. See here for details.
  2. All module/services names are case sensitive.

Referencing other files from hivemodule.xml

<sub-module descriptor="relative.path.to.another.module.description.xml"/>
  • No labels