JBoss.orgCommunity Documentation
The example application is defined by a service descriptor, which refers the Root SBB. The Root SBB does not defines child relations, which means the application is a single SBB.
To obtain the example's complete source code please refer to Section 2.2, “Mobicents JAIN SLEE SIP UAS Example Source Code”.
The service descriptor is plain simple, it just defines the service ID, the ID of the root SBB and its default priority. The complete XML is:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE service-xml PUBLIC
"-//Sun Microsystems, Inc.//DTD JAIN SLEE Service 1.1//EN"
"http://java.sun.com/dtd/slee-service-xml_1_1.dtd">
<service-xml>
<service>
<service-name>SIP UAS</service-name>
<service-vendor>org.mobicents</service-vendor>
<service-version>1.0</service-version>
<root-sbb>
<sbb-name>SIP UAS</sbb-name>
<sbb-vendor>org.mobicents</sbb-vendor>
<sbb-version>1.0</sbb-version>
</root-sbb>
<default-priority>0</default-priority>
</service>
</service-xml>
The SIP UAS Example's Root SBB is composed by the abstract class and the XML descriptor.
The class org.mobicents.slee.example.sip.SipUASExampleSbb
includes all the service logic for the example.
The javax.slee.SbbObject
's setSbbContext(SbbContext)
is used by SBBs to store the SBB's context into a class field. The SBB should take the opportunity to also store objects, such as SLEE facilities, which are reused by all service logic entities, a.k.a. SbbEntities, and are stored in the JNDI environment.
The class fields and setSbbContext(SbbContext)
method's and related code:
public void setSbbContext(SbbContext context) {
sbbContext = (SbbContextExt) context;
sipActivityContextInterfaceFactory = (SipActivityContextInterfaceFactory) sbbContext
.getActivityContextInterfaceFactory(sipRATypeID);
sleeSipProvider = (SleeSipProvider) sbbContext
.getResourceAdaptorInterface(sipRATypeID, sipRALink);
addressFactory = sleeSipProvider.getAddressFactory();
headerFactory = sleeSipProvider.getHeaderFactory();
messageFactory = sleeSipProvider.getMessageFactory();
timerFacility = sbbContext.getTimerFacility();
}
The SIP INVITE is the starting point of each instance of the service logic, its responsibility is:
Create the SIP Dialog activity, which represents the session, and attach the SbbEntity, to receive further SIP messages.
Set the session timer.
Send RINGING response back to the UAC.
Send OK response back to the UAC, to continue the session setup.
The event handler code:
// Initial request
public void onInviteEvent(RequestEvent event, ActivityContextInterface aci) {
final SbbLocalObject sbbLocalObject = this.sbbContext
.getSbbLocalObject();
aci.detach(sbbLocalObject);
final ServerTransaction serverTransaction = requestEvent
.getServerTransaction();
try {
// create dialog and attach this entity to it's aci
final DialogActivity dialog = (DialogActivity) sleeSipProvider
.getNewDialog(serverTransaction);
final ActivityContextInterfaceExt dialogAci =
(ActivityContextInterfaceExt) sipActivityContextInterfaceFactory
.getActivityContextInterface(dialog);
dialogAci.attach(sbbLocalObject);
// set timer of 60 secs on the dialog aci
timerFacility.setTimer(dialogAci, null,
System.currentTimeMillis() + 60000L, getTimerOptions());
// send 180
Response response = messageFactory.createResponse(Response.RINGING,
requestEvent.getRequest());
response.addHeader(getContactHeader());
serverTransaction.sendResponse(response);
// send 200 ok
response = messageFactory.createResponse(Response.OK, requestEvent
.getRequest());
response.addHeader(getContactHeader());
serverTransaction.sendResponse(response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
The Timer Event is received when the session timer expires, the application then sends a BYE request to the other party, requesting the session termination.
The event handler method's code:
public void onTimerEvent(TimerEvent event, ActivityContextInterface aci) {
aci.detach(sbbContext.getSbbLocalObject());
final DialogActivity dialog = (DialogActivity) aci.getActivity();
try {
dialog.sendRequest(dialog.createRequest(Request.BYE));
} catch (Exception ex) {
ex.printStackTrace();
}
}
The Root SBB XML Descriptor has to be provided and match the abstract class code.
First relevant part is the declaration of the sbb-classes
element, where the sbb class abstract name must be specified:
<sbb-classes>
<sbb-abstract-class reentrant="True">
<sbb-abstract-class-name>org.mobicents.slee.example.sip.SipUASExampleSbb</sbb-abstract-class-name>
</sbb-abstract-class>
</sbb-classes>
Then the events handled by the SBB must be specified too:
<event event-direction="Receive" initial-event="True">
<event-name>ServiceStartedEvent</event-name>
<event-type-ref>
<event-type-name>
javax.slee.serviceactivity.ServiceStartedEvent
</event-type-name>
<event-type-vendor>javax.slee</event-type-vendor>
<event-type-version>1.1</event-type-version>
</event-type-ref>
<initial-event-select variable="ActivityContext" />
</event>
<event event-direction="Receive" initial-event="True">
<event-name>InviteEvent</event-name>
<event-type-ref>
<event-type-name>javax.sip.message.Request.INVITE</event-type-name>
<event-type-vendor>net.java.slee</event-type-vendor>
<event-type-version>1.2</event-type-version>
</event-type-ref>
<initial-event-select variable="ActivityContext"/>
</event>
<event event-direction="Receive" initial-event="False">
<event-name>TimerEvent</event-name>
<event-type-ref>
<event-type-name>javax.slee.facilities.TimerEvent</event-type-name>
<event-type-vendor>javax.slee</event-type-vendor>
<event-type-version>1.0</event-type-version>
</event-type-ref>
</event>
Note that there is a single event defined as initial, which triggers the sbb logic, remaining events all happen in activities that the service instance is already attached, abstracting the application from calculating which session it handles.
Finally, the SIP11 Resource Adaptor must be specified also, otherwise SLEE won't put its SBB Interface in the SBB's JNDI Context:
<resource-adaptor-type-binding>
<resource-adaptor-type-ref>
<resource-adaptor-type-name>
JAIN SIP
</resource-adaptor-type-name>
<resource-adaptor-type-vendor>
javax.sip
</resource-adaptor-type-vendor>
<resource-adaptor-type-version>
1.2
</resource-adaptor-type-version>
</resource-adaptor-type-ref>
<activity-context-interface-factory-name>
slee/resources/jainsip/1.2/acifactory
</activity-context-interface-factory-name>
<resource-adaptor-entity-binding>
<resource-adaptor-object-name>
slee/resources/jainsip/1.2/provider
</resource-adaptor-object-name>
<resource-adaptor-entity-link>
SipRA
</resource-adaptor-entity-link>
</resource-adaptor-entity-binding>
</resource-adaptor-type-binding>