Example - starting a client queue manager

Starting a client queue manager involves:
  1. Ensuring that there is no client already running. (Only one client is allowed per Java™ Virtual Machine.)
  2. Adding any aliases to the system
  3. Enabling trace if required
  4. Starting the queue manager

The following code fragment starts a client queue manager:

MQERETURN createQueueManager(MQeExceptBlock *pErrorBlock, MQeQueueManagerHndl *phQMgr, 
                             MQeFieldsHndl hInitFields, MQeStringHndl hQStore)
{

   MQERETURN rc;
   MQeQueueManagerConfigureHndl hQMgrConfigure;

      /* Create instance of QueueManagerConfigure Class */
      rc = mqeQueueManagerConfigure_new(pErrorBlock,&hQMgrConfigure,
                            hInitFields,hQStore);

      if (MQERETURN_OK == rc) {
         /* define queue manager */
         rc = mqeQueueManagerConfigure_defineQueueManager(hQMgrConfigure, pErrorBlock);
         if (MQERETURN_OK == rc) {
            /* define system default queues */
            rc = mqeQueueManagerConfigure_defineDefaultSystemQueue(hQMgrConfigure, 
                                                                   pErrorBlock, NULL);
         }

         /* close mqeQueueManagerConfigure */
         (void)mqeQueueManagerConfigure_close(hQMgrConfigure, NULL);
         if (MQERETURN_OK == rc) {
            /* create queue manager */
            rc = mqeQueueManager_new(pErrorBlock, phQMgr);
            if (MQERETURN_OK == rc) {
               rc = mqeQueueManager_activate(*phQMgr, pErrorBlock, hInitFields);
            } 
         }
         /* free mqeQueueManagerConfigure */
         (void)mqeQueueManagerConfigure_free(hQMgrConfigure, NULL);
      }

   return rc;
}

/*-------------------------------------*/
/* Init - first stage setup             */
/*-------------------------------------*/
public void init( MQeFields parms ) throws Exception
{
  if ( queueManager != null )                
/* One queue manager at a time   */
  {
    throw new Exception( "Client already running" );
  }
  sections = parms;                          
/* Remember startup parms        */
  MQeQueueManagerUtils.processAlias( sections ); 
/* set any alias names       */

// Uncomment the following line to start trace 
    before the queue manager is started
//  MQeQueueManagerUtils.traceOn("MQeClient Trace", null); 
/* Turn trace on   */

  /* Display the startup parameters */
  System.out.println( sections.dumpToString("#1\t=\t#2\r\n"));

  /* Start the queue manage  */
  queueManager = MQeQueueManagerUtils.processQueueManager( sections, null);
}

Once you have started the client, you can obtain a reference to the queue manager object by using API call mqeQueueManager_getReference(queueManagerName)either from the static class variable MQeClient.queueManager or by using the static method MQeQueueManager.getReference(queueManagerName).

The following code fragment loads aliases into the system:
public static void processAlias( MQeFields sections ) throws Exception
{
  if ( sections.contains( Section_Alias ) )   
/* section present ?            */
  {                                           
/* ... yes                      */
    MQeFields section = sections.getFields( Section_Alias );
    Enumeration keys  = section.fields( );    
/* get all the keywords         */
    while ( keys.hasMoreElements() )          
/* as long as there are keywords*/
    {                                         
      String    key   = (String) keys.nextElement();     
/* get the Keyword   */
      MQe.alias( key, section.getAscii( key ).trim( ) ); 
/* add               */
    }                                       
  }
}      

Use the processAlias method to add each alias to the system. MQe and applications can use the aliases once they have been loaded.

Starting a queue manager involves:
  1. Instantiating a queue manager. The name of the queue manager class to load is specified in the alias QueueManager. Use the MQe class loader to load the class and call the null constructor.
  2. Activate the queue manager. Use the activate method, passing the MQeFields object representation of the ini file. The queue manager only makes use of the [QueueManager] and [Registry] sections from the startup parameters.

The following code fragment starts a queue manager:

public static MQeQueueManager processQueueManager( MQeFields sections,
     Hashtable ght ) throws Exception
{                                             
/*                              */
  MQeQueueManager queueManager = null;        
/* work variable                */
  if ( sections.contains( Section_QueueManager) )     
/* section present ?    */
  {                                           
/* ... yes                      */
   queueManager = (MQeQueueManager) MQe.loader.loadObject(Section_QueueManager);
    if ( queueManager != null )               
/* is there a Q manager ?       */
    {
      queueManager.setGlobalHashTable( ght );
      queueManager.activate( sections );      
/* ... yes, activate            */
    }
  }                                           
  return( queueManager );                     
/* return the alloated mgr      */
}      

Terms of use | WebSphere software

(c) Copyright IBM Corporation 2004, 2005. All rights reserved.