LOCKRESOURCE()

From Lianjapedia
Revision as of 09:29, 26 April 2017 by Yvonne.milne (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Purpose

Function to lock a named resource

Syntax

LOCKRESOURCE(<cResource> [, <cMode>])

See Also

UNLOCKRESOURCE(), UNLOCKRESOURCEALL()

Description

The LOCKRESOURCE() function attempts to lock the named resource <cResource> in mode <cMode>.

Argument Description
<cResource> Character string specifying the name of the resource
<cMode> Character string specifying the mode: "shared" or "exclusive"

The LOCKRESOURCE() function is cluster aware and can safely be used across multiple running instances of either Lianja desktop Apps on a network or Lianja Cloud Server instances.

'Shared' locks provide the ability to have multiple readers whereas 'exclusive' locks only provide access to a named resource one process at a time. If the named resource is locked exclusive by another process then the requesting process will wait until the resource is available in a compatible lock mode.

The 'LianjaCloudServerRequestLoop' resource is a built-in resource used by the Lianja Cloud Server. When a request is made to the Lianja Cloud Server a 'shared' lock is placed on the 'LianjaCloudServerRequestLoop' resource and then released at the end of the request. An rsp script placing an 'exclusive' lock on 'LianjaCloudServerRequestLoop' can therefore temporarily block the processing of other Lianja Cloud Server requests, for example to carry out database upgrade operations. Once the required operations are complete, issuing UNLOCKRESOURCE(<cResource>) or UNLOCKRESOURCEALL() will release the lock.

The LOCKRESOURCE(), UNLOCKRESOURCE() and UNLOCKRESOURCEALL() functions can also be called from a JavaScript Server Page (.jssp) file using the Lianja.evaluate() method.

The 'resourcelocks' sub-directory of lianja must exist and be writable (default). If required, an alternative directory can be specified by creating and setting the DB_RESOURCELOCKSDIR environment variable.

Example

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>
<body>
<%
unlockResource("LianjaCloudServerRequestLoop")
lockResource("LianjaCloudServerRequestLoop", "exclusive")
 
// Once the exclusive lock has been granted carry out required operations
// ...
// Then release the lock to unblock other requests
unlockResource("LianjaCloudServerRequestLoop")
%>
</body>
</html>
 
// Custom named resource:
lockResource("myresource", "exclusive")
 
// Resources can be unlocked individually by name:
unlockResource("myresource")
 
// Or all previously locked resources can be unlocked:
unlockresourceall()