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

AdminChannelServer

public class AdminChannelServer extends UnicastRemoteObject implements RemoteAdminChannel
RMI server object for admin channel.

Fields Summary
private String
localAddress
private byte[]
myKey
private int
instanceStatus
Server instance status. Its value is one of the constant kInstanceStartingCode, kInstanceRunningCode or kInstanceStoppingCode from the class com.sun.enterprise.admin.common.Status.
private boolean
restartNeeded
Is restart needed on this server instance to sync it up with persistent configuration.
private int
conflictedPort
private static final String
CLIENT_HOST_NULL
private static final String
LOCAL_ACCESS
private static final String
ADDR_MISMATCH
private static final String
NO_LOCAL_HOST
private static final String
KEY_MISMATCH
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public AdminChannelServer()
Create a new RMI server object for admin channel


                  
        
        super();

        // read from the persisted state
        restartNeeded = RRStateFactory.getState();
    
public AdminChannelServer(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
Create a new RMI server object for admin channel that uses specified socket factories.

        super(port, csf, ssf);

        // read from the persisted state
        restartNeeded = RRStateFactory.getState();
    
Methods Summary
private booleanaddressMatches(java.lang.String addr)
Check whether local address of the server object is same as specified address.

        String localAddr = getLocalAddress();
        if (localAddr == null) {
            return false;
        }
        return addr.equals(localAddr);
    
private booleancheckAccess()
Verify that client is coming from the same IP address as the server.

        boolean allowed = true;
        String addr = null;
        if (AdminChannel.LOCAL_ONLY_ACCESS.equals(AdminChannel.getAccessLevel())) {
            boolean matchAddress = true;
            try {
                addr = this.getClientHost();
                if (addr == null) {
                    AdminChannel.warn(CLIENT_HOST_NULL);
                    allowed = false;
                    matchAddress = false;
                }
            } catch (ServerNotActiveException snae) {
                AdminChannel.warn(LOCAL_ACCESS);
                AdminChannel.debug(snae);
                matchAddress = false;
            }
            if (matchAddress) {
                allowed = addressMatches(addr);
            }
        }
        if (!allowed) {
            AdminChannel.debug(ADDR_MISMATCH,
                    new Object[] {addr, getLocalAddress()});
        }
        return allowed;
    
private booleancheckKeyLength(byte[] key)
Check whether specified key is of correct length.

        return (key.length == AdminChannel.SEED_LENGTH);
    
public intgetConflictedPort(byte[] key)
Returns the port number that caused conflict. This could be 0, if port-conflict is not the cause of failure.

param
key shared secret
return
port number.

        if (!checkAccess()) {
                        String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
                        String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        return conflictedPort;
    
private java.lang.StringgetLocalAddress()
Get local address for the server object. If local address has not been initialized, it is initialized using InetAddress.getLocalHost() .

        if (localAddress == null) {
            InetAddress inetAddr = null;
            try {
                inetAddr = InetAddress.getLocalHost();
            } catch (UnknownHostException uhe) {
                AdminChannel.warn(NO_LOCAL_HOST);
                AdminChannel.debug(uhe);
            }
            if (inetAddr != null) {
                localAddress = inetAddr.getHostAddress();
            }
        }
        return localAddress;
    
java.rmi.server.RemoteStubgetRemoteStub()
Get remote stub for the server object.

        return (RemoteStub)RemoteObject.toStub(this);
    
public intgetServerStatusCode(byte[] key)
Get server status code. This method will return one of the following constants from class com.sun.enterprise.admin.common.Status -- kInstanceStartingCode, kInstanceRunningCode or kInstanceStoppingCode representing starting, running and stopping condition for the instance.

param
key shared secret
returns
server status code denoting whether server is starting, running or stopping.

        if (!checkAccess()) {
			String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
			String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        return instanceStatus;
    
public booleanisRestartNeeded(byte[] key)
Is restart needed to use persistent server configuration. After a notification, the server may be in inconsistenet state with respect to persistent configuration because all changes to configuration can not be handled dynamically - A restart is needed in such cases to synchronize server with persistent configuration.

param
key shared secret
return
true if restart is required, false otherwise.

        if (!checkAccess()) {
			String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
			String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        return restartNeeded;
    
private booleankeyMatches(byte[] key)
Check whether shared secret for the server object matches the specified key.

        boolean matches = true;
        if (AdminChannel.ENFORCE.equals(AdminChannel.getKeyCheckLevel())) {
            matches = checkKeyLength(key);
            for (int i = 0; matches && i < AdminChannel.SEED_LENGTH; i++) {
                if (key[i] != myKey[i]) {
                    matches = false;
                }
            }
        } else if (AdminChannel.REQUIRE_KEY.equals(AdminChannel.getKeyCheckLevel())) {
            matches = checkKeyLength(key);
        }
        if (!matches) {
            AdminChannel.debug(KEY_MISMATCH,
                    new Object[] {new String(key), new String(myKey)});
        }
        return matches;
    
public booleanpingServer(byte[] key)
Ping server. If the method call succeeds, notifications can be sent.

        if (!checkAccess()) {
			String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
			String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        return true;
    
public com.sun.enterprise.admin.event.AdminEventResultsendNotification(byte[] key, com.sun.enterprise.admin.event.AdminEvent event)
Send event notification.

        if (!checkAccess()) {
			String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
			String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        return AdminEventMulticaster.multicastEvent(event);
    
voidsetChannelAborting(int conflictedPort)
Set the channel to failed state.

conflictedPort
Port that causing conflict. This could be 0 if the reason for failure is not port-conflict.

        this.conflictedPort = conflictedPort;
        this.instanceStatus = Status.kInstanceFailedCode;
    
voidsetChannelReady()
Set channel to ready (running) state.

        this.instanceStatus = Status.kInstanceRunningCode;
    
voidsetChannelStarting()
Set channel to starting state.

        this.instanceStatus = Status.kInstanceStartingCode;
    
voidsetChannelStopping()
Set channel to stopping state.

        this.instanceStatus = Status.kInstanceStoppingCode;
    
voidsetLocalAddress(java.net.InetAddress address)
Set the address that clients will be checked against. This is set at startup.

        localAddress = address.getHostAddress();
    
public voidsetRestartNeeded(byte[] key, boolean needRestart)
Set restart needed status on server instance.

param
key shared secret
param
needRestart true if the instance should be restarted to use changes in persistent configuration.

        if (!checkAccess()) {
			String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
			String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }

        try {
            // persists the state to a file
            RRStateFactory.saveState(needRestart);
        } catch (IOException ioe) {
			String msg = localStrings.getString(
                "admin.server.core.channel.unable_saving_state_file");
            throw new RuntimeException(msg, ioe);
        }

        restartNeeded = needRestart;
    
voidsetSharedInfo(byte[] seed)
Set shared secret that clients must specify in every remote call. This is set at startup.

        myKey = seed;
    
public voidtriggerServerExit(byte[] key)
Client will exit after calling this method. Notify the lock held in ASSocketService.

param
key shared secret

        if (!checkAccess()) {
                        String msg = localStrings.getString( "admin.server.core.channel.unauthorized_access" );
            throw new SecurityException( msg );
        }
        if (!keyMatches(key)) {
                        String msg = localStrings.getString( "admin.server.core.channel.invalid_key" );
            throw new IllegalArgumentException( msg );
        }
        ASSocketService.triggerServerExit();