Genesys Labs
DMS

 

 


Class SampleMonitor

This class imitates processing of inbound data flow arriving from a media source. The class generates and submits interactions to Interaction Server.

The class’ declaration section provides access to required resources of DMS and Genesys Platform SDK. Particularly, because data exchange with DMS (as well as with Interaction Server) is based on the Genesys Platform SDK objects KeyValueCollection, Message and RequestSubmit, proper Java import statements are placed in the code as it is presented in the following code excerpt.

 

import com.genesyslab.mcr.smserver.channel.ChannelDriverConstants;

import com.genesyslab.mcr.smserver.channel.ChannelConnectors.InboundRoute;

import com.genesyslab.mcr.smserver.common.Utils;

import com.genesyslab.mcr.smserver.gframework.FieldNames;

import com.genesyslab.mcr.smserver.gframework.LmsMessages;

 

import com.genesyslab.platform.commons.collections.KeyValueCollection;

import com.genesyslab.platform.commons.protocol.Message;

import com.genesyslab.platform.openmedia.protocol.interactionserver.requests.interactionmanagement.RequestSubmit;

 

SampleMonitor class’ instance is created and launched by the method initialize as it is shown in the SampleDriver class’ description. The monitor’s activity is controlled by the driver’s connection state, namely it is regulated by the driver’s variable mediaConnected (defined inSampleDriver class), which is set by connect / disconnect methods (refer to SampleDriver description).

Data Generation

The driver’s class SampleMonitor is a subclass of Java Thread class, its run method generates messages, which imitate media channel’s inbound data flow, and submits them to an Interaction Server. The code below demonstrates a creating of KeyValueCollection object and populating it with data that will be delivered to an Interaction Server. Message submitting (submitAndWait method) is described in the next section.

Submitted data go with the name of media channel which has received these data from a media source. This channel’s mark is helpful to select an originating media channel, for example, to send an answer or a request for additional data related to the initial message. The statement below adds media channel name to a submission. Method getChannelName provided by ChannelDriverPU object is used to get channel name in Genesys CME.

 

     messageData.addString(FieldNames.UMSKEY_Channel, sampleDriver.channelPU.getChannelName());

 

Note, that the message’s generator uses hardcoded message identification (msgId variable in the code fragment below), which is, normally, a part of a message received from a media source.

 

    public void run()

    {

     final String logRpfx = sampleDriver.logPfx("SampleMonitor.run");

 

     . . .

    

     while (true) {

         // Check the driver's connection state -------------------------------------------------

         if (!sampleDriver.mediaConnected) {

           try {

               sleep(1000);

           }

           catch (InterruptedException ex) {

               sampleDriver.getGfrPU().trace(LmsMessages.exception2, logRpfx, Utils.getExcLogRecord(ex));

           }

           continue;

         }

 

    . . .

 

         // Form and submit a message------------------------------------------------------------

 

         . . .

 

           try {

               ++messagesCreated;

 

               String msgId = "SAMPLE-" + 1000000 + messagesCreated;

               KeyValueCollection messageData = new KeyValueCollection();

               messageData.addString(SampleDriver.KEY_PFX + ChannelDriverConstants.UMSKEY_MsgType,

                             SampleDriver.MSGTYPE_SAMPLE);

               messageData.addString(SampleDriver.KEY_PFX + ChannelDriverConstants.UMSKEY_MsgId, msgId);

               messageData.addString(SampleDriver.KEY_PFX + ChannelDriverConstants.UMSKEY_MsgPlainText,

                             "sample_text_" + msgId);

 

               // The next line adds channel name to the submitted data

               messageData.addString(FieldNames.UMSKEY_Channel, sampleDriver.channelPU.getChannelName());

 

               sampleDriver.getGfrPU().trace(LmsMessages.generic_trc2, logRpfx,

                                  "data from sample...\n" + messageData.toStringLine());

 

               // Submit message ============================================

               submitAndWait(messageData);

               // ===========================================================

           }

           catch (Exception ex) {

               sampleDriver.getGfrPU().trace(LmsMessages.exception2, logRpfx, Utils.getExcLogRecord(ex));

           }

 

           . . .

         }

     }

    }

Delivering Data Retrieved by Channel Driver - Requests to Interaction Server

A channel driver delivers data (incoming messages, et al) to Interaction Server by calling method sendItxRequestAndWait, specified in ChannelDriverPU interface. The method is a synchronous one - it waits for a send operation’s completion and passes the operation’s result to a driver. The result is passed as an object Message, defined in the Genesys Platform SDK. An example of using this method is provided in the Sample Driver’s class SampleMonitor.

Note that DMS doesn’t interact with Genesys Contacts Server (UCS), therefore required functionality (creation interactions in UCS, et al) needs to be implemented in a routing strategy as it’s done in the sample business processes provided by Genesys.

Method submitAndWait, implemented in this sample monitor, who is called in the monitor’s generator cycle, performs a delivery of prepared data to an Interaction Server. Each data submission is labeled with a unique identifier and is attributed with a media type, which will be assigned to the resulting interaction. Below is this method’s declaration.

 

    /**

     * The method submits request to Interaction Server and waits for a response from it. If there is no connection to

     * Interaction Server exists, the method tries to repeat the request up to driverParams.itxAttemptsMax times with

     * interval driverParams.itxRepeatTimeout seconds.

     *

     * @param messageData

     *            content of a message to send

     * @param messageMediaType

     *            interaction media type

     * @return true - successfully sent request, false - failed to send

     * @throws Exception

     *             if failed to deliver request to Interaction Server

     */

    private boolean submitAndWait(KeyValueCollection messageData)

         throws Exception

 

 

Method sendItxRequestAndWait provided by ChannelDriverPU object accepts as input an object RequestSubmit implemented in Genesys Platform SDK. The object comprises data obligatory for any interaction – media type, interaction type and subtype, tenant identification and interactions’ queue name.

Interaction media type is specified in the Sample Driver’s configuration option channel-<name>/x-inbound-media. Note that this media type needs to be configured in Genesys CME first, to allow Interaction Server to accept interactions submitted with this media type value.

Interaction type and subtype are hardcoded in the Sample Driver; though these parameters may be defined in a channel configuration for other implementations.

Tenant identification and interaction queue name are specified in the Sample Driver configuration option channel-<name>/inbound-route-default. These parameters are available via DMS’s object InboundRoute from package com.genesyslab.mcr.smserver.channel.ChannelConnectors. The object exposes method findInboundRoute, which must be called with null parameter to get default inbound route.

An incoming media message is placed in a user data part of a RequestSubmit object (and subsequently in an interaction’s user data) as it is shown below.

The code fragment below demonstrates a RequestSubmit object’s creating and populating it with mandatory interaction data.

 

     // Form RequestSubmit object (refer to Genesys Platform SDK)

 

     // Set interaction attributes

     RequestSubmit requestSubmit = RequestSubmit.create(driverParams.inboundMedia, driverParams.itxType);

     requestSubmit.setInteractionSubtype(driverParams.itxSubType);

     requestSubmit.setReferenceId(sampleDriver.channelPU.getNextItxReferenceId());

     requestSubmit.setUserData(messageData);

     // Get and set tenant ID and interaction queue name

     InboundRoute inbRoute = sampleDriver.channelPU.getChannelConnector().findInboundRoute(null);

     requestSubmit.setTenantId(inbRoute.pagingTenant);

     requestSubmit.setQueue(inbRoute.pagingQueue);

 

     // Print the request to a log file

     sampleDriver.getGfrPU().trace(LmsMessages.sent_data, logRpfx, "itx request...\n" + requestSubmit);

 

     // Assign a unique reference ID to the request

     int refID = requestSubmit.getReferenceId();

 

Prepared RequestSubmit object is handed to DMS with calling sendItxRequestAndWait method implemented in ChannelDriverPU object, as it is shown in the following code excerpt.

 

           Message responseMsg = sampleDriver.channelPU

                .sendItxRequestAndWait(requestSubmit, 1000 * driverParams.itxSubmitTimeout);

 

           if (null == responseMsg) // failed to get a response from Interaction Server during specified timeout

               throw new Exception("timeout on sendItxRequestAndWait");

 

 

           // Print a response received from Interaction Server

           sampleDriver.getGfrPU().trace(LmsMessages.received_data, logRpfx, "itx response...\n" + responseMsg);

           return true;

 

These are the basics of how to implement media channel’s data fetching monitor. For more information, see specification of DMS’s channel driver API in this document.

Additional Information

For more information about the Genesys SDKs, including the latest versions of all SDK documents, check out the Genesys Developer Zone, which also contains forums and other important sources of developer-related information. DevZone is available at http://www.genesyslab.com/developer.

Additional information on Genesys Telecommunications Laboratories, Inc. is available on our Technical Support website.

Top of Page


 

 

 

 

 

 

 

 

Genesys Labs
DMS

 

 


Send comments on this topic.
Copyright © 2010–2018 Genesys Telecommunications Laboratories, Inc. All Rights Reserved.