JBoss.orgCommunity Documentation

Chapter 4. Source Code Overview

4.1. Source Code Overview: Sbb
4.2. Source Code Overview: JMX Client

Important

To obtain the example's complete source code please refer to Section 2.2, “Mobicents JAIN SLEE SleeConnectivity Example Source Code”.

SBB descriptor is very simple. Its only purpose is to define SBB abstract class and event handler. Abstract class is defined as follows:



        <sbb-name>SleeConnectivitySbb</sbb-name>
        <sbb-vendor>org.mobicents</sbb-vendor>
        <sbb-version>1.0</sbb-version>

        <sbb-classes>
            <sbb-abstract-class>
                <sbb-abstract-class-name>
                    org.mobicents.slee.service.SleeConnectivitySbb
                </sbb-abstract-class-name>
            </sbb-abstract-class>
        </sbb-classes>
            
            

Handler definition looks as follows:



        <event event-direction="Receive" initial-event="True">
            <event-name>CustomEvent</event-name>
            <event-type-ref>
                <event-type-name>org.mobicents.slee.service.connectivity.Event_1</event-type-name>
                <event-type-vendor>org.mobicents</event-type-vendor>
                <event-type-version>1.0</event-type-version>
            </event-type-ref>
            <initial-event-select variable="ActivityContext" />
        </event>
            
            

JMX Client is defined by two elements: XML descriptor and POJO class.

XML descriptor is very simple. It looks as follows(jboss-beans.xml):



<?xml version="1.0" encoding="UTF-8"?>

<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:jboss:bean-deployer:2.0">

    <bean name="SleeConnectionTest"
        class="org.mobicents.example.slee.connection.SleeConnectionTest">
        <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(
            name="org.mobicents.slee:name=SleeConnectivityExample",exposedInterface=
            org.mobicents.example.slee.connection.SleeConnectionTestMBean.class
                ,registerDirectly=true)
        </annotation>       
    </bean>

</deployment>
        
            

Descriptor has following elements present:

Client contract is defined by implemented interface class, that is org.mobicents.example.slee.connection.SleeConnectionTestMBean

Concrete implementation can be found in org.mobicents.example.slee.connection.SleeConnectionTest class.



            
        public void fireEvent(String messagePassed) {
        // depending on deployment it does following:
        // 1. lookup RA and make RMI calls through it
        // 2. lookup local Bean, which makes direct calls to container!
        logger.info("Attempting call to SleeConnectionFactory.");
        try {
            InitialContext ic = new InitialContext();
            // this is call to local JNDI space, private, it cant be accessed
            // from other JVM
            SleeConnectionFactory factory = (SleeConnectionFactory) ic
                    .lookup("java:/MobicentsConnectionFactory");
            SleeConnection conn1 = null;
            try {
                conn1 = factory.getConnection();
                ExternalActivityHandle handle = conn1.createActivityHandle();
                EventTypeID requestType = conn1.getEventTypeID(eventName,
                        eventVendor, eventVersion);
                CustomEvent customEvent = new CustomEvent();
                customEvent.setMessage(messagePassed);
                logger.info("The event type is: " + requestType);
                conn1.fireEvent(customEvent, requestType, handle, null);
            } finally {
                if (conn1 != null)
                    conn1.close();
            }
        } catch (Exception e) {
            logger.error("Exception caught in event fire method!", e);
        }
    }