Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.yaftp.utils
Class TokenSemaphore  view TokenSemaphore download TokenSemaphore.java

java.lang.Object
  extended bycom.yaftp.utils.TokenSemaphore

public class TokenSemaphore
extends java.lang.Object

Copyright Jean-Yves MENGANT 1998,1999,2000 This class implements a MUTUAL EXCLUSIVE semaphore access using internal _tokenIsReady flag use this to synchronize concurent access to a single ressource Implementation is based on OReilly JAVA THREAD book examples


Field Summary
private  int _busyCount
           
private  boolean _debug
           
static boolean _DEBUG_MODE_
           
private  java.lang.String _name
           
private  java.lang.Thread _owner
           
static boolean _SET_BUSY_
           
static boolean _SET_FREE_
           
 
Constructor Summary
TokenSemaphore(java.lang.String name, boolean tokenState)
          basic constructor
TokenSemaphore(java.lang.String name, boolean tokenState, boolean debug)
          debug Constructor
 
Method Summary
private  void debug(java.lang.String dbg)
           
 void freeSemaphore()
          free synchronized ressource
private  java.lang.Thread getBusyCountOwner()
           
private  void initInstance(java.lang.String name, boolean tokenState)
           
 boolean isBusy()
          returns true if object is belonging to some thread
static void main(java.lang.String[] arg)
          Unit Testing semaphores
 void set_debug(boolean debug)
           
private  boolean tryGetToken()
          request token primitive
 void waitForOwning(java.lang.Thread owner)
          put a clean waiting process when a thread is waiting upon another thread getting ressource property
 void waitForSemaphore()
          wait for synchronized ressource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_busyCount

private transient int _busyCount

_owner

private transient java.lang.Thread _owner

_name

private transient java.lang.String _name

_debug

private transient boolean _debug

_SET_BUSY_

public static final boolean _SET_BUSY_
See Also:
Constant Field Values

_SET_FREE_

public static final boolean _SET_FREE_
See Also:
Constant Field Values

_DEBUG_MODE_

public static final boolean _DEBUG_MODE_
See Also:
Constant Field Values
Constructor Detail

TokenSemaphore

public TokenSemaphore(java.lang.String name,
                      boolean tokenState)
basic constructor


TokenSemaphore

public TokenSemaphore(java.lang.String name,
                      boolean tokenState,
                      boolean debug)
debug Constructor

Method Detail

set_debug

public void set_debug(boolean debug)

debug

private void debug(java.lang.String dbg)

initInstance

private void initInstance(java.lang.String name,
                          boolean tokenState)

getBusyCountOwner

private java.lang.Thread getBusyCountOwner()

tryGetToken

private boolean tryGetToken()
request token primitive


waitForSemaphore

public void waitForSemaphore()
wait for synchronized ressource


freeSemaphore

public void freeSemaphore()
free synchronized ressource


waitForOwning

public void waitForOwning(java.lang.Thread owner)
put a clean waiting process when a thread is waiting upon another thread getting ressource property


isBusy

public boolean isBusy()
returns true if object is belonging to some thread


main

public static void main(java.lang.String[] arg)
Unit Testing semaphores