Writing an iWay Service Manager Emitter

iWay Service Manager emitters provide the output exchange between iWay Service Manager documents produced by the system and the actual destination medium. Emitters are provided for each medium that the facility supports, such as MQ Series, the local file system, FTP, TIBCO Rendezvous, and so on.

Emitters are bound into the system using the addEmitter() method of the component interface.

The emitter itself must be in the package com.ibi.edaqm, and it must be named according to the pattern XDxxxEmit.java.

During emit, the user or configurator creates an XDReply for the appropriate address, and passes into it a map containing parameters. In many cases, the XDReply can be used for more than a single emitter. For example, the XDReply constructed for a queuing emitter can be used in association with any queuing emitter. System-specific parameters may need to be supplied, but common parameters are commonly named and validated.

When the emitter is used, the XDReply is passed into the emitter, and serves as its source of parameters.

The emitter itself extends com.ibi.edaqm.XDEmit, which provides all of the logical services needed by the emitter to interact with the engine. The specific emitter must support four methods:

Associated with each emitter is a separator character used to divide the two parts of the address to which the emitter emits. The addEmitter() call specifies this character. For example, email uses the @ character (name@emailservice), while HTTP uses the : character (//host:port). If you have no separator, use the '\0' character.

A very simple emitter is shown in the following code. This emitter takes the document and displays in the console using System.out. Although this is not a real emitter, it demonstrates the major components.

  1. An XDReply, built by the configuration or manually by an agent, contains the addressing information. If you are simply using the console to configure your listener, you do not have to be concerned with the source of the reply object. The reply object has the address and any parameters defined in the MasterInfoLine that provides the metadata for this emitter.
  2. The document to be emitted arrives in the emit() call. You prepare for emit here.
  3. The commit() call tells the emitter to actually emit the output.
package com.ibi.edaqm;
public class XDLineEmit extends XDEmit
{
    XDTickMaster master = null;
    String prename = null;  // stick this in front of each message
    String suffix="";
    String message;  // message to put out is created here
    // the line emitter example uses an address of name (part1) which it simply
    // prepends to each string 
1.  public XDLineEmit(XDReply reply, XDWorker worker) throws XDException
    {
        master = (XDTickMaster)worker.getMaster();
        super(reply);
        this.worker = worker;
        prename = "["+reply.part1+"]: ";
        if (!reply.useMaster)   // was this from the Master itself?
        {
           worker.setLogger(),debug("worker is not XDTickWorker");
           htParams = reply.htParams;  // pick up user's parameter map to XDReply
           if (htParams == null)
           {
               return;
           }
           String s = (String)htParams.get("suffix");
           if (suffix != null)
           {
               suffix = "["+s+"]";
           }
            // do something with the parms here
            // close (!reply.useMaster)
        }
        else
        {
            // extract parameters from your own master here if this is meaningful
            String s = master.getSuffix();
            if (suffix != null)
            {
                suffix = "["+s+"]";
            }
        }
    } 
2.  public void emit(XDDocument outdoc) throws XDException
    {
       review(outdoc);
       try
       {
           byte[] b = preEmit(worker.dictionary, outdoc);  // get what to emit
           message = prename+new String(b)+suffix;
       }
       catch (XDException x)
       {
           logger.degug(“  “);
           worker.logger.debug("document setup got error "+x);
           throw new XDException((Exception)x);
       }
    }
    // actually issue the message 
3.  public void commit()
    {
        logger.debug(message);
    }
    public void rollback()
    {
        message=null;
    }
}

iWay Software