uk.ac.soton.ecs.grimoires.server.store
Class CopyOfReadWriteLock

java.lang.Object
  extended byuk.ac.soton.ecs.grimoires.server.store.CopyOfReadWriteLock

public class CopyOfReadWriteLock
extends Object

A lock that allows multiple read access or single write access to some data at any one time. Reads are prioritised over writes so all reads are processed first. Before performing a read operation on the data in question, the client code should call beforeRead() on the associated lock, then call afterRead () afterwards. Similarly, before performing a write operation on the data, the client code should call beforeWrite() on the associated lock, then call afterWrite () afterwards.

This code is adapted from that in "Concurrent Programming in Java" by Doug Lea, published by Addison Wesley.

Version:
$Id: CopyOfReadWriteLock.java,v 1.1 2005/11/16 13:38:21 wf Exp $ Created: 29 April 2004,16:14 Copyright 2003 Simon Miles, Luc Moreau, Juri Papay
Author:
Simon Miles

Constructor Summary
CopyOfReadWriteLock()
          Creates a new instance of ReadWriteLock
 
Method Summary
 void afterRead()
          Call after every read operation
 void afterWrite()
          Call after every write operation
protected  boolean allowReader()
          Multiple reads are allowed at the same time and reads are prioritised over writes.
protected  boolean allowWriter()
          A write can only take place when no other reads or writes are taking place
 void beforeRead()
          Call before every read operation
 void beforeWrite()
          Call before every write operation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CopyOfReadWriteLock

public CopyOfReadWriteLock()
Creates a new instance of ReadWriteLock

Method Detail

afterRead

public void afterRead()
Call after every read operation


afterWrite

public void afterWrite()
Call after every write operation


allowReader

protected boolean allowReader()
Multiple reads are allowed at the same time and reads are prioritised over writes. To change so that read and write are given the same priority, change the line to: return activeWriters == 0 && waitingWriters == 0;


allowWriter

protected boolean allowWriter()
A write can only take place when no other reads or writes are taking place


beforeRead

public void beforeRead()
Call before every read operation


beforeWrite

public void beforeWrite()
Call before every write operation