org.sonar.api.utils
Interface Semaphores

All Superinterfaces:
ServerComponent, TaskComponent

public interface Semaphores
extends TaskComponent, ServerComponent

A semaphore shared among all the processes that can connect to the central database. It's ignored when enabling the dry run mode.

Since:
3.4

Nested Class Summary
static class Semaphores.Semaphore
           
 
Method Summary
 Semaphores.Semaphore acquire(String name)
          Try to acquire a semaphore.
 Semaphores.Semaphore acquire(String name, int maxAgeInSeconds, int updatePeriodInSeconds)
          Try to acquire a semaphore for a given duration.
 void release(String name)
          Release the lock on a semaphore by its name.
 

Method Detail

acquire

Semaphores.Semaphore acquire(String name,
                             int maxAgeInSeconds,
                             int updatePeriodInSeconds)
Try to acquire a semaphore for a given duration. The semaphore is acquired if it's unlocked or if the max locking duration is reached. When the lock is acquired there will be a periodic ping of the server to update the semaphore and avoid it to be considered as outdated.

Parameters:
name - the key of the semaphore
maxAgeInSeconds - the max duration in seconds the semaphore will be considered unlocked if it was not updated. The value zero forces the semaphore to be acquired, whatever its status.
updatePeriodInSeconds - the period in seconds the semaphore will be updated.
Returns:
the semaphore, whatever its status (locked or unlocked). Can't be null.

acquire

Semaphores.Semaphore acquire(String name)
Try to acquire a semaphore. The semaphore will be acquired only if there's no existing lock.

Parameters:
name - the key of the semaphore
Returns:
the semaphore, whatever its status (locked or unlocked). Can't be null.

release

void release(String name)
Release the lock on a semaphore by its name. Does nothing if the lock is already released.

Parameters:
name - the key of the semaphore


Copyright © 2009-2014 SonarSource. All Rights Reserved.