de.esprit.netsuite.server.lock

## Class ResourceLock

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.common.util.TransferableObject
    - - de.esprit.netsuite.server.lock.ResourceLock

- All Implemented Interfaces:
    Renderable, DeepCloneable, Dumpable, java.io.Serializable, java.lang.Cloneable

      public class ResourceLock
      extends TransferableObject
      implements Renderable

  A ResourceLock protects server resources against concurrent client access. There are two types of locks: SHARED and EXCLUSIVE. Many SHARED locks may exist on a resource whereas an EXCLUSIVE lock can only exist once. When a resource is locked exclusively by one client, any other client will receive a `ResourceLockedException` if he tries to access it exclusively too.

  Note that the lock has a dispose timer for protection against too long blocking of the resource. When the dispose timeout exceeds, the resource is released automatically by the server and the client will receive an appropriate warning. The client needs to retrigger the lock periodically as long as he wants to hold it.
  Retriggering the lock is automatically enabled when the lock is sent to the client.

  Author:
    Rainer Buesch
  See Also:
    `LockType`, Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceLock(ResourceLockManager rscList, ResourceLock lock)` This is a copy-constructor to create an EXCLUSIVE version of a SHARED lock
    `ResourceLock(ResourceLockManager rscList, SessionId sessId, LockType lockType, ResourceType rscType, java.lang.String rscName)`
    `ResourceLock(ResourceLockManager lockMgr, SessionId sessId, LockType lockType, ResourceType rscType, java.lang.String rscName, java.lang.String reason)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `dispose()`
    `boolean` | `equals(java.lang.Object obj)` Note that it is not sufficient to compare by lockId, instead we must compare four parameters.
    `long` | `getFetchTime()`
    `long` | `getLockDuration()`
    `int` | `getLockId()`
    `int` | `getLockTimeout()`
    `LockType` | `getLockType()`
    `java.lang.String` | `getReason()`
    `java.awt.Color` | `getRenderColor()`
    `javax.swing.Icon` | `getRenderIcon()`
    `java.lang.String` | `getRenderText()`
    `java.lang.String` | `getResourceName()`
    `ResourceType` | `getResourceType()`
    `SessionId` | `getSessionId()`
    `java.lang.String` | `getShortInfo()`
    `java.lang.String` | `getUserName()`
    `int` | `hashCode()`
    `boolean` | `isExclusive()`
    `boolean` | `isShared()`
    `boolean` | `isStale()` Note that a lock is made stale, when the client wants to access it but cannot find it in the ResourceLockList
    `boolean` | `isTimedOut()` A lock is timed out if it has not been retriggered within a certain time frame.
    `void` | `retrigger()`
    `void` | `setLockTimeout(int seconds)`
    `void` | `setLockType(LockType type)`
    `void` | `setReason(java.lang.String reason)`
    `void` | `setRetriggerEnabled(boolean isRetriggerEnabled)`
    `void` | `setStale()` Note that a lock is made stale, when the client wants to access it but cannot find it in the ResourceLockList
    `void` | `startDisposeTimer()`
    `DumpString` | `toDumpString(DumpString s)` Same content as toString, just in a different dump format
    `ToString` | `toString(ToString s)` This method allows subclasses to add values to the existing ToString of the superclass.

    - ### Methods inherited from class de.esprit.common.util.TransferableObject

      `clone, deepClone`

    - ### Methods inherited from class de.esprit.common.util.DumpableObject

      `configureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, createDumpHeader, toDumpString, toString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ResourceLock

          public ResourceLock(ResourceLockManager lockMgr,
                      SessionId sessId,
                      LockType lockType,
                      ResourceType rscType,
                      java.lang.String rscName,
                      java.lang.String reason)

      Parameters:
        `sessId` - the SessionId of the user who requires the lock
        `lockType` - the type of the lock, SHARED or EXCLUSIVE
        `rscType` - the type of a resource
        `rscName` - the unique name of a resource
        `reason` - optional string describing the reason why the lock was fetched

    - #### ResourceLock

          public ResourceLock(ResourceLockManager rscList,
                      SessionId sessId,
                      LockType lockType,
                      ResourceType rscType,
                      java.lang.String rscName)

    - #### ResourceLock

          public ResourceLock(ResourceLockManager rscList,
                      ResourceLock lock)

      This is a copy-constructor to create an EXCLUSIVE version of a SHARED lock

  - ### Method Detail

    - #### setRetriggerEnabled

          public void setRetriggerEnabled(boolean isRetriggerEnabled)

    - #### startDisposeTimer

          public void startDisposeTimer()

    - #### getReason

          public java.lang.String getReason()

    - #### setReason

          public void setReason(java.lang.String reason)

    - #### getShortInfo

          public java.lang.String getShortInfo()

    - #### getLockTimeout

          public int getLockTimeout()

    - #### setLockTimeout

          public void setLockTimeout(int seconds)

    - #### retrigger

          public void retrigger()

    - #### getResourceType

          public ResourceType getResourceType()

    - #### getResourceName

          public java.lang.String getResourceName()

    - #### getLockId

          public int getLockId()

    - #### getSessionId

          public SessionId getSessionId()

    - #### isTimedOut

          public boolean isTimedOut()

      A lock is timed out if it has not been retriggered within a certain time frame.

    - #### isStale

          public boolean isStale()

      Note that a lock is made stale, when the client wants to access it but cannot find it in the ResourceLockList

    - #### setStale

          public void setStale()

      Note that a lock is made stale, when the client wants to access it but cannot find it in the ResourceLockList

    - #### isShared

          public boolean isShared()

    - #### isExclusive

          public boolean isExclusive()

    - #### getLockType

          public LockType getLockType()

    - #### setLockType

          public void setLockType(LockType type)

    - #### getUserName

          public java.lang.String getUserName()

    - #### getFetchTime

          public long getFetchTime()

    - #### getLockDuration

          public long getLockDuration()

    - #### dispose

          public void dispose()

    - #### equals

          public boolean equals(java.lang.Object obj)

      Note that it is not sufficient to compare by lockId, instead we must compare four parameters. This prevents a user from fetching the same lock twice.
      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### getRenderIcon

          public javax.swing.Icon getRenderIcon()

      Specified by:
        `getRenderIcon` in interface `Renderable`

    - #### getRenderText

          public java.lang.String getRenderText()

      Specified by:
        `getRenderText` in interface `Renderable`

    - #### getRenderColor

          public java.awt.Color getRenderColor()

      Specified by:
        `getRenderColor` in interface `Renderable`

    - #### toString

          public ToString toString(ToString s)

      Description copied from interface: `Dumpable`
      This method allows subclasses to add values to the existing ToString of the superclass. Usually subclasses only need to override this method.
      Specified by:
        `toString` in interface `Dumpable`
      Overrides:
        `toString` in class `DumpableObject`

    - #### toDumpString

          public DumpString toDumpString(DumpString s)

      Same content as toString, just in a different dump format
      Specified by:
        `toDumpString` in interface `Dumpable`
      Overrides:
        `toDumpString` in class `DumpableObject`

Copyright © 2014 EsprIT-Systems. All Rights Reserved.