Codeunit 70623688 EOS004Semaphore

Codeunit 70623688 EOS004Semaphore

Methods

SemaphoreId

procedure SemaphoreId(): Guid

Returns the semaphore ID.

Parameters / Return Value

  • Returns Guid

Initialize

procedure Initialize(NewSemaphoreId: Guid; PerCompany: Boolean)

Initializes the semaphore with the specified ID and release intervals. This must always be called before you can use a semaphore.

Parameters / Return Value

  • NewSemaphoreId Guid

    The ID of the semaphore.

  • PerCompany Boolean

    Specifies whether the semaphore should be per company.


SetSuccessReleaseInterval

procedure SetSuccessReleaseInterval(NewIntervalInMs: Integer; NewJitterInMs: Integer)

Sets the amount of time (in milliseconds) after which the semaphore will release after a successful call.

Parameters / Return Value

  • NewIntervalInMs Integer

    The release time in milliseconds. The default value is 1h

  • NewJitterInMs Integer

    If specified, this will add a random jitter to the release time. This jitter will be applied positive and negative. For example: a jitter of 30min applied to 12:00 will result in a random time between 11:30 and 12:30. The default is zero.


SetSuccessReleaseInterval

procedure SetSuccessReleaseInterval(Release: DateTime; NewJitterInMs: Integer)

Sets the date/time when the semaphore will release after a successful call.

Parameters / Return Value

  • Release DateTime

    The release date/time.

  • NewJitterInMs Integer

    If specified, this will add a random jitter to the release time. This jitter will be applied positive and negative. For example: a jitter of 30min applied to 12:00 will result in a random time between 11:30 and 12:30. The default is zero.


SetFailureReleaseInterval

procedure SetFailureReleaseInterval(NewIntervalInMs: Integer; NewJitterInMs: Integer)

Sets the amount of time (in milliseconds) after which the semaphore will release after a failed call.

Parameters / Return Value

  • NewIntervalInMs Integer

    The release time in milliseconds. The default value is 5min.

  • NewJitterInMs Integer

    If specified, this will add a random jitter to the release time. This jitter will be applied positive and negative. For example: a jitter of 30min applied to 12:00 will result in a random time between 11:30 and 12:30. The default is zero.


SetFailureReleaseInterval

procedure SetFailureReleaseInterval(Release: DateTime; NewJitterInMs: Integer)

Sets the date/time when the semaphore will release after a failed call.

Parameters / Return Value

  • Release DateTime

    The release date/time.

  • NewJitterInMs Integer

    If specified, this will add a random jitter to the release time. This jitter will be applied positive and negative. For example: a jitter of 30min applied to 12:00 will result in a random time between 11:30 and 12:30. The default is zero.


SetLockTimeout

procedure SetLockTimeout(NewLockTimeout: Integer)

Sets the lock timeout (in milliseconds) for the semaphore. This is the maximum amount of time that a semaphore can remain locked. A semaphore that has timed out can be unlocked (as failure) by calling ReleaseIfTimedOut(). The default value is 5min.

Parameters / Return Value

  • NewLockTimeout Integer

IsReleased

procedure IsReleased(): Boolean

Returns whether the semaphore is released. A semaphore can be unlocked, but not yet released. Only released semaphores can be locked again.

Parameters / Return Value

  • Returns Boolean

    true or false.


IsUnlocked

procedure IsUnlocked(): Boolean

Returns whether the semaphore is unlocked. A semaphore can be unlocked, but not yet released. Only released semaphores can be locked again.

Parameters / Return Value

  • Returns Boolean

    true or false.


ReleaseIfTimedOut

procedure ReleaseIfTimedOut()

Checks if the semaphore has timed out and unlocks it (as failure) if it has. Call this to make sure that the semaphore is not locked indefinitely.


Lock

procedure Lock()

Locks the semaphore. This will fail if the semaphore could not be locked. This is usually called before the actual request is made to signal that the request is in progress and no other requests should be made. This method will issue a Commit()


TryLock

procedure TryLock(): Boolean

Tries to locks the semaphore. This is usually called before the actual request is made to signal that the request is in progress and no other requests should be made. This method will issue a Commit()

Parameters / Return Value

  • Returns Boolean

    true if the semaphore was successfully locked, false if it was already locked.


Unlock

procedure Unlock(Success: Boolean)

Unlocks the semaphore. This will fail if trying to unlock a semaphore that is not locked. This is usually called after the request has been completed (either successfully or not). The success parameter will be used to determine when the semaphore will actually release. This method will issue a Commit()

Parameters / Return Value

  • Success Boolean

    Whether the request was successful.


Unlock

procedure Unlock(Success: Boolean; ErrorMessage: Text)

Unlocks the semaphore. This will fail if trying to unlock a semaphore that is not locked. This is usually called after the request has been completed (either successfully or not). The success parameter will be used to determine when the semaphore will actually release. This method will issue a Commit()

Parameters / Return Value

  • Success Boolean

    Whether the request was successful.

  • ErrorMessage Text

    An optional error message that will be logged if success is false.


Events

OnAfterCalculateReleaseDateTime

local procedure OnAfterCalculateReleaseDateTime(Id: Guid; Success: Boolean; Interval: Integer; Jitter: Integer; JitterValue: Integer; var NewReleaseDateTime: DateTime)

Raised after the release date time for a semaphore has been calculated.

Parameters / Return Value

  • Id Guid

    The ID of the semaphore.

  • Success Boolean

    Indicates whether the release date time was calculated for a successful or failed request.

  • Interval Integer

    The configured interval (in milliseconds).

  • Jitter Integer

    The configured jitter (in milliseconds).

  • JitterValue Integer

    The calculated random jitter (in milliseconds).

  • NewReleaseDateTime DateTime

    The calculated release date time.



EOS Labs -