FileDocCategorySizeDatePackage
MQAddressList.javaAPI DocGlassfish v2 API13664Fri May 04 22:34:26 BST 2007com.sun.enterprise.connectors.system

MQAddressList

public class MQAddressList extends Object
Defines an MQ addressList.
author
Binod P.G

Fields Summary
static Logger
logger
private static String
myName
private List
urlList
private JmsService
jmsService
private AppserverClusterViewFromCacheRepository
rep
private static String
nodeAgentHost
private String
targetName
Constructors Summary
public MQAddressList()
Create an empty address list


              
        
        this(null);
    
public MQAddressList(JmsService service)
Use the provided JmsService to create an addresslist

        //use the server instance this is being run in as the target
        this(service, getServerName());
    
public MQAddressList(JmsService service, String targetName)
Creates an instance from jmsService and resolves values using the provided target name

param
targetName Represents the target for which the addresslist needs to be created
param
service JmsService instance.

        logFine(" init" + service + "target " + targetName);
        this.jmsService = service;
        this.targetName = targetName;
    
Methods Summary
public voidaddMQUrl(JmsHost host)
Creates an instance of MQUrl from JmsHost element in the dtd and add it to the addresslist.

param
host An instance of JmsHost object.

        MQUrl url = createUrl(host);
        urlList.add(url);
    
private MQUrlcreateUrl(JmsHost host)

        return createUrl(host, this.jmsService);
    
private MQUrlcreateUrl(JmsHost host, java.lang.String overridedHostName)

        return createUrl(host, this.jmsService, overridedHostName);
    
public static MQUrlcreateUrl(JmsHost host, JmsService js)

        return createUrl(host, js, null);
    
public static MQUrlcreateUrl(JmsHost host, JmsService js, java.lang.String overridedHostName)

        try {
        String name = host.getName();
        String hostName = host.getHost();
        // For LOCAL/EMBEDDED Clustered instances and 
        // standalone server instances, use
        // their nodeagent's hostname as the jms host name.
        ServerContext serverContext = ApplicationServer.getServerContext();
        Server server = serverContext.getConfigBean();
        if (overridedHostName != null && !overridedHostName.trim().equals("")) {
           hostName = overridedHostName;
        }

        String port = host.getPort();
        MQUrl url = new MQUrl(name);
        url.setHost(hostName);
        url.setPort(port);
        if (js != null) {
            String scheme = js.getMqScheme();
            if (scheme != null && !scheme.trim().equals("")) {
                url.setScheme(scheme);
            }

            String service = js.getMqService();
            if (service != null && !service.trim().equals("")) {
                url.setService(service);
            }
        }
        return url;
        } catch (ConfigException ce) {
            ce.printStackTrace();
        }
        return null;
    
private voiddefaultSetup()
Default setup concatanates all JMSHosts in a JMSService to create the address list

        logFine("performing defaultsetup");
        JmsHost[] hosts = jmsService.getJmsHost();
        for (int i=0; i < hosts.length; i++) {
            MQUrl url = createUrl(hosts[i]);
            urlList.add(url);
        }
    
private com.sun.enterprise.config.ConfigContextgetAdminConfigContext()
Gets the admin config context associated with this server instance Usage Notice: Use this only for operations that are performed in DAS and requires the admin config context

        return com.sun.enterprise.admin.server.core.AdminService.
                   getAdminService().getAdminContext().getAdminConfigContext();
    
public java.lang.StringgetMasterBroker(java.lang.String clustername)

	String masterbrk = null;
	if (rep != null) {
	    try {
		JmsHost mb = rep.getMasterJmsHostInCluster(clustername);
		JmsService js = rep.getJmsServiceForMasterBroker
                                 (clustername);
		MQUrl url = createUrl(mb, js); 
		masterbrk = url.toString();
		logger.log(Level.FINE, "Master broker obtained is " 
	           + masterbrk);
	    }
	    catch (Exception e) {
		logger.log(Level.SEVERE, "Cannot obtain master broker");
		logger.log(Level.SEVERE, e.getMessage(), e);
	    }
	}
	return masterbrk;
    
private JmsHostgetResolvedJmsHost(Server as)

        logFine("getResolvedJmsHost " + as);
        return rep.getResolvedJmsHost(as);
    
private JmsHostgetResolvedJmsHostForStandaloneServerInstance(java.lang.String serverName)

        logFine(" getresolved " + serverName);
       ConfigContext con =  getAdminConfigContext();
       Server serverInstance = ServerHelper.getServerByName(con, serverName);
       logFine("serverinstace " + serverInstance);
       JmsHost jmsHost = getResolvedJmsHost(serverInstance);
       return jmsHost;
    
private static java.lang.StringgetServerName()

        String serverName=System.getProperty(SystemPropertyConstants.SERVER_NAME);
        return serverName;
    
public intgetSize()

        if (this.urlList != null) {
            return this.urlList.size();
        } else {
            return 0;
        }
    
private booleanisAConfig(java.lang.String targetName)

        return ServerHelper.isAConfig(getAdminConfigContext(), targetName);
    
private booleanisClustered()

        return JmsRaUtil.isClustered();
    
private booleanisDAS(java.lang.String targetName)

        if (isAConfig(targetName)) {
            return false;   
        }
        return ServerHelper.isDAS(getAdminConfigContext(), targetName);
    
private voidlogFine(java.lang.String s)

        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "MQAddressList :: " + s);
        }
    
public voidremoveMQUrl(JmsHost host)
Deletes the url represented by the JmsHost from the AddressList.

param
host An instance of JmsHost object.

        MQUrl url = createUrl(host);
        urlList.remove(url);
    
public voidsetup()
Sets up the addresslist.

        try {
            if (isClustered() && (!this.jmsService.getType().equals(ActiveJmsResourceAdapter.REMOTE)) ) {
                //setup for LOCAL/EMBEDDED clusters.
                logFine("setting up for cluster " +  this.targetName);
                setupClusterViewFromRepository();
                setupForCluster();
            } else {
                logFine("setting up for SI/DAS " + this.targetName);
                if (isAConfig(targetName) || isDAS(targetName)) {
                    logFine("performing default setup for DAS/remote clusters/PE instance" + targetName);
                    defaultSetup();
                } else {
                    logFine("configuring for Standalone EE server instance");
                    //resolve and add.
                    setupClusterViewFromRepository();
                    setupForStandaloneServerInstance();
                }
            }
        } catch (ConnectorRuntimeException ce) {
            throw new ConfigException(ce);
        }
    
private voidsetupClusterViewFromRepository()

        ServerContext context = ApplicationServer.getServerContext();
        Server server = context.getConfigBean();
        String domainurl = context.getServerConfigURL();
        rep = new AppserverClusterViewFromCacheRepository(domainurl);
        try {
            nodeAgentHost = rep.getNodeAgentHostName(server);
            logFine("na host" + nodeAgentHost);
        } catch (Exception e) {
            logger.log(Level.FINE,"Exception while attempting to get nodeagentHost", e.getMessage());
            logger.log(Level.FINER, e.getMessage(), e);
        }
    
private voidsetupForCluster()
Setup the address list after calculating the JMS hosts belonging to the local appserver cluster members. For LOCAL/EMBEDDED clusters the MQ broker corresponding to "this" server instance needs to be placed ahead of the other brokers of the other siblings in the AS cluter to enable sticky connection balancing by MQ.

        java.util.Map<String,JmsHost> hostMap = 
            rep.getResolvedLocalJmsHostsInMyCluster(true);
        //First add my jms host.
        JmsHost jmsHost = hostMap.get(myName); 
        MQUrl myUrl = createUrl(jmsHost, nodeAgentHost);
        urlList.add(myUrl);
        hostMap.remove(myName);
        
        // Add all buddies to URL.
        for (JmsHost host : hostMap.values() ) {
            MQUrl url = createUrl(host);
            urlList.add(url);
        }
    
private voidsetupForStandaloneServerInstance()
Setup addresslist for Standalone server instance in EE

        if (jmsService.getType().equals(ActiveJmsResourceAdapter.REMOTE)) {
            logFine("REMOTE Standalone server instance and hence use default setup");
            defaultSetup();
        } else {
            //For LOCAL or EMBEDDED standalone server instances, we need to resolve
            //the JMSHost
            logFine("LOCAL/EMBEDDED Standalone server instance");
            JmsHost host = getResolvedJmsHostForStandaloneServerInstance(this.targetName);
            MQUrl url = createUrl(host);
            urlList.add(url);
        }            
    
public java.lang.StringtoString()
Creates a String representation of address list from array list. In short, it is a comma separated list. Actual syntax of an MQ url is inside MQUrl class.

returns
AddressList String
see
MQUrl

        String s = "";
	
        Iterator it = urlList.iterator();
	if (it.hasNext()) {
            s = it.next().toString();
	}
	
        while (it.hasNext()) {
            s = s + "," +  it.next().toString();
        }

        logFine("toString returns :: " + s);
        return s;
    
public voidupdateMQUrl(JmsHost host)
Updates the information about the JmsHost in the address list.

param
host An instance of JmsHost object.

        MQUrl url = createUrl(host);
        urlList.remove(url);
        urlList.add(url);