The data centric rules of the converged load balancer is configurable using an implementation of the org.glassfish.comms.api.datacentric.DcrPlugin interface , which is supplied as a pre-compiled Java class packaged in a JAR file. When routing a request, the converged load balancer calls the instantiated plug-in to extract the key from initial SIP and HTTP requests. The converged load balancer uses the result returned from the plug-in, to lookup the serving instance in the consistent hash.
The org.glassfish.comms.api.datacentric.DcrPlugin interface specifies two methods:
String getKey(javax.servlet.sip.SipServletRequest request, javax.servlet.sip.SipFactory sipFactory, org.glassfish.comms.api.uriutils.UriTools uriTools, org.glassfish.comms.api.telurl.TelUrlResolver telUrlResolver)
String getKey(javax.servlet.http.HttpServletRequest request, javax.servlet.sip.SipFactory sipFactory, org.glassfish.comms.api.uriutils.UriTools uriTools, org.glassfish.comms.api.telurl.TelUrlResolver telUrlResolver)
You can implement these methods to extract the key to be used for lookup in the consistent hash in the converged load balancer, for initial requests. Each method can return a non-null value, which indicates that the request matches a rule and a hash key is successfully extracted. If none of the rules match a request, a null value is returned and the hash key is extracted using default rules.
To facilitate the implementation of the data centric rules plug-in, the following entities are provided as method arguments:
TelUrlResolver — For resolving Tel URIs
UriTools— For normalizing and canonicalizing URIs
SipFactory — For converting header values to URIs and extracting the various components from such a URI
The data centric rules JAR file must contain a compiled implementation of the plug-in interface. It can also contain other application specific helper classes. It must also have a manifest that specifies the class name of this data centric rules plug-in implementation. The converged load balancer uses the manifest to identify the class that implements data centric rules plug-in. It then loads the plug-in class and creates an instance.
Here is an example Java class file that specifies data centric rules:
package mydcr; import org.glassfish.comms.api.datacentric.DcrPlugin; import javax.servlet.http.HttpServletRequest; import javax.servlet.sip.SipFactory; import javax.servlet.sip.SipServletRequest; import javax.servlet.sip.SipURI; import org.glassfish.comms.api.telurl.TelUrlResolver; import org.glassfish.comms.api.uriutils.UriTools; public class MyDcrPluginImpl implements DcrPlugin{ public String getKey(SipServletRequest request, SipFactory sipFactory, UriTools uriTools, TelUrlResolver telUrlResolver) { String key = null; String method = request.getMethod().toUpperCase(); if(method.equals( "PUBLISH" ) || method.equals( "INVITE" ) || method.equals( "CANCEL" )){ key = SipURI.class.cast(request.getTo().getURI()).getUser(); } else if (method.equals( "REGISTER" ) || method.equals( "SUBSCRIBE" )){ key = SipURI.class.cast(request.getFrom().getURI()).getUser(); } System.out.println("MY DCR PLUGIN - Key extracted from SIP request : " + key); return key; } public String getKey(HttpServletRequest request, SipFactory sipFactory, UriTools uriTools, TelUrlResolver telUrlResolver) { String key = request.getParameter( "j_username" ); System.out.println("MY DCR PLUGIN - Key extracted from HTTP request : " + key); return key; } }
After you have written the data centric rules class, follow these steps:
Compile the data centric rules class as shown in the following example command. You must include ssa-api.jar, javaee.jar, and comms-appserv-api.jar in the classpath. The classes directory must exist.
javac -classpath as-install/lib/ssa-api.jar:as-install/lib/javaee.jar:as-install/lib/comms-appserv-api.jar -d classes src/mydcr/MyDcrPluginImpl.java |
Write the manifest file. For example:
Manifest-Version: 1.0 Dcr-Plugin-Class: mydcr.MyDcrPluginImpl
Create the data centric rules JAR file. For example:
jar -cvfm mydcrplugin.jar mymanifest -C classes mydcr/MyDcrPluginImpl.class |
Set the data centric rules file using the asadmin set-dcr-file command. Refer the instructions at Setting the Data Centric Rules File for a Converged Load Balancer.