FileDocCategorySizeDatePackage
MBeanServerRequestHandler.javaAPI DocGlassfish v2 API10727Fri May 04 22:36:26 BST 2007com.sun.enterprise.admin.jmx.remote.server

MBeanServerRequestHandler

public class MBeanServerRequestHandler extends Object
Handles the request that is received from the servlet. Responsible for producing a guaranteed MBeanServerResponseMessage. Delegates the requests to the System MBean Server. Currently it searches for the MBeanServer after finding the list of MBeanServers.
author
Kedar Mhaswade
since
S1AS8.0
version
1.0

Fields Summary
private final Set
callers
Creates a new instance of MBeanServerResponseHandler
private static final Logger
logger
private static com.sun.enterprise.admin.jmx.remote.protocol.Version
sv
private static final ServerVersionMatcher
matcher
private com.sun.enterprise.admin.jmx.remote.server.notification.ServerNotificationManager
notifyMgr
Constructors Summary
public MBeanServerRequestHandler(ServletConfig cfg)


//    public MBeanServerRequestHandler() {
       
        MBeanServerConnection mbsc = getMBeanServerConnection(cfg);
        notifyMgr = new ServerNotificationManager(mbsc);
        notifyMgr.setBufSiz(cfg);
//        callers	= MethodCallers.callers(getMBeanServerConnection());
        callers	= MethodCallers.callers(mbsc, notifyMgr);
/* END -- S1WS_MOD */
		logger.finer("Server Jmx Connector Version: " + sv.toString());
    
Methods Summary
private javax.management.MBeanServerConnectiongetMBeanServerConnection(javax.servlet.ServletConfig cfg)

		//first get through reflection.
        String factoryClass = cfg.getInitParameter(DefaultConfiguration.MBEANSERVER_FACTORY_PROPERTY_NAME);
//		final MBeanServerConnection mbsc = introspectMBS();
		final MBeanServerConnection mbsc = introspectMBS(factoryClass);
/* END -- S1WS_MOD */
		if (mbsc != null) {
			return mbsc;
		}
        final java.util.ArrayList servers = MBeanServerFactory.findMBeanServer(null);
        final MBeanServer systemMBS = (MBeanServer)servers.get(0);
        return ((MBeanServerConnection)systemMBS);
    
public com.sun.enterprise.admin.jmx.remote.server.notification.ServerNotificationManagergetNotificationManager()

        return notifyMgr;
    
public javax.management.remote.message.MBeanServerResponseMessagehandle(javax.management.remote.message.MBeanServerRequestMessage request0)

		assert (request0.getParams().length >= 1) : "Invalid Object Array"; //has to have at least one elem
        MBeanServerResponseMessage response = null;
		final Version cv = (Version)request0.getParams()[0];
		logger.finer("Client Version = " + cv.toString());
		if (! isCompatible(cv)) {
			response = incompatibleVersionMessage(request0);
			return ( response );
		}
		//should come here iff the version is compatible.
		final MBeanServerRequestMessage request = removeVersion(request0);
        boolean handled = false;
        final Iterator iter = callers.iterator();
        while (iter.hasNext()) {
            final MBeanServerConnectionMethodCaller caller =
            (MBeanServerConnectionMethodCaller)iter.next();
            if (caller.canCall(request)) {
                response = caller.call(request);
                handled = true;
                break;
            }
        }
        assert handled : "The request is not handled -- catastrophe";
        return ( response );
    
private javax.management.remote.message.MBeanServerResponseMessageincompatibleVersionMessage(javax.management.remote.message.MBeanServerRequestMessage r)

		//should come in this method only in case of incompatible versions
		final int id				= r.getMethodId();
		final boolean isException	= true;
		final Version cv = (Version)r.getParams()[0];
		Exception e = null;
		assert (! isCompatible(cv)) : "No message for compatible versions";
		
		if (! matcher.majorCompatible(cv, sv)) {
			e = majorVersionIncompatible(cv, sv);
		}
		else if (! matcher.minorCompatible(cv, sv)) {
			e = minorVersionIncompatible(cv, sv);
		}
		else if (! matcher.upgradeCompatible(cv, sv)) {
			e = upgradeIncompatible(cv, sv);
		}
		assert (e != null) : "Either minor/major version or upgrade data have to fail the match";
		
		return ( new MBeanServerResponseMessage(id, e, isException) );
	
private javax.management.MBeanServerConnectionintrospectMBS(java.lang.String factoryClass)
Returns the instance of S1AS MBeanServer. This information could well come from deployment descriptor, but for now I am hardcoding it -- 08/04/03. Returns a null if none could be found.

return
MBeanServerConnection instance or null

/* END -- S1WS_MOD */
		MBeanServerConnection mbsc = null;
/* BEGIN -- S1WS_MOD */
		//final String FACTORY_CLASS = "com.sun.enterprise.admin.common.MBeanServerFactory";
		String FACTORY_CLASS = factoryClass;
        if (factoryClass == null || factoryClass.trim().length() == 0)
            FACTORY_CLASS = System.getProperty(DefaultConfiguration.MBEANSERVER_FACTORY_PROPERTY_NAME);
/* END -- S1WS_MOD */
		final String FACTORY_METHOD = "getMBeanServer";
/* BEGIN -- S1WS_MOD */
        if (FACTORY_CLASS == null || FACTORY_CLASS.trim().length() == 0)
            return null;
/* END -- S1WS_MOD */
		try {
			logger.finer("Introspecting the MBeanServerConnection");
			final Class c = Class.forName(FACTORY_CLASS); //loaded by the same CL
			final Method m = c.getMethod(FACTORY_METHOD, null);
			final Object r = m.invoke(c, null);
			assert (r instanceof MBeanServer) : "Reflection does not return the correct type";
			mbsc = (MBeanServerConnection)r;
			logger.finer("Introspected the MBeanServerConnection successfully!!");
		}
		catch (Throwable t) {
			logger.throwing(this.getClass().getName(), "introspectMBS", t);
		}
		return ( mbsc );
	
private booleanisCompatible(com.sun.enterprise.admin.jmx.remote.protocol.Version cv)

		return ( matcher.match(cv, sv) );
	
private java.lang.ExceptionmajorVersionIncompatible(com.sun.enterprise.admin.jmx.remote.protocol.Version cv, com.sun.enterprise.admin.jmx.remote.protocol.Version sv)

		//i18n
		final StringBuffer sb = new StringBuffer();
		sb.append("The major versions don't match: ").
		append("Client Major Version = " + cv.getMajorVersion()).
		append("Server Major Version = " + sv.getMajorVersion()).
		append(" Upgrade the software accordingly");
		
		return ( new RuntimeException(sb.toString()) );
	
private java.lang.ExceptionminorVersionIncompatible(com.sun.enterprise.admin.jmx.remote.protocol.Version cv, com.sun.enterprise.admin.jmx.remote.protocol.Version sv)

		//i18n
		final StringBuffer sb = new StringBuffer();
		sb.append("The minor versions don't match: ").
		append("Client Minor Version = " + cv.getMinorVersion()).
		append("Server Minor Version = " + sv.getMinorVersion()).
		append(" Upgrade the software accordingly");
		
		return ( new RuntimeException(sb.toString()) );
	
private javax.management.remote.message.MBeanServerRequestMessageremoveVersion(javax.management.remote.message.MBeanServerRequestMessage from)

		final int id = from.getMethodId();
		final Subject s = from.getDelegationSubject();
		final Shifter sh = new Shifter(from.getParams());
		sh.shiftLeft();
		final Object[] np = sh.state();
		return ( new MBeanServerRequestMessage(id, np, s) );
	
private java.lang.ExceptionupgradeIncompatible(com.sun.enterprise.admin.jmx.remote.protocol.Version cv, com.sun.enterprise.admin.jmx.remote.protocol.Version sv)

		//i18n
		final StringBuffer sb = new StringBuffer();
		sb.append("The upgrade data in versions does not match: ").
		append("Client Upgrade Data = " + cv.toString()).
		append("Server Upgrade Data = " + sv.toString()).
		append(" Upgrade the software accordingly");
		
		return ( new RuntimeException(sb.toString()) );