FileDocCategorySizeDatePackage
Unlocked.javaAPI DocGlassfish v2 API4700Fri May 04 22:33:32 BST 2007com.sun.enterprise.admin.common.domains.registry

Unlocked

public class Unlocked extends Object implements LockingStore

Fields Summary
private PersistentStore
storeImpl
private static final int
TIMEOUT
private static final int
ATTEMPTS
Constructors Summary
Unlocked(PersistentStore s)

	if (s == null) {
	  throw new NullPointerException("store is null");
	}
	
	storeImpl = s;
  
Methods Summary
private java.io.ObjectInputStreamgetIn()

	final FileInputStream fis = new FileInputStream(storeImpl.getStore());
	getReadLock(fis.getChannel());
	if (fis.available() > 0){
	  return new ObjectInputStream(fis);
	} else {
	  fis.close();
	  return null;
	}
  
private java.nio.channels.FileLockgetReadLock(java.nio.channels.FileChannel ch)

	return obtainLock(ch, true);
  
private java.nio.channels.FileLockgetWriteLock(java.nio.channels.FileChannel ch)
get a write lock on the given channel

	return obtainLock(ch, false);
  
public longlastModified()

 return 0L ;
public voidlock()

	final RandomAccessFile raf = new RandomAccessFile(storeImpl.getLock(),
													  "rws");
	getWriteLock(raf.getChannel());
	storeImpl.setState(new Locked(storeImpl, raf));
  
private java.nio.channels.FileLockobtainLock(java.nio.channels.FileChannel channel, boolean shared)

	FileLock lock = null;
	int attempts = 0;
	try{
/** Using 0x7fffffff in place of Long.MAX_VALUE. Bug # 4719967,4719605 **/
	  while ((lock = channel.tryLock(0L, 0x7fffffff, shared)) == null && attempts++ < ATTEMPTS){
		Thread.currentThread().sleep(TIMEOUT);
	  }
	}
	catch (InterruptedException e){
	  throw new TimeoutException();
	}
	
	if (lock == null) {
	  throw new TimeoutException();
	}
	return lock;
  
public synchronized java.lang.ObjectreadObject()

	ObjectInputStream in = null;
	Object o = null;
	try{
	  in = getIn();
	  o = (in != null ? in.readObject() : null) ;
	}
	catch (EOFException e){
	  o = null;					// this occurs if file is empty
	}
	finally {
	  if (in != null) {
		in.close();
	  }
	}
	return o;
  
public voidunlock()

public voidwriteObject(java.lang.Object o)

	throw new IllegalStateException("Unlocked state - writeObject() not allowed");