FileDocCategorySizeDatePackage
AppserverClusterViewFromCacheRepository.javaAPI DocGlassfish v2 API7803Wed May 16 01:02:16 BST 2007com.sun.enterprise.config.serverbeans

AppserverClusterViewFromCacheRepository

public class AppserverClusterViewFromCacheRepository extends Object

Fields Summary
private final String
myName
private final com.sun.enterprise.config.ConfigContext
domainCC
Constructors Summary
public AppserverClusterViewFromCacheRepository(String domainXmlUrl)

        if (domainXmlUrl == null) {
            throw new IllegalArgumentException("null_arg");
        }
        myName              = System.getProperty(SystemPropertyConstants.SERVER_NAME);
        final String url    = domainXmlUrl;
        // enable caching - with caching domain.xml gets read/parsed one less
        domainCC            = ConfigFactory.createConfigContext(url, true, true, false, false);
    
Methods Summary
private JmsHostgetDefaultJmsHost(JmsService jmsService)

        final JmsHost[] jmsHosts        = jmsService.getJmsHost();
        final String defaultHostName    = jmsService.getDefaultJmsHost();
        JmsHost defaultJmsHost          = null;
        for (final JmsHost h : jmsHosts) {
            final String name = h.getName();
            if (name.equals(defaultHostName)) {
                defaultJmsHost = h;
                break;
            }
        }
        return ( defaultJmsHost );
    
public JmsServicegetJmsServiceForMasterBroker(java.lang.String clusterName)

        final String myCluster      = ClusterHelper.getClusterByName(domainCC, clusterName).getName();
	final Server[] buddies      = ServerHelper.getServersInCluster(domainCC, myCluster);
        final Config cfg             =  ServerHelper.getConfigForServer(domainCC, buddies[0].getName());
        return cfg.getJmsService();
	
public JmsHostgetMasterJmsHostInCluster(java.lang.String clusterName)

        final String myCluster      = ClusterHelper.getClusterByName(domainCC, clusterName).getName();
	final Server[] buddies      = ServerHelper.getServersInCluster(domainCC, myCluster);
	 for (final Server as : buddies) {
	 	try {
             		final JmsHost copy	  = getResolvedJmsHost(as);
			// return the first valid host
			// there may be hosts attached to an NA that is down
             		return copy;
	 	} catch (Exception e) {
		// we dont add the host if we cannot get it
			;
	 	}
	}
	throw new RuntimeException("No JMS hosts available to select as Master");
		
        // final JmsHost copy   = getResolvedJmsHost(buddies[0]);
    
public java.lang.StringgetNodeAgentHostName(Server as)

        final NodeAgent na = NodeAgentHelper.getNodeAgentForServer(domainCC, as.getName());
        final boolean dasShookHandsWithNodeAgent = NodeAgentHelper.hasNodeAgentRendezvousd(domainCC, na);
        if (! dasShookHandsWithNodeAgent)
            throw new RuntimeException("Error: NA: " + na.getName() + " has not rendezvous'ed with DAS");
        final String naHost = NodeAgentHelper.getNodeAgentSystemConnector(domainCC, na.getName()).getElementPropertyByName(IAdminConstants.HOST_PROPERTY_NAME).getValue();
        return ( naHost );
    
public JmsHostgetResolvedJmsHost(Server as)

        final JmsHost jmsHost   = getResolvedLocalJmsHostInServer(as);
        final JmsHost copy      = new JmsHost();
        final String hostName = getNodeAgentHostName(as);
        if (jmsHost != null) {
             copy.setHost(hostName);
             copy.setName(jmsHost.getName());
             final String resolved = this.resolve(as.getName(), SystemPropertyConstants.unSystemProperty(jmsHost.getPort()));
             copy.setPort(resolved);
             copy.setAdminPassword(jmsHost.getAdminPassword());
             copy.setAdminUserName(jmsHost.getAdminUserName());
         }
        
        return copy;
    
private JmsHostgetResolvedLocalJmsHostInServer(Server server)

        final Config cfg                = ServerHelper.getConfigForServer(domainCC, server.getName());
        final JmsService jmsService     = cfg.getJmsService();
        JmsHost jmsHost                 = null;
        if (JMSServiceType.LOCAL.toString().equals(jmsService.getType())	|| JMSServiceType.EMBEDDED.toString().equals(jmsService.getType())) {
            jmsHost = getDefaultJmsHost(jmsService);
        }
        return ( jmsHost );
    
public java.util.MapgetResolvedLocalJmsHostsInCluster(java.lang.String clusterName)

         final Map<String, JmsHost> map = new HashMap<String, JmsHost> ();
         final String myCluster      = ClusterHelper.getClusterByName(domainCC, clusterName).getName();
         final Server[] buddies      = ServerHelper.getServersInCluster(domainCC, myCluster);
         for (final Server as : buddies) {
	 try {
             final JmsHost copy   = getResolvedJmsHost(as);
             map.put(as.getName(), copy);
	 } catch (Exception e) {
		// we dont add the host if we cannot get it
		;
	 }
         }
         return map;
    
public java.util.MapgetResolvedLocalJmsHostsInMyCluster(boolean includeMe)

        final Map<String, JmsHost> map = new HashMap<String, JmsHost> ();
        if (ServerHelper.isServerClustered(domainCC, myName)) {
            final String myCluster      = ClusterHelper.getClusterForInstance(domainCC, myName).getName();
            final Server[] buddies      = ServerHelper.getServersInCluster(domainCC, myCluster);
            for (final Server as : buddies) {
                if (!includeMe && myName.equals(as.getName()))
                    continue;
		try {
                	final JmsHost copy      = getResolvedJmsHost(as);
                	map.put(as.getName(), copy);
		} catch (Exception e) {
			;
		}
            }
        }
        return ( map );
    
public java.util.MapgetResolvedLocalJmsHostsInMyCluster()

        return ( this.getResolvedLocalJmsHostsInMyCluster(false) );
    
public com.sun.enterprise.config.ConfigContextgetUnResolvedConfigContext()

        return domainCC;
    
private java.lang.Stringresolve(java.lang.String server, java.lang.String value)

        final PropertyResolver pr = new PropertyResolver(domainCC, server);
        String resolved = pr.getPropertyValue(value, true);
        if (resolved == null) // the property could not be resolved, returned what was passed
            resolved = value;
        return ( resolved );