This page illustrates a simple example of a SIP Overload Control Plugin that simply accepts every request it receives for consideration.

Plugin Implementation

Code for the simple plugin implementation is given below.

package com.opencloud.slee.services.example.sipoverload;

import javax.slee.facilities.Tracer;
import org.jainslee.resources.sip.SipRequest;
import org.jainslee.resources.sip.overloadcontrol.LimiterInstruction;
import org.jainslee.resources.sip.overloadcontrol.SipOverloadControlPlugin;

public class SimpleOverloadControlPlugin implements SipOverloadControlPlugin {
    public SimpleOverloadControlPluginImpl(Tracer tracer) {
        this.tracer = tracer;
    }

    @Override
    public LimiterInstruction invoke(SipRequest request) {
        tracer.info("Handling request for overload control: " + request);
        // just accept it
        return LimiterInstruction.accept();
    }

    private final Tracer tracer;
}

SBB Implementation

Code for the SBB that manages the plugin registration is given below.

A plugin may be given references to non-transactional SBB resources such as tracers (for logging) and usage parameter sets (for stats). Consequently, it is important that plugin objects are deregistered from the SIS no later than associated service deactivation to avoid potential memory leaks if the service is later uninstalled from the SLEE.

package com.opencloud.slee.services.example.sipoverload;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.slee.ActivityContextInterface;
import javax.slee.ActivityEndEvent;
import javax.slee.CreateException;
import javax.slee.RolledBackContext;
import javax.slee.Sbb;
import javax.slee.SbbContext;
import javax.slee.facilities.Tracer;
import com.opencloud.rhino.slee.servicenodeactivity.ServiceNodeActivity;
import com.opencloud.rhino.slee.servicenodeactivity.ServiceNodeStartedEvent;
import org.jainslee.resources.sip.SipFactory;

public abstract class SimpleOverloadControlPluginSbb implements Sbb {
    @Override
    public void setSbbContext(SbbContext context) {
        tracer = context.getTracer("");
        try {
            sipFactory = (SipFactory)new InitialContext().lookup("java:comp/env/resources/sis");
        }
        catch (NamingException e) {
            throw new RuntimeException("JNDI lookup error", e);
        }
    }

    public void onServiceNodeStartedEvent(ServiceNodeStartedEvent e, ActivityContextInterface aci) {
        tracer.info("Registering overload control plugin");
        sipFactory.registerOverloadControlPlugin(new SimpleOverloadControlPluginImpl(tracer));
    }

    public void onActivityEndEvent(ActivityEndEvent e, ActivityContextInterface aci) {
        if (aci.getActivity() instanceof ServiceNodeActivity) {
            tracer.info("Deregistering overload control plugin");
            sipFactory.registerOverloadControlPlugin(null);
        }
    }


    @Override public void unsetSbbContext() {}
    @Override public void sbbCreate() throws CreateException {}
    @Override public void sbbPostCreate() {}
    @Override public void sbbActivate() {}
    @Override public void sbbPassivate() {}
    @Override public void sbbLoad() {}
    @Override public void sbbStore() {}
    @Override public void sbbRemove() {}
    @Override public void sbbExceptionThrown(Exception exception, Object event, ActivityContextInterface aci) {}
    @Override public void sbbRolledBack(RolledBackContext context) {}


    private Tracer tracer;
    private SipFactory sipFactory;
}

Deployment descriptors

The deployment descriptor for the SBB implementation illustrated above is given below:

<?xml version="1.0"?>

<!DOCTYPE sbb-jar PUBLIC
    "-//Sun Microsystems, Inc.//DTD JAIN SLEE SBB 1.1//EN"
    "http://java.sun.com/dtd/slee-sbb-jar_1_1.dtd">

<sbb-jar>
  <sbb>
    <description>Simple Overload Control Plugin SBB</description>
    <sbb-name>SimpleOverloadControlPluginSbb</sbb-name>
    <sbb-vendor>OpenCloud</sbb-vendor>
    <sbb-version>1.0</sbb-version>

    <sbb-classes>
      <sbb-abstract-class>
        <sbb-abstract-class-name>
          com.opencloud.slee.services.example.sipoverload.SimpleOverloadControlPluginSbb
        </sbb-abstract-class-name>
      </sbb-abstract-class>
    </sbb-classes>

    <event event-direction="Receive" initial-event="True">
      <event-name>ServiceNodeStartedEvent</event-name>
      <event-type-ref>
        <event-type-name>
            com.opencloud.rhino.slee.servicenodeactivity.ServiceNodeStartedEvent
        </event-type-name>
        <event-type-vendor>com.opencloud</event-type-vendor>
        <event-type-version>1.0</event-type-version>
      </event-type-ref>
      <initial-event-select variable="ActivityContext"/>
    </event>

    <event event-direction="Receive">
      <event-name>ActivityEndEvent</event-name>
      <event-type-ref>
        <event-type-name>javax.slee.ActivityEndEvent</event-type-name>
        <event-type-vendor>javax.slee</event-type-vendor>
        <event-type-version>1.0</event-type-version>
      </event-type-ref>
    </event>

    <resource-adaptor-type-binding>
      <resource-adaptor-type-ref>
        <resource-adaptor-type-name>EasySIP</resource-adaptor-type-name>
        <resource-adaptor-type-vendor>jainslee.org</resource-adaptor-type-vendor>
        <resource-adaptor-type-version>3.1.0</resource-adaptor-type-version>
      </resource-adaptor-type-ref>
      <resource-adaptor-entity-binding>
        <resource-adaptor-object-name>resources/sis</resource-adaptor-object-name>
        <resource-adaptor-entity-link>EASYSIP</resource-adaptor-entity-link>
      </resource-adaptor-entity-binding>
    </resource-adaptor-type-binding>
  </sbb>
</sbb-jar>

The deployment descriptor for a service using this SBB as a root SBB is also given below:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE service-xml PUBLIC
    "-//Sun Microsystems, Inc.//DTD JAIN SLEE Service 1.1//EN"
    "http://java.sun.com/dtd/slee-service_1_1.dtd">

<service-xml>
  <service>
    <service-name>SimpleOverloadControlPluginService</service-name>
    <service-vendor>OpenCloud</service-vendor>
    <service-version>1.0</service-version>
    <root-sbb>
      <sbb-name>SimpleOverloadControlPluginSbb</sbb-name>
      <sbb-vendor>OpenCloud</sbb-vendor>
      <sbb-version>1.0</sbb-version>
    </root-sbb>
    <default-priority>0</default-priority>
  </service>
</service-xml>

Custom Reject Responses

An overload control plugin that returns a REJECT instruction also has the option to return a custom response message to be sent to the network in place of the SIS' default overload control response. The example code below illustrates how an overload control plugin can do this.

@Override
public LimiterInstruction invoke(SipRequest request) {
    // status code should be a 3xx, 4xx, or 5xx response code
    int rejectStatusCode = XXX;

    // create response object
    SipResponse rejectResponse = ((IncomingSipRequest)request).createResponse(rejectStatusCode);

    // set any required headers as needed
    rejectResponse.setHeader(...);
    ...

    // return reject instruction with this response
    return LimiterInstruction.reject(rejectResponse);
}
Previous page
SIS Version 3.2