FileDocCategorySizeDatePackage
NamingService.javaAPI DocGlassfish v2 API7604Fri May 04 22:33:00 BST 2007org.apache.naming

NamingService

public final class NamingService extends NotificationBroadcasterSupport implements NamingServiceMBean, MBeanRegistration
Implementation of the NamingService JMX MBean.
author
Remy Maucherat
version
$Revision: 1.4 $

Fields Summary
private int
state
Status of the Slide domain.
private long
sequenceNumber
Notification sequence number.
private String
oldUrlValue
Old URL packages value.
private String
oldIcValue
Old initial context value.
Constructors Summary
Methods Summary
public voiddestroy()
Destroy servlet container (if any is running).

        
        if (getState() != STOPPED)
            stop();
        
    
public java.lang.StringgetName()
Retruns the Catalina component name.

        return NAME;
    
public intgetState()
Returns the state.

        return state;
    
public java.lang.StringgetStateString()
Returns a String representation of the state.

        return states[state];
    
public voidpostDeregister()

        destroy();
    
public voidpostRegister(java.lang.Boolean registrationDone)

        if (!registrationDone.booleanValue())
            destroy();
    
public voidpreDeregister()

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

    
    
    // ---------------------------------------------- MBeanRegistration Methods
    
    
         
          
        return new ObjectName(OBJECT_NAME);
    
public voidstart()
Start the servlet container.

        
        Notification notification = null;
        
        if (state != STOPPED)
            return;
        
        state = STARTING;
        
        // Notifying the MBEan server that we're starting
        
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(), 
             "Starting " + NAME, "State", "java.lang.Integer", 
             Integer.valueOf(STOPPED), Integer.valueOf(STARTING));
        sendNotification(notification);
        
        try {
            
            String value = "org.apache.naming";
            String oldValue = System.getProperty(Context.URL_PKG_PREFIXES);
            if (oldValue != null) {
                oldUrlValue = oldValue;
                value = oldValue + ":" + value;
            }
            System.setProperty(Context.URL_PKG_PREFIXES, value);
            
            oldValue = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
            if (oldValue != null) {
                oldIcValue = oldValue;
            } else {
                System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
                                   Constants.Package 
                                   + ".java.javaURLContextFactory");
            }
            
        } catch (Throwable t) {
            state = STOPPED;
            notification = new AttributeChangeNotification
                (this, sequenceNumber++, System.currentTimeMillis(), 
                 "Stopped " + NAME, "State", "java.lang.Integer", 
                 Integer.valueOf(STARTING), Integer.valueOf(STOPPED));
            sendNotification(notification);
        }
        
        state = STARTED;
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(), 
             "Started " + NAME, "State", "java.lang.Integer", 
             Integer.valueOf(STARTING), Integer.valueOf(STARTED));
        sendNotification(notification);
        
    
public voidstop()
Stop the servlet container.

        
        Notification notification = null;
        
        if (state != STARTED)
            return;
        
        state = STOPPING;
        
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(), 
             "Stopping " + NAME, "State", "java.lang.Integer", 
             Integer.valueOf(STARTED), Integer.valueOf(STOPPING));
        sendNotification(notification);
        
        try {
            
            System.setProperty(Context.URL_PKG_PREFIXES, oldUrlValue);
            System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldIcValue);
            
        } catch (Throwable t) {
            
            // FIXME
            t.printStackTrace();
            
        }
        
        state = STOPPED;
        
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(), 
             "Stopped " + NAME, "State", "java.lang.Integer", 
             Integer.valueOf(STOPPING), Integer.valueOf(STOPPED));
        sendNotification(notification);