FileDocCategorySizeDatePackage
AdminChannel.javaAPI DocGlassfish v2 API15781Fri May 04 22:33:46 BST 2007com.sun.enterprise.admin.server.core.channel

AdminChannel

public class AdminChannel extends Object
Admin channel is used for communication between admin service agents running in different server instances.

Fields Summary
static final Logger
logger
A reference to logger object
static volatile String
instanceRoot
static final String
fileSeparator
static final int
SEED_LENGTH
private static volatile AdminChannelServer
server
private static final Map
rmiClientMap
private static com.sun.enterprise.util.i18n.StringManager
localStrings
static final String
stubFileName
static final String
seedFileName
static final String
LOCAL_ONLY_ACCESS
static final String
ALLOW_ALL_ACCESS
static final String
ENFORCE
static final String
REQUIRE_KEY
static final String
NO_ENFORCE
static final String
RECONFIG_ENABLE_ERROR
static final String
SERVER_CREATION_ERRCODE
static final String
KEY_READ_ERROR
static final String
KEY_WRITE_ERROR
static final String
PROP_SERVER_PORT
Constructors Summary
Methods Summary
private static final voidassertAdminServerChannelNotNull()
Assert than Admin server channel is not null.

throws
RuntimeException if admin server channel is null.

        if (server == null) {
			String msg = localStrings.getString( "admin.server.core.channel.admin_server_channel_not_initialized" ); 
            throw new RuntimeException( msg );
        }
    
public static synchronized voidcreateRMIChannel()
Create a RMI channel. This method creates a server object and exposes the stub on local filesystem.


                          
           
        try {
            server = createServerObject();
            saveStubToFile(server.getRemoteStub());
        } catch (Exception e) {
            warn(SERVER_CREATION_ERRCODE);
            debug(e);
            throw new ServerLifecycleException(e);
        }
    
private static AdminChannelServercreateServerObject()
Create server object that serves RMI client. If local loopback address can be determined the server object listens on only local loopback address, otherwise it listens on all interfaces (default RMI behavior).

        AdminChannelServer server = null;
        InetAddress localAddress = getLocalLoopbackAddress();
        if (localAddress == null) {
            server = new AdminChannelServer();
        } else {
            LocalRMIClientSocketFactory csf =
                    new LocalRMIClientSocketFactory(localAddress);
            LocalRMIServerSocketFactory ssf =
                    new LocalRMIServerSocketFactory(localAddress);
            int port = 0;
            port = Integer.getInteger(
                PROP_SERVER_PORT, new Integer(port)).intValue();
            server = new AdminChannelServer(port, csf, ssf);            
            server = new AdminChannelServer(0, csf, ssf);
            server.setLocalAddress(localAddress);
        }
        return server;
    
public static synchronized voidcreateSharedSecret()
Create a shared secret. The shared secret is saved on the filesystem and is verified during every call on admin channel.

        
        assertAdminServerChannelNotNull();
        String fileName = getSeedFileName();
        File seedFile = new File(fileName);
        byte[] prevSeed = getPreviousSeed(seedFile);
        SecureRandom sr = new SecureRandom(prevSeed);
        byte[] seed = new byte[SEED_LENGTH];
        sr.nextBytes(seed);
        saveSeedToFile(seed, seedFile);
        server.setSharedInfo(seed);
        server.setChannelStarting();
    
static voiddebug(java.lang.String s)

        logger.fine(s);
    
static voiddebug(java.lang.String msgkey, java.lang.String obj1)

        logger.log(Level.FINE, msgkey, obj1);
    
static voiddebug(java.lang.String msgkey, java.lang.Object[] objarr)

        logger.log(Level.FINE, msgkey, objarr);
    
static voiddebug(java.lang.Throwable t)

        logger.log(Level.FINE, t.getMessage(), t);
    
private static voiddeleteStubFile()
Cleanup stub file (is invoked on shutdown)

        String fileName = getStubFileName();
        new File(fileName).delete();
    
public static synchronized voiddestroyRMIChannel()
Remove RMI channel. Remove the server object from JVM (do not accept any more calls and abort in process calls) and clean up the stub exposed on filesystem.

        if (server != null) {
            server.setChannelStopping();
            try {
                UnicastRemoteObject.unexportObject(server, true);
            } catch (NoSuchObjectException nsoe) {
                throw new ServerLifecycleException(nsoe);
            }
        }
        deleteStubFile();
    
public static voidenableWebCoreReconfig()
Enable reconfiguration of Sun ONE Web Server core.

        try {
            ReconfigHelper.enableWebCoreReconfig();
        } catch (Throwable t) {
            // If reconfiguration could not be enabled log a warning
            // message and continue
            warn(RECONFIG_ENABLE_ERROR );
            debug(t);
        }
    
static java.lang.StringgetAccessLevel()
Get access level. FIX to use config parameter


                 
       
        return LOCAL_ONLY_ACCESS;
    
static booleangetClientAutoRefreshEnabled()
Is Auto Refresh enabled for RMIClient objects (so they will keep on scanning file system for changes to stub file and reset themselves). FIX to use config parameter

        return true;
    
static longgetClientAutoRefreshInterval()
How frequently should the RMI client objects refresh themselves (in milliseconds). FIX to use config parameter

        // 1 minute
        return (1 * 60 * 1000);
    
static java.lang.StringgetInstanceRoot()


    //Begin EE: 4921345 instanceRoot cannot be statically initialized since it relies on
    //a system property which may not be set until startup time. This removes the
    //dependency ond AdminService.
       
        if (instanceRoot == null) {            
            instanceRoot = System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
        }
        return instanceRoot;
    
static java.lang.StringgetKeyCheckLevel()
Get key check level. FIX to use config parameter.


                  
       
        return ENFORCE;
    
private static java.net.InetAddressgetLocalLoopbackAddress()
Get local loopback address.

return
local loopback address, if it can be determined, null otherwise

        InetAddress localAddr = null;
        try {
            localAddr = InetAddress.getByName(null);
            if (!localAddr.isLoopbackAddress()) {
                localAddr = null;
            }
        } catch (Throwable t) {
            // Catch all exceptions and return null to the caller
            localAddr = null;
        }
        return localAddr;
    
private static byte[]getPreviousSeed(java.io.File seedFile)
Get previous seed. This seed is read either from previous session's shared secret file or initialized using SecureRandom.getSeed (if the shared secret file does not exist). This seed is then used with SecureRandom to generate next key value.

        boolean haveSeed = false;
        byte[] prevSeed = new byte[SEED_LENGTH];

        // Using secure.seed bits to mix in a few extra bits of randomness
        // since we cannot use SecureRandoms built-in seeding.
        // Read bugs 4703002 and 4709460 for some background on this.
        SecureRandom sr = 
            com.sun.enterprise.server.J2EEServer.secureRandom;
        assert (sr != null);    // was initialized early on startup
        sr.setSeed(System.currentTimeMillis());
        
        if (seedFile.exists() && seedFile.canRead()) {
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(seedFile);
                fis.read(prevSeed);
                sr.setSeed(prevSeed);
                sr.nextBytes(prevSeed);
                haveSeed = true;
            } catch (IOException ioe) {
                warn(KEY_READ_ERROR);
                debug(ioe);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException ioe) {
                    }
                }
            }
        }
        if (!haveSeed) {
            sr.nextBytes(prevSeed);
        }
        return prevSeed;
    
public static synchronized RMIClientgetRMIClient(java.lang.String instanceName)
Get RMI client for specified instance.

        //KE FIXME: All of this code is obsolete whent the stub file 
        //is removed.
        RMIClient client = (RMIClient)rmiClientMap.get(instanceName);
        if (client == null) {
            client = new RMIClient(getStubFileName(),
                    getSeedFileName());
            rmiClientMap.put(instanceName, client);
        }
        return client;
    
static java.lang.StringgetSeedFileName()


       
        return getInstanceRoot() + fileSeparator 
                + Constants.CONFIG_DIR_NAME + fileSeparator
                + seedFileName;
    
static java.lang.StringgetStubFileName()

        return getInstanceRoot() + fileSeparator 
                + Constants.CONFIG_DIR_NAME + fileSeparator
                + stubFileName;
    
private static voidsaveSeedToFile(byte[] seed, java.io.File seedFile)
Save shared secret in file (so that it becomes shared)

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(seedFile);
            fos.write(seed);
        } catch (IOException ioe) {
            warn(KEY_WRITE_ERROR);
            debug(ioe);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException ioe) {
                }
            }
        }
    
private static voidsaveStubToFile(java.rmi.server.RemoteStub stub)
Save remote stub for admin channel server to file.

        
        String fileName = getStubFileName();
        try {
            File file = new File(fileName);
            FileOutputStream fos = new FileOutputStream(file);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(stub);
            fos.close();
        } catch (Exception e) {
			String msg = localStrings.getString( "admin.server.core.channel.unable_saving_stub_to_file", fileName );	
            throw new RuntimeException( msg, e );
        }
    
public static voidsetRMIChannelAborting(int port)
Set the channel to failed state. If the client detects this state, then it will try to get the port number that caused failure from the channel.

param
port port number.

        assertAdminServerChannelNotNull();
        server.setChannelAborting(port);
    
public static synchronized voidsetRMIChannelReady()
Set channel to ready state. This means that the server instance that initialized the channel is ready to serve client requests.

throws
RuntimeException if the channel has not been initialized

        assertAdminServerChannelNotNull();
        server.setChannelReady();
    
public static synchronized voidsetRMIChannelStopping()

        assertAdminServerChannelNotNull();
        server.setChannelStopping();
    
static voidtrace(java.lang.Throwable t)

        logger.log(Level.FINEST, t.getMessage(), t);
    
static voidwarn(java.lang.String s)

        logger.warning(s);
    
static voidwarn(java.lang.String msgkey, java.lang.String obj1)

        logger.log(Level.WARNING, msgkey, obj1);