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

ASORBUtilities

public class ASORBUtilities extends Object
author
Harold Carr

Fields Summary
private static Logger
_logger
private static final String
GMS_CLASS
private static boolean
gisInitialized
Constructors Summary
Methods Summary
public static booleanequals(com.sun.corba.ee.spi.folb.ClusterInstanceInfo c1, com.sun.corba.ee.spi.folb.ClusterInstanceInfo c2)

	if (c1 == c2) {
	    return true;
	}
	if (c1.weight != c2.weight) {
	    return false;
	}
	if (c1.endpoints.length != c2.endpoints.length) {
	    return false;
	}
	if (! c1.name.equals(c2.name)) {
	    return false;
	}
	for (int i = 0; i < c1.endpoints.length; ++i) {
	    if (c1.endpoints[i].port != c2.endpoints[i].port) {
		return false;
	    }
	    if (! c1.endpoints[i].type.equals(c2.endpoints[i].type)) {
		return false;
	    }
	    if (! c1.endpoints[i].host.equals(c2.endpoints[i].host)) {
		return false;
	    }
	}
	return true;
    
public static voidforceStackTrace(java.lang.String msg)

	forceStackTrace(msg, System.out);
    
public static voidforceStackTrace(java.lang.String msg, java.io.PrintStream out)

	try {
	    _logger.log(Level.INFO, msg + "->:");
	    throw new Exception("FORCED STACKTRACE");
	} catch (Exception e) {
	    e.printStackTrace(out);
	} finally {
	    _logger.log(Level.INFO, msg + "<-:");
	}
    
public static com.sun.enterprise.config.serverbeans.ClustergetCluster()

	ConfigContext configCtx = null;
	String instanceName = null;
	Cluster result = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".getCluster->:");
	    }
	    ServerContext serverContext = ApplicationServer.getServerContext();
	    if (serverContext == null) {
		if(_logger.isLoggable(Level.FINE)) {
		    _logger.log(Level.FINE, ".getCluster: No ServerContext");
		}
		return null;
	    }
	    configCtx = serverContext.getConfigContext();
	    instanceName = serverContext.getInstanceName();
	    result =
	        ClusterHelper.getClusterForInstance(configCtx, instanceName);
	} catch (ConfigException e) {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, 
			    ".getCluster: ConfigContext: " + configCtx.toString()
			    + " ; instanceName: " + instanceName
			    + " ; exception: " + e);
	    }
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".getCluster<-: " + result);
	    }
	}
	return result;
    
public static synchronized voidinitGIS(org.omg.CORBA.ORB orb)


         
    
	GroupInfoService gis = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, "initGIS->: " + gisInitialized);
	    }
	    if (gisInitialized) {
		return;
	    }
	    if (isGMSAvailableAndClusterHeartbeatEnabled()) {
		gis = initGISUsesGMS();
	    } else {
		gis = initGISUsesAdmin();
	    }
	    if (gis == null) {
		return;
	    }
	    try {
		((ORB)orb).register_initial_reference(
                    ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE,
		    (org.omg.CORBA.Object) gis);
		if(_logger.isLoggable(Level.FINE)) {
		    _logger.log(Level.FINE, 
				".initGIS: naming registration complete: "
				+ gis);
		}
		gisInitialized = true;

		if (_logger.isLoggable(Level.FINE)) {
		    gis = (GroupInfoService)
			((ORB)orb).resolve_initial_references(
                            ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE);
		    List<ClusterInstanceInfo> lcii = 
			gis.getClusterInstanceInfo(null);
		    _logger.log(Level.FINE,
				"Results from getClusterInstanceInfo:");
		    if (lcii != null) {
			for (ClusterInstanceInfo cii : lcii) {
			    _logger.log(Level.INFO, toString(cii));
			}
		    }
		}

	    } catch (InvalidName e) {
		if(_logger.isLoggable(Level.FINE)) {
		    _logger.log(Level.SEVERE,
				".initGIS: registering GIS failed: " + e);
		}
	    }
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, 
			    "initGIS<-: " + gisInitialized + " " + gis);
	    }
	}
    
private static com.sun.corba.ee.spi.folb.GroupInfoServiceinitGISUsesAdmin()

	GroupInfoService result = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, "initGISUsesAdmin->:");
	    }
	    result = new GroupInfoServiceImplForJNLP();
	    return result;
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE,  "initGISUsesAdmin<-: " + result);
	    }
	}
    
private static com.sun.corba.ee.spi.folb.GroupInfoServiceinitGISUsesGMS()

	GroupInfoService result = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, "initGISUsesGMS->:");
	    }

	    Class clazz = loadClass(GMS_CLASS);

	    if (clazz == null) {
		_logger.log(Level.SEVERE, 
			    ".initGISUsesGMS: GMS initialization failure: class not found: " + GMS_CLASS);
	    }

	    result = (GroupInfoService) newInstance(clazz);

	    if (result == null) {
		_logger.log(Level.SEVERE, ".initGISUsesGMS: GMS initialization failure: cannot instantiate: " + GMS_CLASS);
	    }

	    return result;

	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE,  "initGISUsesGMS<-: " + result);
	    }
	}
    
public static booleanisClusterHeartbeatEnabled(com.sun.enterprise.config.serverbeans.Cluster cluster)

	boolean result = false;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, 
			    ".isClusterHeartbeatEnabled->: " + cluster);
	    }
	    result = cluster.isHeartbeatEnabled();
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, 
			    ".isClusterHeartbeatEnabled<-: " + cluster 
			    + " " + result);
	    }
	}
	return result;
    
public static booleanisGMSAvailableAndClusterHeartbeatEnabled()

	Cluster cluster = null;
	boolean result =
	    (loadClass("com.sun.enterprise.ee.cms.core.GMSFactory") != null)
	    && (cluster = getCluster()) != null
	    && isClusterHeartbeatEnabled(cluster);
	return result;
    
public static java.lang.ClassloadClass(java.lang.String classname)

	Class result = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".loadClass->: " + classname);
	    }
	    result = ORBClassLoader.loadClass(classname);
	} catch (ClassNotFoundException e) {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".loadClass: " + classname + " " + e);
	    }
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, 
			    ".loadClass<-: " + classname + " " + result);
	    }
	}
	return result;
    
public static booleanmember(com.sun.corba.ee.spi.folb.ClusterInstanceInfo item, java.util.List list)

	for (ClusterInstanceInfo element : list) {
	    if (equals(item, element)) {
		return true;
	    }
	}
	return false;
    
public static java.lang.ObjectnewInstance(java.lang.Class clazz)

	Object result = null;
	try {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".newInstance->: " + clazz);
	    }
	    result = clazz.newInstance();
	} catch (InstantiationException e) {
	    _logger.log(Level.WARNING, ".newInstance: " + clazz + " " + e);
	} catch (IllegalAccessException e) {
	    _logger.log(Level.WARNING, ".newInstance: " + clazz + " " + e);
	} finally {
            if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE, ".newInstance<-: " + clazz + " " + result);
	    }
	}
	return result;
    
public static java.lang.StringtoString(com.sun.corba.ee.spi.folb.ClusterInstanceInfo cii)

	return
	    "[ClusterInstanceInfo "
	    + cii.name
	    + " "
	    + cii.weight
	    + " "
	    + toString(cii.endpoints)
	    + "]";

    
public static java.lang.StringtoString(com.sun.corba.ee.spi.folb.SocketInfo[] socketInfo)

	String result = "";
	for (int i = 0; i < socketInfo.length; ++i) {
	    result += toString(socketInfo[i]) + " ";
	}
	return result;
    
public static java.lang.StringtoString(com.sun.corba.ee.spi.folb.SocketInfo socketInfo)

	return
	    "[SocketInfo "
	    + socketInfo.type
	    + " " 
	    + socketInfo.host
	    + " " 
	    + socketInfo.port
	    + "]";