autohit.common
Class ProcessMonitor

java.lang.Object
  extended byautohit.common.ProcessMonitor

public class ProcessMonitor
extends java.lang.Object

Process monitors. There are three seperate monitors: 1- Locks: spinlocks on a shared lock monitor. Includes the redlight, greenlight function. 2- Signals: A cummulative signal, much like a semaphore. 3- Rendezous: Between two threads. Each of the three monitors do not effect each other.

Version:
1.0 Version History EPG - Rewrite - 16May03
Author:
Erich P. Gatejen

Constructor Summary
ProcessMonitor()
          Default constructor.
 
Method Summary
 boolean free()
          Cancel all locks.
 void green()
          Turn on the green light.
 boolean lock()
          Lock monitor.
 void red()
          Turn on the green light.
 void rendezous()
          Rendevous between two threads-- not signal.
 void signal()
          Send a signal.
 void stoplight()
          Wait for the green light.
 boolean unlock()
          Knock the spinlock down one.
 void waitlock()
          Wait for a lock.
 void waitSignal()
          Wait for a signal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessMonitor

public ProcessMonitor()
Default constructor. It will create the monitor that is unlocked.

Method Detail

lock

public boolean lock()
Lock monitor. Try to lock it. If it already locked by another thread, it will return false. If it is locked by the current thread, the lockcount will be incremented, and it will return true. If it is not locked, it will be locked and owned by the current thread.

Returns:
true if it locks, false it is already locked by another thread.

unlock

public boolean unlock()
Knock the spinlock down one. If it hits zero, the lock is removed. If the lock is owned by another thread, it will return false, otherwise it will return true--even if the spinlock hasn't hit zero.

Returns:
true for success, false for owned by another thread.

free

public boolean free()
Cancel all locks. Returns false if the lock is owned by another thread.

Returns:
true for success, otherwise false

waitlock

public void waitlock()
Wait for a lock.

Returns:
true for success, otherwise false TODO Look into the localized synchronization

stoplight

public void stoplight()
Wait for the green light.


green

public void green()
Turn on the green light.


red

public void red()
Turn on the green light.


waitSignal

public void waitSignal()
                throws java.lang.InterruptedException
Wait for a signal. It's pretty mch a semaphore.

Throws:
java.lang.InterruptedException

signal

public void signal()
Send a signal. They are cummulative and independent of the other monitors.


rendezous

public void rendezous()
Rendevous between two threads-- not signal. The first in the door will wait for the second. You should only use this for synchronization between two threads--NO MORE THAN TWO!



Test.