Applications with a dependency on messaging engine availability

If an application depends on a messaging engine being available, then the messaging engine must be started before the application can be run.

If you want the appserver to start an application automatically, develop the application to test that any required messaging engine has been started and, if needed, wait for the messaging engine to start. If this is technique used in a startup bean, then the startup bean method should perform the work (to test and wait) in a separate thread, and use the standard WorkManager methods, so that the appserver startup is not delayed. For an example of code to test and wait for a messaging engine, see the following code extract:

import java.util.Iterator;
import javax.management.ObjectName;                                     
import com.ibm.websphere.management.AdminService;                       
import com.ibm.websphere.management.AdminServiceFactory;      

    String messagingEngineName = "messagingEngineName"; 
    
// Messaging engine to check if started? for example "node01.server1-bus1"
    boolean meStarted = false;                                            
                                                                        
    AdminService adminService = AdminServiceFactory.getAdminService();
    while (!meStarted) {                                                  
      String filterString = "WebSphere:type=SIBMessagingEngine,name=" + 
                             messagingEngineName + ",*";                  
      boolean foundBean = false;                                          
      ObjectName objectName = null;                                       
      try {                                                               
        ObjectName objectNameFilter = new ObjectName(filterString);     
        Iterator iter = adminService.queryNames(objectNameFilter,null).iterator();                                                       
        while (iter.hasNext()) {                                        
            objectName = (ObjectName) iter.next();                      
            foundBean = true;                                           
            break;                                                      
        }                                                               
      } catch (Exception e) {                                             
        e.printStackTrace();                                            
      }                                                                   
      if (foundBean) {                                                    
        
// we have found messaging engine MBean, which means it is initialized, 
        
// now check if it is in Started state?              
        meStarted = 
          ((Boolean) adminService.invoke(objectName, "isStarted", null, null)).booleanValue();                               
      }                                                                   
                                                                        
      if (!meStarted) {                                                   
        
// messaging engine is not started yet so sleep (wait) for a bit...     
        Thread.sleep(5000);                                             
      }                                                                   
    }

Last updated Dec 15, 2010 8:14:22 PM CST