de.esprit.netsuite.server.lock

## Class ResourceLockManager

- java.lang.Object
- - de.esprit.common.util.DumpableObject
  - - de.esprit.appsuite.launch.AbstractApplicationObject<S>
    - - de.esprit.netsuite.server.AbstractServerObject<ServerContext>
      - - de.esprit.netsuite.server.lock.ResourceLockManager

- All Implemented Interfaces:
    ApplicationObject<ServerContext>, SimpleLogSupport, Dumpable, ServerObject<ServerContext>

      public class ResourceLockManager
      extends AbstractServerObject<ServerContext>

  This List manages the resource locks that are being hold by clients during editing a server resource.
  Author:
    Rainer Buesch

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceLockManager(ServerContext serverCtx)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ResourceLock` | `acquireAsExclusiveLock(ResourceLock myLock)` Acquires and returns a new EXCLUSIVE lock for the given SHARED lock.
    `void` | `checkIsDataSourceLockedByForeignSession(SessionId sessionId)` Checks whether there is a foreign DATA_SOURCE lock, no matter whether shared or exclusive.
    `void` | `checkIsLockedByForeignSession(SessionId sessionId, LockType lockType, ResourceType resourceType, java.lang.String resourceName)`
    `ResourceLock` | `findResourceLock(LockType lockType, ResourceType rscType, java.lang.String resourceName)` Finds a particular lock by specifying all its parameters
    `ResourceLock` | `findResourceLock(ResourceType rscType, java.lang.String rscName)` Scans for all lockTypes and returns the strongest type found
    `ResourceLock[]` | `findResourceLocks(LockType lockType, ResourceType rscType)` Finds all matching locks either by `LockType` or `ResourceType` or both.
    `ResourceLock[]` | `getLocks()`
    `int` | `getSize()`
    `ResourceLock` | `lockDataSource(SessionId sessionId, java.lang.String dataSourceName)` Fetches an exclusive lock for the given data-source.
    `ResourceLock` | `lockDataSourcePoolExclusive(SessionId sessionId)` Fetches an exclusive lock for the data-source pool.
    `ResourceLock` | `lockDataSourcePoolShared(SessionId sessionId)` Fetches a shared lock for the data-source pool.
    `ResourceLock` | `lockExclusive(SessionId sessionId, ResourceType rscType, java.lang.String rscName, java.lang.String reason)`
    `ResourceLock` | `lockShared(SessionId sessionId, ResourceType rscType, java.lang.String rscName, java.lang.String reason)`
    `void` | `releaseAllLocks()`
    `void` | `releaseAllLocksOf(SessionId sessionId)`
    `void` | `releaseLock(SessionId sessionId, ResourceLock myLock)` Releases the given lock.
    `void` | `retriggerLock(ResourceLock myLock)`
    `DumpString` | `toDumpString(DumpString s)` This method allows subclasses to add values to the existing DumpString of the superclass.
    `ToString` | `toString(ToString s)` This method allows subclasses to add values to the existing ToString of the superclass.

    - ### Methods inherited from class de.esprit.netsuite.server.AbstractServerObject

      `checkPermission, getServerConfig, getServerContext, getStatisticManager`

    - ### Methods inherited from class de.esprit.appsuite.launch.AbstractApplicationObject

      `getApplicationContext, getLogChannel, isLogDebug, isLogVerbose, logDebug, logDump, logError, logError, logFatal, logInfo, logVerbose, logWarning, setLogChannel`

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

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

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

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ResourceLockManager

          public ResourceLockManager(ServerContext serverCtx)

  - ### Method Detail

    - #### releaseLock

          public void releaseLock(SessionId sessionId,
                         ResourceLock myLock)
                           throws NotLockOwnerException

      Releases the given lock. The lock may only be released by the owner or any admin user.
      Throws:
        `NotLockOwnerException` - if the session is not the lock-owner

    - #### retriggerLock

          public void retriggerLock(ResourceLock myLock)
                             throws StaleResourceLockException

      Throws:
        `StaleResourceLockException`

    - #### lockShared

          public ResourceLock lockShared(SessionId sessionId,
                                ResourceType rscType,
                                java.lang.String rscName,
                                java.lang.String reason)
                                  throws ResourceLockedException

      Throws:
        `ResourceLockedException`

    - #### lockExclusive

          public ResourceLock lockExclusive(SessionId sessionId,
                                   ResourceType rscType,
                                   java.lang.String rscName,
                                   java.lang.String reason)
                                     throws ResourceLockedException,
                                            PermissionException

      Throws:
        `ResourceLockedException`
        `PermissionException`

    - #### checkIsLockedByForeignSession

          public void checkIsLockedByForeignSession(SessionId sessionId,
                                           LockType lockType,
                                           ResourceType resourceType,
                                           java.lang.String resourceName)
                                             throws ResourceLockedException

      Throws:
        `ResourceLockedException`

    - #### checkIsDataSourceLockedByForeignSession

          public void checkIsDataSourceLockedByForeignSession(SessionId sessionId)
                                                       throws ResourceLockedException

      Checks whether there is a foreign DATA_SOURCE lock, no matter whether shared or exclusive. sessionId may be null.
      Throws:
        `ResourceLockedException`

    - #### findResourceLock

          public ResourceLock findResourceLock(LockType lockType,
                                      ResourceType rscType,
                                      java.lang.String resourceName)

      Finds a particular lock by specifying all its parameters

    - #### findResourceLocks

          public ResourceLock[] findResourceLocks(LockType lockType,
                                         ResourceType rscType)

      Finds all matching locks either by `LockType` or `ResourceType` or both. Both args may be null in order to find ALL_PERMISSIONS locks.

    - #### findResourceLock

          public ResourceLock findResourceLock(ResourceType rscType,
                                      java.lang.String rscName)

      Scans for all lockTypes and returns the strongest type found

    - #### lockDataSource

          public ResourceLock lockDataSource(SessionId sessionId,
                                    java.lang.String dataSourceName)
                                      throws ResourceLockedException,
                                             PermissionException

      Fetches an exclusive lock for the given data-source.
      Throws:
        `PermissionException`
        `MissingMessageTypeRegistryException`
        `SessionNotFoundException`
        `ResourceLockedException`

    - #### lockDataSourcePoolExclusive

          public ResourceLock lockDataSourcePoolExclusive(SessionId sessionId)
                                                   throws ResourceLockedException,
                                                          PermissionException

      Fetches an exclusive lock for the data-source pool. This lock must be fetched before an attempt to select another data-source in the data-source pool
      Throws:
        `PermissionException`
        `MissingMessageTypeRegistryException`
        `SessionNotFoundException`
        `ResourceLockedException`

    - #### lockDataSourcePoolShared

          public ResourceLock lockDataSourcePoolShared(SessionId sessionId)
                                                throws ResourceLockedException

      Fetches a shared lock for the data-source pool. This lock must be fetched in order to prevent other users from changing the datasource while i am working
      Throws:
        `MissingMessageTypeRegistryException`
        `SessionNotFoundException`
        `ResourceLockedException`

    - #### acquireAsExclusiveLock

          public ResourceLock acquireAsExclusiveLock(ResourceLock myLock)
                                              throws StaleResourceLockException,
                                                     ResourceLockedException

      Acquires and returns a new EXCLUSIVE lock for the given SHARED lock. Note that if myLock is already exclusive, then no new lock is created and null is returned.
      Throws:
        `ResourceLockedException` - if another user already holds an EXCLUSIVE lock on the same resource
        `StaleResourceLockException` - if myLock is not found in the lock-list.

    - #### getLocks

          public ResourceLock[] getLocks()

    - #### releaseAllLocksOf

          public void releaseAllLocksOf(SessionId sessionId)

    - #### releaseAllLocks

          public void releaseAllLocks()

    - #### getSize

          public int getSize()

    - #### 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 `AbstractServerObject<ServerContext>`

    - #### toDumpString

          public DumpString toDumpString(DumpString s)

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

Copyright © 2014 EsprIT-Systems. All Rights Reserved.