FileDocCategorySizeDatePackage
NamingService.javaAPI DocApache Tomcat 6.0.146635Fri Jul 20 04:20:34 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: 467222 $

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", 
             new Integer(STOPPED), new Integer(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) && (oldValue.length() > 0)) {
                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", 
                 new Integer(STARTING), new Integer(STOPPED));
            sendNotification(notification);
        }
        
        state = STARTED;
        notification = new AttributeChangeNotification
            (this, sequenceNumber++, System.currentTimeMillis(), 
             "Started " + NAME, "State", "java.lang.Integer", 
             new Integer(STARTING), new Integer(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", 
             new Integer(STARTED), new Integer(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", 
             new Integer(STOPPING), new Integer(STOPPED));
        sendNotification(notification);