Writing a Custom JGroups Protocol

From NovaOrdis Knowledge Base
Revision as of 15:41, 6 June 2016 by Ovidiu (talk | contribs) (→‎Deployment)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Internal

Overview

This article explains how to write a simple custom JGroups protocol and deploy it as part of a WildFly JGroups stack. The protocol used as example is named “INSPECT”, it looks at the MSG type JGroups events and displays their body in the logs. This protocol was developed as an example only, a production version will require additional error checking and boundary condition handling. INSPECT was developed starting from the EXAMPLE protocol, shipped with JGroups.

Source

https://github.com/NovaOrdis/playground/tree/master/jboss/jgroups/custom-protocol

Protocol Class Package Name

The protocol class must belong to the “org.jgroups.protocols” package, otherwise the protocol instance creation will fail when deployed as part of a WildFly protocol stack. This is because the WildFly class in charge with instantiating the protocol (org.jboss.as.clustering.jgroups.subsystem. JGroupsSubsystemXMLReader_1_1 or equivalent) will attempt to use org.jgroups.conf.ProtocolConfiguration.protocol_prefix as package name for the fully qualified class name. org.jgroups.conf.ProtocolConfiguration.protocol_prefix is hardcoded to “org.jgroups.protocols”.

Build

mvn clean package

Deployment

The custom protocol JAR can be deployed by copying the JAR into $JBOSS_HOME/modules/system/layers/base/org/jgroups/main and modifying the JGroups module descriptor $JBOSS_HOME/modules/system/layers/base/org/jgroups/main/module.xml as follows:

<module xmlns="urn:jboss:module:1.1" name="org.jgroups">
    ...
    <resources>
        ...
        <resource-root path="jgroups-custom-protocol.jar"/>
    </dependencies>
</module>

Note that if the JBoss instance was patched, the modifications described above must go where the latest JGroups module version is installed (example $JBOSS_HOME/modules/system/layers/base/.overlays/layer-base-jboss-eap-6.4.6.CP/org/jgroups/main

For more details about the patching process, see EAP Patching.