FileDocCategorySizeDatePackage
DASJ2EEServerImpl.javaAPI DocGlassfish v2 API16708Fri May 04 22:23:30 BST 2007com.sun.enterprise.management.j2ee

DASJ2EEServerImpl

public class DASJ2EEServerImpl extends J2EEServerImpl implements NotificationListener
JSR 77 extension representing an Appserver standalone server (non-clustered) Server MBean which will reside on DAS for enabling state management including start() and stop()

Fields Summary
private static final Class[]
DOMAIN_STATUS_INTERFACES
static final String
DAS_SERVER_NAME
The DAS is always named "server", or so inquiries suggest
private MBeanInfo
mMBeanInfo
Constructors Summary
public DASJ2EEServerImpl()

		super( J2EETypes.J2EE_SERVER, DummyDelegate.INSTANCE );
	
Methods Summary
protected com.sun.enterprise.admin.mbeans.DomainStatusMBeangetDomainStatus()

	
		 
	
	
		DomainStatusMBean	domainStatus	= null;
		try {
			final MBeanServer	mbeanServer = getMBeanServer();
			final Set<ObjectName>	candidates	= QueryMgrImpl.queryPatternObjectNameSet( 
				mbeanServer, JMXUtil.newObjectNamePattern( 
					"*", DomainStatusMBean.DOMAIN_STATUS_PROPS ) );
			final ObjectName on = GSetUtil.getSingleton( candidates );
			domainStatus = (DomainStatusMBean)MBeanServerInvocationHandler.
				newProxyInstance( mbeanServer, on, DomainStatusMBean.class, false );
		} catch (Exception e) {
			final Throwable rootCause = ExceptionUtil.getRootCause( e );
			getMBeanLogger().warning( rootCause.toString() + "\n" +
				ExceptionUtil.getStackTrace( rootCause ) );
		}
		return( domainStatus );
	
private javax.management.MBeanAttributeInfo[]getMBeanAttributeInfo()

		MBeanAttributeInfo[] dAttributes = new MBeanAttributeInfo[1];
		dAttributes[0] = new MBeanAttributeInfo("state",
                                                "java.lang.Integer",
                                                "server state",
                                                true,
                                                false,
                                                false);
		return dAttributes;
	
public synchronized javax.management.MBeanInfogetMBeanInfo()

    
		  
	
	
        // compute the MBeanInfo only once!
        if ( mMBeanInfo == null )
        {
            final MBeanInfo	superMBeanInfo	= super.getMBeanInfo();
            mMBeanInfo	= new MBeanInfo(
                superMBeanInfo.getClassName(),
                superMBeanInfo.getDescription(),
                mergeAttributeInfos(superMBeanInfo.getAttributes(), getMBeanAttributeInfo()),
                superMBeanInfo.getConstructors(),
                mergeOperationInfos(superMBeanInfo.getOperations(), getMBeanOperationInfo()),
                superMBeanInfo.getNotifications() );
        }
        return mMBeanInfo;
	
private javax.management.MBeanOperationInfo[]getMBeanOperationInfo()

		MBeanOperationInfo[] dOperations = new MBeanOperationInfo[3];
		dOperations[0] = new MBeanOperationInfo("start",
                                                "start server instance",
                                                null,
                                                "void",
                                                MBeanOperationInfo.ACTION);
		dOperations[1] = new MBeanOperationInfo("stop",
                                                "stop server instance",
                                                null,
                                                "void",
                                                MBeanOperationInfo.ACTION);
		dOperations[2] = new MBeanOperationInfo("startRecursive",
                                                "start server instance",
                                                null,
                                                "void",
                                                MBeanOperationInfo.ACTION);
		return dOperations;
	
public booleangetRestartRequired()

        // there might not be a Delegate.  Default to 'true', since a non-running server
        // must be restarted!
        boolean required    = true;
        if ( getDelegate() != null )
        {
            try {
                final Object result  = getDelegate().getAttribute( "restartRequired" );
                required    = Boolean.valueOf( "" + result );
            }
            catch( AttributeNotFoundException e ) {
                logWarning( ExceptionUtil.toString(e) );
                required    = true;
            }
        }
        return required;
	
protected java.lang.StringgetServerName()

		return( getSelfName() );
	
public intgetstate()

		try {
			return (getDomainStatus().getstate(getServerName()));
		} catch (Exception e) {
            final Throwable rootCause       = ExceptionUtil.getRootCause( e );
            getMBeanLogger().warning( rootCause.toString() + "\n" +
                            ExceptionUtil.getStackTrace( rootCause ) );
        }
		return StateManageable.STATE_FAILED;
 	
public voidhandleNotification(javax.management.Notification notif, java.lang.Object obj)

		final String	notifType	= notif.getType();
		
		if ( notifType.equals( DomainStatusMBean.SERVER_STATUS_NOTIFICATION_TYPE ) )
		{
			final String	serverName = (String)
			    Util.getAMXNotificationValue( notif, DomainStatusMBean.SERVER_NAME_KEY );
			
			if ( serverName.equals( getServerName() ) )
			{
				setDelegate();
			}
		}
	
private booleanisDASJ2EEServer()
Does this particular J2EEServer represent the DAS?

    
                       
         
    
    
        return DAS_SERVER_NAME.equals( getName() );
    
public booleanisstateManageable()

		return true;
	
private javax.management.MBeanAttributeInfo[]mergeAttributeInfos(javax.management.MBeanAttributeInfo[] infos1, javax.management.MBeanAttributeInfo[] infos2)

		final MBeanAttributeInfo[] infos =
			new MBeanAttributeInfo[ infos1.length + infos2.length ];
		
		System.arraycopy( infos1, 0, infos, 0, infos1.length );
		System.arraycopy( infos2, 0, infos, infos1.length, infos2.length );
		
		return( infos );
	
private javax.management.MBeanOperationInfo[]mergeOperationInfos(javax.management.MBeanOperationInfo[] infos1, javax.management.MBeanOperationInfo[] infos2)

		final MBeanOperationInfo[] infos =
			new MBeanOperationInfo[ infos1.length + infos2.length ];
		
		System.arraycopy( infos1, 0, infos, 0, infos1.length );
		System.arraycopy( infos2, 0, infos, infos1.length, infos2.length );
		
		return( infos );
	
public voidpreRegisterDone()

		super.preRegisterDone( );
		
		setstartTime( 0 );
		setDelegate();
	
private booleanremoteServerIsRunning()

		return (StateManageable.STATE_RUNNING == getstate());
	
private booleanremoteServerIsStartable()

		final int cState = getstate();

		return  (StateManageable.STATE_STOPPED == cState) ||
                (StateManageable.STATE_FAILED == cState);
	
private booleanremoteServerIsStoppable()

		int cState = getstate();

		if ((StateManageable.STATE_STARTING == cState) ||
		    (StateManageable.STATE_RUNNING == cState) ||
		    (StateManageable.STATE_FAILED == cState)) 
		{
			return true;
		} 
		else 
		{
			return false;
		}
	
private synchronized voidsetDelegate()

		if ( remoteServerIsRunning() )
		{
		    try {
                // get the object name for the old jsr77 server mBean
                com.sun.enterprise.ManagementObjectManager mgmtObjManager =
                    com.sun.enterprise.Switch.getSwitch().getManagementObjectManager();

                final String strON = mgmtObjManager.getServerBaseON(false, getServerName());
                
                final MBeanServerConnection remoteConn	=
                    getDomainStatus().getServerMBeanServerConnection( getServerName() );
                    
                final ObjectName onPattern = new ObjectName(strON + ",*");

                final Set<ObjectName> names = JMXUtil.queryNames( remoteConn, onPattern, null);

                assert( names.size() == 1 );

                final ObjectName serverON = GSetUtil.getSingleton( names );
                final Delegate	delegate = new DelegateToMBeanDelegate( remoteConn, serverON );
                
                setDelegate( delegate );
                setstartTime(System.currentTimeMillis());
		    }
            catch (Exception e) {
                final Throwable rootCause = ExceptionUtil.getRootCause( e );
                getMBeanLogger().warning(
                    rootCause.toString() + "\n" + ExceptionUtil.getStackTrace( rootCause ) );
            }
		}
		else
		{
			setDelegate( DummyDelegate.INSTANCE );
			setstartTime(0);
		}
	
public voidstart()

 		if ( remoteServerIsStartable() )
 		{
 			startRemoteServer();
 		}
 		else
 		{
			throw new RuntimeException("server is not in a startable state");
 		}
 	
public voidstartRecursive()

 		start();
 	
private voidstartRemoteServer()


		try {
			// get the object name for servers config mBean
			ObjectName on = DomainStatusHelper.getServersConfigObjectName();

			// invoke start method on servers config mBean

			// get mBean server
			final MBeanServer server = getMBeanServer();

			// form the parameters
			Object[] params = new Object[1];
                	params[0] = getServerName();
                	String[] signature = {"java.lang.String"};

			// invoke the start method
                	server.invoke(on, "startServerInstance", params, signature);
		} catch (javax.management.MalformedObjectNameException mfone) {
                        final Throwable rootCause       = ExceptionUtil.getRootCause( mfone );
                        getMBeanLogger().warning( rootCause.toString() + "\n" +
                                        ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(mfone);
		} catch (javax.management.InstanceNotFoundException infe) {
                        final Throwable rootCause       = ExceptionUtil.getRootCause( infe );
                        getMBeanLogger().warning( rootCause.toString() + "\n" +
                                        ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(infe);
		} catch (javax.management.MBeanException mbe) {
                        final Throwable rootCause       = ExceptionUtil.getRootCause( mbe );
                        getMBeanLogger().warning( rootCause.toString() + "\n" +
                                        ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(mbe);
		} catch (javax.management.ReflectionException rfe) {
                        final Throwable rootCause       = ExceptionUtil.getRootCause( rfe );
                        getMBeanLogger().warning( rootCause.toString() + "\n" +
                                        ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(rfe);
		}
	
public voidstop()

        if ( isDASJ2EEServer()  )
        {
            getDelegate().invoke( "stop", (Object[])null, (String[])null);
        }
        else if ( remoteServerIsStoppable() )
        {
            stopRemoteServer();
        }
        else
        {
            throw new RuntimeException("server is not in a stoppable state");
        }
    
private voidstopRemoteServer()

		try {
			// get the object name for servers config mBean
			ObjectName on = DomainStatusHelper.getServersConfigObjectName();

			// invoke stop method on servers config mBean

			// get mBean server
			final MBeanServer server = getMBeanServer();

			// form the parameters
			Object[] params = new Object[1];
                	params[0] = getServerName();
                	String[] signature = {"java.lang.String"};

			// invoke the start method
                	server.invoke(on, "stopServerInstance", params, signature);
		} catch (javax.management.MalformedObjectNameException mfone) {
                        final Throwable rootCause       = ExceptionUtil.getRootCause( mfone );
                        getMBeanLogger().warning( rootCause.toString() + "\n" +
                                        ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(mfone);
		} catch (javax.management.InstanceNotFoundException infe) {
			// in case of PE and DAS 
			// it is desit]rable that the instance be not stopped
			// hence the log level is fine
            final Throwable rootCause       = ExceptionUtil.getRootCause( infe );
            getMBeanLogger().fine( rootCause.toString() + "\n" +
                            ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(infe);
		} catch (javax.management.MBeanException mbe) {
            final Throwable rootCause       = ExceptionUtil.getRootCause( mbe );
            getMBeanLogger().warning( rootCause.toString() + "\n" +
                            ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(mbe);
		} catch (javax.management.ReflectionException rfe) {
            final Throwable rootCause       = ExceptionUtil.getRootCause( rfe );
            getMBeanLogger().warning( rootCause.toString() + "\n" +
                            ExceptionUtil.getStackTrace( rootCause ) );
			throw new RuntimeException(rfe);
		}