Queue rules - Java™ example 2

The following example shows how to log an event that occurs on the queue. The event that occurs is the creation of a message listener.

In the example, the queue has its own log file, but it is equally as valid to have a central log file that is used by all queues. The queue needs to open the log file when it is activated, and close the log file when the queue is closed. The queue rules, queueActivate and queueClose can be used to do this. The variable logFile needs to be a class variable so that both rules can access the log file.

/* This rule logs the activation of the queue */
public void queueActivate()    {
    try    {
     logFile = new LogToDiskFile( \\log.txt );
     log( MQe_Log_Information, Event_Activate, "Queue " +
     ((MQeQueueProxy)owner).getQueueManagerName() + " + " +
     ((MQeQueueProxy)owner).getQueueName() + " active" );
    }
    catch( Exception e )    {
        e.printStackTrace( System.err );
    }
}

/* This rule logs the closure of the queue */
public void queueClose()    {
    try    {
      log( MQe_Log_Information, Event_Closed, "Queue " +
          ((MQeQueueProxy)owner).getQueueManagerName() + " + " +
          ((MQeQueueProxy)owner).getQueueName() + " closed" );
        /* close log file */
        logFile.close();
    }
    catch ( Exception e )    {
        e.printStackTrace( System.err );
    }
}

The addListener rule is shown in the following code. It uses the MQe.log method to add an Event_Queue_AddMsgListener event.

/* This rule logs the addition of a message listener */
public void addListener( MQeMessageListenerInterface listener, 
                  MQeFields filter ) throws Exception 
   {
    log( MQe_Log_Information, Event_Queue_AddMsgListener, 
                "Added listener on queue " 
         + ((MQeQueueProxy)owner).getQueueManagerName() + "+" 
         + ((MQeQueueProxy)owner).getQueueName() );
}

Terms of use | WebSphere software

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