FileDocCategorySizeDatePackage
IIOPEndpointsInfo.javaAPI DocGlassfish v2 API15152Fri May 04 22:34:54 BST 2007com.sun.enterprise.iiop

IIOPEndpointsInfo

public class IIOPEndpointsInfo extends Object
This class is responsible for reading the domain.xml via Config API and producing a list of instances in the form of ClusterInstanceInfo objects. This class is designed for use by both FailoverIORInterceptor and Java Web Start.
author
Sheetal Vartak
date
1/12/05

Fields Summary
private static com.sun.enterprise.config.serverbeans.ServerRef[]
serverRefs
private static com.sun.enterprise.config.serverbeans.IiopListener[]
listeners
private static com.sun.enterprise.config.serverbeans.Cluster
cluster
private static Logger
_logger
private static final String
baseMsg
private static com.sun.enterprise.config.ConfigContext
configCtx
Constructors Summary
Methods Summary
public static java.util.ListgetClusterInstanceInfo()
This method returns a ClusterInstanceInfo list.

	List<ClusterInstanceInfo> result = 
	    new LinkedList<ClusterInstanceInfo>();

	try {
	    _logger.log(Level.FINE,
			baseMsg + ".getClusterForInstanceInfo->:");

	    Cluster[] clusterInfo = ClusterHelper.getClustersInDomain(configCtx);
	    if (clusterInfo.length == 0) {
	        _logger.fine(baseMsg + ".getClusterInstanceInfo->:" +
			     "This is EE. But there is either no cluster or" +
			     " the cluster has only one server instance");
		return null;
		
	    }
	    /*for (Cluster clus : clusterInfo) {
	      ServerRef[] serverRef = clus.getServerRef();
	      IiopListener[][] listenersForServerRef = getIIOPEndPointsForCurrentCluster(serverRef);
	      
	      // For EE and a server participating in a cluster...
	      for (int i = 0; i <serverRef.length; i++) {    
	      String serverName = serverRef[i].getRef();
	      List<SocketInfo> listOfSocketInfo = 
	      getSocketInfoForServer(i, serverRef, listenersForServerRef);
	      */
	    //Server[] servers = ServerHelper.getServersInCluster(configCtx, cluster);

	    if (serverRefs != null) {
	        for (int i = 0; i < serverRefs.length; i++) {
		    String serverName = serverRefs[i].getRef();
		    Server server = ServerHelper.getServerByName(configCtx, serverName);
		    List<SocketInfo> listOfSocketInfo = 
		      getSocketInfoForServer(serverRefs[i], listeners[i]);
		    		    
		    // REVISIT - make orbutil utility
		    // and use in IiopFolbGmsClient and here.
		    SocketInfo[] arrayOfSocketInfo =
		      new SocketInfo[listOfSocketInfo.size()];
		    int x = 0;
		    for (SocketInfo si : listOfSocketInfo) {
		      arrayOfSocketInfo[x++] = si;
		    }
		    _logger.fine("server.getLbWeight() = "+ server.getLbWeight());
		    // REVISIT - default 100 weight
		    // Not used by JNLP but should put in the actual weight.
		    ClusterInstanceInfo clusterInstanceInfo = 
		      new ClusterInstanceInfo(serverName, (Integer.valueOf(server.getLbWeight())).intValue(), arrayOfSocketInfo);
		    result.add(clusterInstanceInfo);
		    if (_logger.isLoggable(Level.FINE)) {
		      _logger.log(Level.INFO, 
				  baseMsg + ".getClusterForInstance: " +
				  ASORBUtilities.toString(clusterInstanceInfo));
		       }
		}	
	    }
	    return result;
	} catch (ConfigException e) {
	    _logger.log(Level.FINE, baseMsg + ".getClusterForInstance: " + "ConfigException occurred => " + e);
	    return null;
	} catch (NullPointerException e) {
	    _logger.log(Level.FINE, baseMsg + ".getClusterForInstance: " + "NPE occurred => " + e);
	    return null;
	} finally {
	    _logger.log(Level.FINE,
			baseMsg + ".getClusterForInstanceInfo<-: " + result);
	}
    
public static java.lang.StringgetHostNameForServerInstance(java.lang.String serverName)
Returns ip address from node agent refered from instance or null if Exception

author
sridatta.viswanath@sun.com

        try {
            JMXConnectorConfig info = 
		ServerHelper.getJMXConnectorInfo(configCtx, serverName);
            _logger.log(Level.FINE, 
			baseMsg + ".getHostNameForServerInstance: " +
			"found info: " + info.toString());
	    String host = info.getHost();
            _logger.log(Level.FINE, 
			baseMsg + ".getHostNameForServerInstance: " +
			"found host: " + host);
            return host;
        } catch (Throwable e){
            _logger.log(Level.FINE, 
			baseMsg + ".getHostNameForServerInstance: " +
			"gotException: " + e + " " + e.getMessage() +
			"; returning null");
            return null;
        }
    
public static com.sun.enterprise.config.serverbeans.IiopListener[][]getIIOPEndPointsForCurrentCluster()
The following returns the IIOP listener(s) for all the servers belonging to the current cluster.

author
satish.viswanatham@sun.com
param
configCtx Current server's config context
return
IiopListener[i][j] Two dimension array of iiop listener info i = index of server j = index of iiop listner (j <= 3)
throws
ConfigException In any configuration error cases, ConfigException is thrown

	// For each server instance in a cluster, there are 3 iiop listeners:
	// one for non ssl, one for ssl and third for ssl mutual auth
	
        IiopListener[][] listeners = new IiopListener[serverRefs.length][3];  //SHEETAL can there be multiple SSL or 
                                                                         //SSL_MUTH_AUTH ports? bug 6321813
	for (int i = 0; i < serverRefs.length; i++) {
	    Server server = 
		ServerHelper.getServerByName(configCtx, serverRefs[i].getRef());
	    String configRef = server.getConfigRef();
	    Config config =
		ConfigAPIHelper.getConfigByName(configCtx, configRef);
	    IiopService iiopService = config.getIiopService();
	    listeners[i] = iiopService.getIiopListener();
	}
	return listeners;
    
public static java.lang.StringgetIIOPEndpoints()
This method returns the endpoints in host:port,host1:port1,host2:port2,... format. This is called by Java Web Start

        String endpoints = null;
	GroupInfoService gis;

        try {
	    _logger.log(Level.FINE,
			baseMsg + ".getIIOPEndpoints->:");
	    if (isEE()) {
	        gis = 
		  (GroupInfoService) ((ORBManager.getORB()).resolve_initial_references(
				       ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE));	    
		if (gis == null) {
		    _logger.fine(baseMsg + ".getIIOPEndpoints->:" +
				 "GroupInfoService not available.Is this PE?");
		    return null;
		} 
	    } else {
	        _logger.fine(baseMsg + ".getIIOPEndpoints->:" +
				 "This is PE");
		return null;
	    }

	    /*Cluster[] clusterInfo = ClusterHelper.getClustersInDomain(configCtx);
	      if (clusterInfo.length == 0) {
	      _logger.fine(baseMsg + ".getIIOPEndpoints->:" +
	      "This is EE. But there is either no cluster or" +
	      " the cluster has only one server instance");
	      return null;
	      
	      }
	      for (Cluster clus : clusterInfo) {
	      ServerRef[] serverRef = clus.getServerRef();		
	      IiopListener[][] listenersForServerRef = getIIOPEndPointsForCurrentCluster(serverRef);
	      // For EE and a server participating in a cluster...
	      for (int i = 0; i <serverRef.length; i++) {   
	      
	      
	      List<SocketInfo> listOfSocketInfo = 
	      getSocketInfoForServer(i, serverRef, listenersForServerRef);
	      */
	    if (serverRefs != null) {
	        for (int i = 0; i < serverRefs.length; i++) {
		    List<SocketInfo> listOfSocketInfo = 
		      getSocketInfoForServer(serverRefs[i], listeners[i]);
		    
		    for (SocketInfo si : listOfSocketInfo) {
		        if (!si.type.equals("SSL_MUTUALAUTH") &&
			    !si.type.equals("SSL")) {
			    if (endpoints == null) {
			        endpoints = si.host + ":" + si.port;
			    } else {
			        endpoints = endpoints + "," + si.host + ":" + si.port;
			    }
			}
		    }
		    
		    if (_logger.isLoggable(Level.FINE)) {
		        _logger.log(Level.FINE, 
				    baseMsg + ".getIIOPEndpoints: " +
				    endpoints);
		    }
		}
	    }
	    return endpoints;
	} catch (ConfigException e) {
	    _logger.log(Level.FINE, baseMsg + ".getIIOPEndpoints: " + "ConfigException occurred => " + e);
	    return null;
	} catch (NullPointerException e) {
	    _logger.log(Level.FINE, baseMsg + ".getIIOPEndpoints: " + "NPE occurred => " + e);
	    return null;
	} catch (org.omg.CORBA.ORBPackage.InvalidName in) {
	    _logger.log(Level.FINE,
			baseMsg + ".getIIOPEndpoints<-: " +
			ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE + 
			"doesnot exist. This is PE");
	    return null;
	} finally {
	    _logger.log(Level.FINE,
			baseMsg + ".getIIOPEndpoints<-: " + endpoints);
	}
    
public static com.sun.enterprise.config.serverbeans.IiopListener[][]getListenersInCluster()

 
        if (listeners != null) 
	    return listeners;
	else {
	    _logger.log(Level.FINE,
			baseMsg + ".getServersInCluster:"
			+ "no listeners available. Server Context is null");
	    return null;
	}
    
public static java.lang.StringgetResolvedPort(com.sun.enterprise.config.serverbeans.IiopListener l, java.lang.String server)
Gets the correct resolved value for the specific instance Without this routine, config context resolves the value to the current running instance

author
sridatta.viswanath@sun.com

	String rawPort = l.getRawAttributeValue("port");
	PropertyResolver pr = new PropertyResolver(configCtx, server);
	return pr.resolve(rawPort);
    
public static com.sun.enterprise.config.serverbeans.ServerRef[]getServersInCluster()


     
        if (ApplicationServer.getServerContext() != null) {
	    configCtx = ApplicationServer.getServerContext().getConfigContext();
	    String instanceName =
	      ApplicationServer.getServerContext().getInstanceName();	    
	    try {
	        cluster = 
		  ClusterHelper.getClusterForInstance(configCtx, instanceName);
		serverRefs = cluster.getServerRef();
		listeners = getIIOPEndPointsForCurrentCluster();
	    } catch (ConfigException e) {
	        _logger.log(Level.FINE, 
			    baseMsg + ".<static block>:" + e);	    
	    }
	}
    
    
        if (serverRefs != null)
	    return serverRefs;
	else {
	    _logger.log(Level.FINE,
			baseMsg + ".getServersInCluster:"
			+ "no servers available. Server Context is null");
	    return null;
	}
    
public static java.util.ListgetSocketInfoForServer(com.sun.enterprise.config.serverbeans.ServerRef serverRef, com.sun.enterprise.config.serverbeans.IiopListener[] listen)
This method returns a list of SocketInfo objects for a particular server. This method is the common code called by getIIOPEndpoints() and getClusterInstanceInfo()

      
        List<SocketInfo> listOfSocketInfo =
		    new LinkedList<SocketInfo>();
	String serverName = serverRef.getRef();
	String hostName =
	  getHostNameForServerInstance(serverName);
	if (hostName == null) {
	    hostName = listen[0].getAddress();
	}
	for (int j = 0; j < listen.length; j++) { 
	    String id = listen[j].getId();
	    String port = 
	      getResolvedPort(listen[j], serverName);
	    if (_logger.isLoggable(Level.FINE)) {
	        _logger.log(Level.FINE, 
			    baseMsg + ".getSocketInfoForServer:" +
			    " adding address for "+ 
			    serverName + "/" + id +
			    "/" + hostName + "/" + port);
	    }
	    listOfSocketInfo.add(new SocketInfo(id, hostName, Integer.valueOf(port)));
	}
	return listOfSocketInfo;
    
private static booleanisEE()
Determines if the AS process is running in EE. XXX: to refactor this to use the common implementation. from PELaunch.java

        boolean isEE = false;
        final String eepffc = "com.sun.enterprise.ee.server.pluggable.EEPluggableFeatureImpl";
        final String pn = "com.sun.appserv.pluggable.features";
        final String pv = System.getProperty(pn);
        if (eepffc.equals(pv)) {
            isEE = true;
        }
        return ( isEE );