FileDocCategorySizeDatePackage
Customer.javaAPI DocExample1097Mon Nov 24 09:38:34 GMT 2003com.oreilly.patterns.chapter10

Customer

public class Customer extends Object implements Lockable

Fields Summary
private String
lockingUser
private Object
lockSynchronizer
Constructors Summary
Methods Summary
public booleanisLocked()

        return (lockingUser != null);
    
public voidlock(java.lang.String username)


          
        if (username == null) throw new LockingException("No User Provided.");
        synchronized(lockSynchronizer) {
            if(lockingUser == null)
                lockingUser = username;
            else if ((lockingUser != null) && (!lockingUser.equals(username)))
                throw new LockingException("Resource already locked");
        }
    
public voidunlock(java.lang.String username)

        if((lockingUser != null) && (lockingUser.equals(username)))
            lockingUser = null;
        else if (lockingUser != null)
            throw new LockingException("You do not hold the lock.");