Luky Library - 4.1.1 (20061117-1148)

luky.util
Class Semaphore

java.lang.Object
  extended by luky.util.Semaphore

public class Semaphore
extends Object

The Sempaphore Class is a class that holds all logic that's required for synchronizing access and execution of threads with counting sems

Version:
1.00
Author:
Chris Lukassen
 

Constructor Summary
Semaphore()
          constructor for a blocking semaphore (no timeout)
Semaphore(long timeout)
          timed constructor
Semaphore(String timeout)
          timed constructor
 
Method Summary
 int getSem()
          takes the current semaphore, in case the semaphore is not available the method will 'hang' until a semaphore is set or a timeout occurs
 long getTimeoutValue()
          returns the timeout value for this semaphore
 int setSem()
          sets the current semaphore, in case a different thread was 'hanging' on this thread will be released
 int setTimeoutValue(long timeout)
          sets the timeout value for this semaphore, blocked threads will not be affected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphore

public Semaphore()
constructor for a blocking semaphore (no timeout)


Semaphore

public Semaphore(long timeout)
timed constructor

Parameters:
timeout - long value specifying the timeout value in milli seconds

Semaphore

public Semaphore(String timeout)
timed constructor

Parameters:
timeout - string value specifying the timeout value in milli seconds
Method Detail

setTimeoutValue

public int setTimeoutValue(long timeout)
sets the timeout value for this semaphore, blocked threads will not be affected

Parameters:
timeout - long value specifying the timeout value in milli seconds
Returns:
Constants.NOK in case the timeout value is illegal or Constants.OK in case the value was accepted

getTimeoutValue

public long getTimeoutValue()
returns the timeout value for this semaphore

Returns:
the current timeout value

getSem

public int getSem()
takes the current semaphore, in case the semaphore is not available the method will 'hang' until a semaphore is set or a timeout occurs

Returns:
Constants.NOK in case an the wait method was interupted, Constants.OK in case the semaphore has been taken succesfully or Constants.TIMEOUT in case a timeout has occured

setSem

public int setSem()
sets the current semaphore, in case a different thread was 'hanging' on this thread will be released

Returns:
Constants.NOK in case the semaphore had already been set, Constants.OK if all went well

Luky Library - 4.1.1 (20061117-1148)