Extending MQeQueueConnectionFactory

By default MQeQueueConnectionFactory 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 MQeQueueConnectionFactory 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 a WebSphere MQ Everyplace queue manager when a QueueConnection is first created, while the second shuts it down cleanly when the final QueueConnection 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 MQeQueueConnectionFactory to start its own queue manager without the need for an initialization file:

import javax.jms.*;
import examples.config.*;
import com.ibm.mqe.jms.MQeQueueConnectionFactory;
import com.ibm.mqe.MQeQueueManager;
import java.io.File;
 
// type on one line
public class MQeExtendedQueueConnectionFactory 
			extends MQeQueueConnectionFactory {
 
private static final String queueManagerName = "ExampleQM"; 
	// Queue Manager Name
  	private static final String registryLocation = ".\\ExampleQM"; 
	// Location of the registry
  	private static final String queueStore = "MsgLog:" + 
registryLocation + File.separator + "Queues"; 
	// Queue store
private static MQeQueueManager queueManager = null; 
// the WebSphere MQ Everyplace Queue Manager 
 
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.



© IBM Corporation 2002, 2003. All Rights Reserved