JBoss.orgCommunity Documentation

Chapter 2. Resource Adaptor Type

2.1. Activities
2.2. Events
2.3. Activity Context Interface Factory
2.4. Resource Adaptor Interface
2.5. Restrictions
2.6. Sbb Code Examples

Diameter Sh-Server Resource Adaptor Type is defined by Mobicents team as part of effort to standardize RA Types.

Diameter Sh-Server Type 2.4.2-SNAPSHOT defines the following Activities:

All activities define methods required to properly function and expose necessary information to JAIN SLEE services. Sh Server Activity is defined as follows:



    public UserDataAnswer createUserDataAnswer(byte[] userData);
    public UserDataAnswer createUserDataAnswer(long resultCode, 
        boolean isExperimentalResult);
    public UserDataAnswer createUserDataAnswer();
    public ProfileUpdateAnswer createProfileUpdateAnswer(long resultCode, 
        boolean isExperimentalResult);
    public ProfileUpdateAnswer createProfileUpdateAnswer();
    public SubscribeNotificationsAnswer createSubscribeNotificationsAnswer();
    public SubscribeNotificationsAnswer createSubscribeNotificationsAnswer(long resultCode, 
        boolean isExperimentalResult);
    public void sendUserDataAnswer(UserDataAnswer message) throws IOException;
    public void sendProfileUpdateAnswer(ProfileUpdateAnswer message) throws IOException;
    public void sendSubscribeNotificationsAnswer(SubscribeNotificationsAnswer message)
        throws IOException;
    
public UserDataAnswer createUserDataAnswer(byte[] userData);

This method creates a UserDataAnswer using the given parameter to populate the User-Data AVP. The Result-Code AVP is automatically set to SUCCESS. If there is no request of this type received, this method returns null.

public UserDataAnswer createUserDataAnswer(long resultCode, boolean isExperimentalResult);

This method creates a UserDataAnswer containing a Result-Code or Experimental-Result AVP populated with the given value. If isExperimentalResultCode is true, the resultCode parameter will be set as ExperimentalResultAvp AVP, if it is false the result code will be set in a Result-Code AVP. If there is no request of this type received, this method returns null.

public UserDataAnswer createUserDataAnswer();

This method creates an empty UserDataAnswer that will need to have AVPs set on it before being sent.If there is no request of this type received, this method returns null.

public ProfileUpdateAnswer createProfileUpdateAnswer(long resultCode, boolean isExperimentalResult);

This method creates a ProfileUpdateAnswer containing a Result-Code or Experimental-Result AVP populated with the given value. If isExperimentalResultCode is true, the resultCode parameter will be set in a ExperimentalResultAvp AVP, if it is false the result code will be set in a Result-Code AVP.If there is no request of this type received, this method returns null.

public ProfileUpdateAnswer createProfileUpdateAnswer();

This method creates an empty ProfileUpdateAnswer that will need to have AVPs set on it before being sent.If there is no request of this type received, this method returns null.

public SubscribeNotificationsAnswer createSubscribeNotificationsAnswer();

This method creates an empty SubscribeNotificationsAnswer that will need to have AVPs set on it before being sent.If there is no request of this type received, this method returns null.

public SubscribeNotificationsAnswer createSubscribeNotificationsAnswer(long resultCode, boolean isExperimentalResult);

This method creates a SubscribeNotificationsAnswer containing a Result-Code or Experimental-Result AVP populated with the given value. If there is no request of this type received, this method returns null.

public void sendUserDataAnswer(UserDataAnswer message) throws IOException;

This method sends a UserDataAnswer to the peer that sent the UserDataRequest.

public void sendProfileUpdateAnswer(ProfileUpdateAnswer message) throws IOException;

This method sends a ProfileUpdateAnswer to the peer that sent the ProfileUpdateRequest.

public void sendSubscribeNotificationsAnswer(SubscribeNotificationsAnswer message) throws IOException;

This method sends a SubscribeNotificationsAnswer to the peer that sent the SubscribeNotificationsRequest.

Sh Server Notification Activity is defined as follows:



    public ShServerMessageFactory getServerMessageFactory();
    public void sendPushNotificationRequest(PushNotificationRequest message)
        throws IOException;
    

Diameter Sh-Server Resource Adaptor Type declares all the Diameter Sh messages related to server operations.

The following tables shows which events are fired on each activity.



Important

Spaces where introduced in Name and Event Class column values, to correctly render the table. Please remove them when using copy/paste.

The JBoss Communications Diameter Sh-Server Activity Context Interface Factory is defined as follows:



    package net.java.slee.resource.diameter.sh.server;
    import javax.slee.ActivityContextInterface;
    import javax.slee.UnrecognizedActivityException;
    public interface ShServerActivityContextInterfaceFactory {
        ActivityContextInterface getActivityContextInterface(ShServerActivity activity)
            throws UnrecognizedActivityException;
        ActivityContextInterface getActivityContextInterface(ShServerSubscriptionActivity activity)
            throws UnrecognizedActivityException;
    }
    

The JBoss Communications Diameter Sh-Server Resource Adaptor SBB Interface provides SBBs with access to the Diameter objects required for creating and sending messages. It is defined as follows:



    package net.java.slee.resource.diameter.sh.server;
    import java.io.IOException;
    import net.java.slee.resource.diameter.base.events.avp.DiameterIdentity;
    import net.java.slee.resource.diameter.sh.DiameterShAvpFactory;
    import net.java.slee.resource.diameter.sh.events.PushNotificationAnswer;
    import net.java.slee.resource.diameter.sh.events.PushNotificationRequest;
    public interface ShServerProvider {
        public ShServerMessageFactory getServerMessageFactory();
        public DiameterShAvpFactory getServerAvpFactory();
        public ShServerNotificationActivity createShServerNotificationActivity()
            throws CreateActivityException;
        public PushNotificationAnswer pushNotificationRequest(PushNotificationRequest message)
            throws IOException;
        public DiameterIdentity[] getConnectedPeers();
        public int getPeerCount();
    }
    

Current Resource Adaptor Type has no defined restrictions.

Simple Server-Side Example that receives an User-Data-Request and sends an User-Data-Answer.



    /* Method for receiving UDR and sending UDA with SUCCESS (code 2001) Result-Code. */
    public void onUserDataRequest(UserDataRequest event, ActivityContextInterface aci) {
        if (tracer.isInfoEnabled()) {
            tracer.info("Received UDR:\r\n" + event);
        }
        
        UserDataAnswer answer = ((ShServerActivity) aci.getActivity()).
            createUserDataAnswer(2001, false);
        try {
            if (tracer.isInfoEnabled()) {
                tracer.info("Created UDA:\r\n" + answer);
            }
            ((ShServerActivity) aci.getActivity()).sendUserDataAnswer(answer);
        }
        catch (IOException e) {
            tracer.severe("Failed to send UDA.", e);
        }
    }
    

Simple Server-Side Example that sends an Push-Notification-Request and receives an Push-Notification-Answer.



    /* Method for handling timer event where a PNR created and sent */
    public void onTimerEvent(TimerEvent event, ActivityContextInterface aci) {
        ShServerNotificationActivity activity = null;
        for (ActivityContextInterface _aci : this.getSbbContext().getActivities()) {
            if (_aci.getActivity() instanceof ShServerNotificationActivity) {
                activity = (ShServerNotificationActivity) _aci.getActivity();
                break;
            }
        }
        if (activity == null) {
            tracer.severe("Activity is null, with list: " + Arrays.toString(this.getSbbContext().
                getActivities()));
            return;
        }
        PushNotificationRequest request = activity.createPushNotificationRequest();
        tracer.info("Created PNR:\r\n" + request);
        try {
            UserIdentityAvp ui = avpFactory.createUserIdentity();
            ui.setPublicIdentity("sip:user@diameter.mobicents.org");
            request.setUserIdentity(ui);
            request.setUserData("<xml>Some secrete user xml</xml>");
            if(tracer.isInfoEnabled()) {
                tracer.info("Sending PNR:\r\n" + request);
            }
            activity.sendPushNotificationRequest(request);
        }
        catch (Exception e) {
            tracer.severe("Failed to send PNR.", e);
        }
    }
    
    ...
    
    /* Method for handling PNA messages. Just print the Result-Code AVP. */
    public void onPushNotificationAnswer(PushNotificationAnswer pna, 
        ActivityContextInterface aci) {
        if (tracer.isInfoEnabled()) {
            tracer.info("Push-Notification-Answer received. Result-Code[" + pna.getResultCode() + "].");
        }
    }