You can lock a resource or set of resources for exclusive
use by a particular user or shared use among more than one user.
A shared lock is an indication that something will happen with the
resource, but it does not prevent anyone else from taking actions
with that resource. A shared lock should be considered a signaling
mechanism. An exclusive lock means that the user who locked the
resource is going to change the resource, and the lock ensures that nobody
else can do so until the user no longer needs access to the resource
and has released the lock. If a repository administrator unlocks
a resource, all exclusive and shared locks on that resource will
automatically be removed. This type of action is meant for situations
in which a user is no longer available and has not unlocked the
resource.
When a resource is locked, a lock icon appears when you view
the Resources tab located in Workbench, as shown in the following
illustration.
You can programmatically control access to resources by using
the Repository service Java API or web service API.
Summary of stepsTo lock and unlock resources, follow these steps:
Include project files.
Create a Repository service client.
Specify the URI of the resource to be locked.
Lock the resource.
Retrieve the locks for the resource.
Unlock the resource
Include project filesInclude the necessary files in your development
project. If you are creating a client application using Java, include
the necessary JAR files. If you are using web services, include
the proxy files.
Create the service clientBefore you can programmatically read
a resource, you must establish a connection and provide credentials.
This is accomplished by creating a service client.
Specify the URI of the resource to be lockedCreate a string containing
the URI of the resource to be locked. The syntax includes forward
slashes, as in this example: "/path/resource".
Lock the resourceInvoke the Repository service method to lock
the resource, specifying the URI, the type of lock, and the locking
depth.
Retrieve the locks for the resourceInvoke the Repository service
method to retrieve the locks for the resource, specifying the URI.
Unlock the resourceInvoke the Repository service method to unlock
the resource, specifying the URI.
Lock resources using the Java APILock resources by using the Repository service API (Java):
Include project files
Include client JAR files
in your Java project’s class path.
Create the service client
Create a ResourceRepositoryClient object by
using its constructor and passing a ServiceClientFactory object
that contains connection properties.
Specify the URI of the resource to be locked
Specify
the URI of the resource to be locked. In this case, because the resource
named testResource is in the folder named testFolder,
its URI is "/testFolder/testResource". The URI
is stored as a java.lang.String object.
Lock the resource
Invoke the ResourceRepositoryClient object’s lockResource method
and pass in the following parameters:
The URI of the
resource.
The lock scope. In this example, because the resource will
be locked for exclusive use, the lock scope is specified as com.adobe.repository.infomodel.bean.Lock.SCOPE_EXCLUSIVE.
The lock depth. In this example, because the locking will
apply only to the particular resource and none of its members or
children, the lock depth is specified as Lock.DEPTH_ZERO.
Important : The overloaded version of the lockResource method
that requires four parameters throws an exception. Ensure to use
the lockResource method that requires three parameters
as shown in this walkthrough.
Retrieve the locks for the resource
Invoke the ResourceRepositoryClient object’s getLocks method
and pass the URI of the resource as a parameter. The method returns
a List of Lock objects through which you can iterate. In this example,
the lock owner, depth, and scope are printed for each object by
invoking each Lock object’s getOwnerUserId, getDepth, and getType methods,
respectively.
Unlock the resource
Invoke the ResourceRepositoryClient object’s unlockResource method
and pass the URI of the resource as a parameter. For more information,
see the LiveCycle API Reference.
Lock resources using the web service APILock resources by using the Repository service API (web service):
Include project files
Create the service client
Using the Microsoft .NET
client assembly, create a RepositoryServiceService object
by invoking its default constructor. Set its Credentials property using
a System.Net.NetworkCredential object containing
the user name and password.
Specify the URI of the resource to be locked
Specify
a string containing the URI of the resource to be locked. In this case,
because the resource named testResource is in the
folder testFolder, its URI is "/testFolder/testResource".
When using a language compliant with the Microsoft .NET Framework
(for example, C#), store the URI in a System.String object.
Lock the resource
Invoke the RepositoryServiceService object’s lockResource method
and pass in the following parameters:
The URI of the
resource.
The lock scope. In this example, because the resource will
be locked for exclusive use, the lock scope is specified as 11.
The lock depth. In this example, because the locking will
apply only to the particular resource and none of its members or
children, the lock depth is specified as 2.
An int value indicating the number of seconds
until the lock expires. In this example, the value of 1000 is
used.
Pass null for the last parameter.
Retrieve the locks for the resource
Invoke the RepositoryServiceService object’s getLocks method
and pass the URI of the resource as the first parameter and null for
the second parameter. The method returns an object array containing Lock objects
through which you can iterate. In this example, the lock owner,
depth, and scope are printed for each object by accessing each Lock object’s ownerUserId, depth,
and type fields, respectively.
Unlock the resource
Invoke the RepositoryServiceService object’s unlockResource method
and pass the URI of the resource as the first parameter and null for
the second parameter.
|
|
|