Extending MQeConnectionFactory

By default MQeConnectionFactory will either look for a queue manager already running in the JVM, or will start its own using an initialization (.ini) file.

A third option is to extend MQeConnectionFactory to provide the desired behavior. The preferred way to do this is to override two internal methods, startQueueManager() and stopQueueManager(). The first method is called to start and configure an MQe queue manager when a Connection is first created, while the second shuts it down cleanly when the final Connection is closed. These methods are both public to make them easy to override, but they should not normally be called by an application.

The following class shows a simple way of extending MQeConnectionFactory to start its own queue manager without the need for an initialization file:

import javax.jms.*;
import examples.config.*;
import com.ibm.mqe.jms.MQeConnectionFactory;
import com.ibm.mqe.MQeQueueManager;
import java.io.File;

// type on one line:
public class MQeExtendedConnectionFactory 
         extends MQeConnectionFactory {
 
  // Queue Manager Name -
  private static final String queueManagerName = "ExampleQM";
  // Location of the registry -
  private static final String registryLocation = ".\\ExampleQM";
  // Queue store -
  private static final String queueStore = "MsgLog:"
                                          + registryLocation
                                          + File.separator
                                          + "Queues";
  // the MQe Queue Manager -
  private static MQeQueueManager queueManager = null;
  
  public MQeQueueManager startQueueManager() throws JMSException {
    try {
      CreateQueueManager.createQueueManagerDefinition(
      queueManagerName, registryLocation, queueStore);
      queueManager=CreateQueueManager.startQueueManager(
      queueManagerName, registryLocation);
    }
    catch (Exception e) {
      JMSException je = new JMSException("QMgr start  failed");
                   je.setLinkedException(e);
                   throw je;
    }
  return queueManager;
  }
  
  public void stopQueueManager() throws Exception {
    CreateQueueManager.stopQueueManager(queueManager);
  }

}

In this example the actual queue manager startup and shutdown has been delegated to the CreateQueueManager examples described in an earlier chapter.


Terms of use | WebSphere software

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