WebSphere WebSphere Application Server Network Deployment, Version 6.0.x Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Enabling an application to be started before a messaging engine

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 application server to start an application automatically, you should develop your applications to test that any required messaging engine has been started and, if needed, wait for the messaging engine. 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, using the standard WorkManager methods, so that the application server 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 actually 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);                                             
      }                                                                   
    }

Concept topic

Terms of Use | Feedback

Last updated: 15 Mar 2007
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.nd.doc\concepts\cjb0003_.html

© Copyright IBM Corporation 2004, 2007. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)