FileDocCategorySizeDatePackage
SessionLock.javaAPI DocGlassfish v2 API7970Fri May 04 22:32:20 BST 2007org.apache.catalina.session

SessionLock

public class SessionLock extends Object

Fields Summary
private static final String
BACKGROUND_LOCK
private static final String
FOREGROUND_LOCK
private String
_lockType
private int
_foregroundRefCount
Constructors Summary
public SessionLock()
Creates a new instance of SessionLock

    
           
      
    
Methods Summary
public voiddecrementForegroundRefCount()
decrement the foregroundRefCount

        _foregroundRefCount--;
    
public intgetForegroundRefCount()
get the foregroundRefCount

        return _foregroundRefCount;
    
public java.lang.StringgetLockType()
get the lock type

        return _lockType;
    
public voidincrementForegroundRefCount()
increment the foregroundRefCount

        _foregroundRefCount++;
    
public booleanisBackgroundLocked()
return whether lock is background locked

        if(_lockType == null) {
            return false;
        }
        return (_lockType.equals(BACKGROUND_LOCK));
    
public booleanisForegroundLocked()
return whether lock is foreground locked

        if(_lockType == null) {
            return false;
        }
        return (_lockType.equals(FOREGROUND_LOCK));
    
public booleanisLocked()
return whether lock is locked (either foreground or background)

        return (_lockType != null);
    
public synchronized booleanlockBackground()
if possible, the lock will be background locked if the lock is already foreground locked the method will return false and the lock remains foreground locked (i.e. lock failed) otherwise it will return true (lock succeeded)

        if(isForegroundLocked()) {
            return false;
        } 
        setLockType(BACKGROUND_LOCK);
        setForegroundRefCount(0);
        return true;
    
public synchronized booleanlockForeground()
if possible, the lock will be foreground locked if it was already foreground locked; it will remain so and the foregroundRefCount will be incremented if the lock is already background locked the method will return false and the lock remains background locked (i.e. lock failed) otherwise it will return true (lock succeeded)

        if(isBackgroundLocked()) {
            return false;
        }
        if(isForegroundLocked()) {
            incrementForegroundRefCount();
        } else {
            setForegroundRefCount(1);
        }
        setLockType(FOREGROUND_LOCK);
        return true;
    
public voidsetForegroundRefCount(int foregroundRefCount)
set the foregroundRefCount

param
foregroundRefCount

        _foregroundRefCount = foregroundRefCount;
    
public voidsetLockType(java.lang.String lockType)
set the lock type - lockType must be BACKGROUND_LOCK or FOREGROUND_LOCK

param
lockType the type of the lock

        _lockType = lockType;
    
public java.lang.StringtoString()
returns String representation of the state of the lock

        StringBuffer sb = new StringBuffer(50);
        sb.append("_lockType= " + _lockType);
        sb.append("\n" + "foregroundRefCount= " + _foregroundRefCount);
        return sb.toString();
    
public voidunlock()
unlock the lock if background locked the lock will become fully unlocked if foreground locked the lock will become fully unlocked if foregroundRefCount was 1; otherwise it will decrement the foregroundRefCount and the lock will remain foreground locked

        if(!isLocked())
            return;
        if(isBackgroundLocked()) {
            this.setLockType(null);
            this.setForegroundRefCount(0);
            return;
        }
        if(isForegroundLocked()) {
            decrementForegroundRefCount();
            if(_foregroundRefCount == 0) {
                this.setLockType(null);
            }
        }                        
    
public voidunlockBackground()
unlock the lock for the background locked case the lock will be unlocked

        //unlock if the lock is background locked
        //else do nothing
        if(!isLocked())
            return;
        if(isBackgroundLocked()) {
            this.setLockType(null);
            this.setForegroundRefCount(0);
            return;
        }                        
    
public voidunlockForeground()
unlock the lock for the foreground locked case the lock will be unlocked if foregroundRefCount was 1; otherwise it will decrement the foregroundRefCount and the lock will remain foreground locked

        //unlock if the lock is foreground locked
        //else do nothing        
        if(!isLocked())
            return;
        if(isForegroundLocked()) {
            decrementForegroundRefCount();
            if(_foregroundRefCount == 0) {
                this.setLockType(null);
            }
        }                        
    
public voidunlockForegroundCompletely()
unlock the lock this is a force unlock; foregroundRefCount is ignored

        //unlock completely if the lock is foreground locked
        //else do nothing        
        if(!isLocked())
            return;
        if(isForegroundLocked()) {
            this.setForegroundRefCount(0);
            this.setLockType(null);
        }