com.hermetica.util3d
Class CriticalSection

java.lang.Object
  |
  +--com.hermetica.util3d.CriticalSection

public class CriticalSection
extends java.lang.Object

This class acts as a sort of mutex that provides exclusive access to ``critical sections'' of code. You can acquire ( or attempt to acquire ) a lock via the ``lock'' method. Similarly, ``unlock'' will release the lock for other waiters to fight for!

This code is based on an original by Jason Osgood who similarly was inspired by Doug Lea's ``Concurrent Programming in Java''.

Version:
$Revision: 1.4 $
Author:
Alligator Descartes <descarte@arcana.co.uk>

Constructor Summary
CriticalSection()
          Create a new anonymous lock object
CriticalSection(boolean mode)
          Create a new anonymous lock object with the specified tracing mode
CriticalSection(java.lang.String name)
          Create a new lock object with the specified name
CriticalSection(java.lang.String name, boolean mode)
          Create a new named lock object with the specified name and tracing mode
CriticalSection(java.lang.String name, boolean mode, java.io.PrintStream oStream)
          Create a new named lock with the given tracing mode and the given output stream for the trace output
 
Method Summary
 java.lang.String getName()
          Returns the name of the lock
 boolean getTraceStatus()
          Returns the tracing level of the lock
 void lock()
          Begins a critical section of code
 void setName(java.lang.String name)
          Sets the name of the lock
 void setOutputStream(java.io.PrintStream oStream)
          Sets the output stream for the trace output
 void setTraceStatus(boolean mode)
          Sets the tracing level of this lock
 void unlock()
          Ends a critical section of code
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CriticalSection

public CriticalSection()
Create a new anonymous lock object

CriticalSection

public CriticalSection(java.lang.String name)
Create a new lock object with the specified name

CriticalSection

public CriticalSection(boolean mode)
Create a new anonymous lock object with the specified tracing mode

CriticalSection

public CriticalSection(java.lang.String name,
                       boolean mode)
Create a new named lock object with the specified name and tracing mode

CriticalSection

public CriticalSection(java.lang.String name,
                       boolean mode,
                       java.io.PrintStream oStream)
Create a new named lock with the given tracing mode and the given output stream for the trace output
Method Detail

setTraceStatus

public void setTraceStatus(boolean mode)
Sets the tracing level of this lock

getTraceStatus

public boolean getTraceStatus()
Returns the tracing level of the lock

setName

public void setName(java.lang.String name)
Sets the name of the lock

getName

public java.lang.String getName()
Returns the name of the lock

setOutputStream

public void setOutputStream(java.io.PrintStream oStream)
Sets the output stream for the trace output

lock

public void lock()
Begins a critical section of code

unlock

public void unlock()
Ends a critical section of code