com.buildforge.services.client.dbo
Class Semaphore

java.lang.Object
  extended by com.buildforge.services.client.dbo.Semaphore

public class Semaphore
extends java.lang.Object

Semaphores are used in a classic, concurrent sense in the Build Forge system. They are binary semaphores (maximum count of 1) that enforce mutual exclusion both within a single build across multiple threaded Steps and across multiple builds. Most interaction with Semaphores is done via the dot commands '.semget' and '.semput' within the bounds of a Project, but programmatic manipulation outside the runtime of a Project may be accomplished via this class.


Field Summary
static java.lang.Class<Semaphore> CLASS
           
 
Constructor Summary
Semaphore(APIClientConnection conn)
          Defines a new Semaphore
 
Method Summary
 boolean acquire()
          Attempts to exclusively acquire the desired Semaphore
 Semaphore create()
          Creates a new Semaphore in the database
 void delete()
          Removes this Semaphore from the database
static java.util.List<Semaphore> findAll(APIClientConnection conn)
          Retrieves all Semaphores in the database
static Semaphore findById(APIClientConnection conn, java.lang.String semaphoreName)
          Retrieves a single Semaphore by identifier (name)
 boolean getActive()
          Returns whether this Semaphore has already been acquired.
 int getBuildId()
          Returns the identifier of the Build that last acquired the semaphore
 java.lang.String getName()
          Returns the name of this Semaphore
 java.lang.String getRequestor()
          Returns the name of the project and step which owns or last owned the semaphore
 int getTimestamp()
          The timestamp of when the semaphore was last acquired, in seconds since epoch
 java.lang.String getUserId()
          Returns the identifier of the user that owns this Semaphore
 void release()
          Releases the exclusive lock on the supplied Semaphore
 void setActive(boolean active)
          Marks this Semaphore as acquired (true) or available (false)
 void setBuildId(int buildId)
          Sets the identifier for the Build that last acquired this Semaphore
 void setName(java.lang.String name)
          Sets the name of this Semaphore
 void setRequestor(java.lang.String requestor)
          Sets the name of the project and step which owns or last owned the semaphore
 void setTimestamp(int timestamp)
          Sets the timestamp of when the semaphore was last acquired, in seconds since epoch
 void setUserId(java.lang.String uid)
          Sets the identifier of the user that owns this Semaphore
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS

public static final java.lang.Class<Semaphore> CLASS
Constructor Detail

Semaphore

public Semaphore(APIClientConnection conn)
Defines a new Semaphore

Parameters:
conn -
Method Detail

findAll

public static java.util.List<Semaphore> findAll(APIClientConnection conn)
                                         throws java.io.IOException,
                                                ServiceException
Retrieves all Semaphores in the database

Parameters:
conn -
Returns:
Throws:
java.io.IOException
ServiceException

findById

public static Semaphore findById(APIClientConnection conn,
                                 java.lang.String semaphoreName)
                          throws java.io.IOException,
                                 ServiceException
Retrieves a single Semaphore by identifier (name)

Parameters:
conn -
semaphoreName -
Returns:
Throws:
java.io.IOException
ServiceException

create

public Semaphore create()
                 throws java.io.IOException,
                        ServiceException
Creates a new Semaphore in the database

Returns:
Throws:
java.io.IOException
ServiceException

delete

public void delete()
            throws java.io.IOException,
                   ServiceException
Removes this Semaphore from the database

Throws:
java.io.IOException
ServiceException

acquire

public boolean acquire()
                throws java.io.IOException,
                       ServiceException
Attempts to exclusively acquire the desired Semaphore

Returns:
true if the Semaphore was acquired, if not
Throws:
java.io.IOException
ServiceException

release

public void release()
             throws java.io.IOException,
                    ServiceException
Releases the exclusive lock on the supplied Semaphore

Throws:
java.io.IOException
ServiceException

getActive

public boolean getActive()
Returns whether this Semaphore has already been acquired.

Returns:
true if it has already been acquired, false if not

getBuildId

public int getBuildId()
Returns the identifier of the Build that last acquired the semaphore


getName

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


getRequestor

public java.lang.String getRequestor()
Returns the name of the project and step which owns or last owned the semaphore


getTimestamp

public int getTimestamp()
The timestamp of when the semaphore was last acquired, in seconds since epoch


getUserId

public java.lang.String getUserId()
Returns the identifier of the user that owns this Semaphore


setActive

public void setActive(boolean active)
Marks this Semaphore as acquired (true) or available (false)

Parameters:
active - true for acquired or false for available

setBuildId

public void setBuildId(int buildId)
Sets the identifier for the Build that last acquired this Semaphore

Parameters:
buildId -

setName

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

Parameters:
name -

setRequestor

public void setRequestor(java.lang.String requestor)
Sets the name of the project and step which owns or last owned the semaphore

Parameters:
requestor -

setTimestamp

public void setTimestamp(int timestamp)
Sets the timestamp of when the semaphore was last acquired, in seconds since epoch


setUserId

public void setUserId(java.lang.String uid)
Sets the identifier of the user that owns this Semaphore


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object