It's all about the answers!

Ask a question

How do I lock a stream through the Java API ?


Giacomo Tonucci (2631) | asked May 18 '10, 11:02 a.m.
Hi everyone,
this is my first experience extending RTC. I have to code some basic operations in java.
For some reason I have to lock a stream, so that I can be sure nobody would change it until my work Item change state and deliver the the contents to another stream.

I'm trying to figure out how to use these classes I can't find examples for:

IWorkspaceManager wm = (IWorkspaceManager)teamRepository.getClientLibrary(IWorkspaceManager.class);

wm.applyLockOperations(lockOperations, monitor)

lockOperations must be a list of non-null IVersionableLockOperation elements; duplicates/equivalent elements tolerated.

How do I create such a list?

Is this the right way to lock a stream?

Thanks in advance.

Comments
Giacomo Tonucci commented May 18 '10, 11:23 a.m. | edited Oct 05 '17, 5:51 p.m.

Actually the javadoc for these classes doesn't work very well. It only tells the input parameters, but not their meanings.


Geoffrey Clemm commented May 18 '10, 6:08 p.m. | edited Oct 05 '17, 5:51 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Those locks are for locking individual files, not for locking the whole
stream. Could you expand a bit more on your use case? In general in
RTC, you shouldn't have to place temporary locks on streams.

Cheers,
Geoff

Accepted answer


permanent link
David Lafreniere (4.8k7) | answered Oct 05 '17, 6:15 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 06 '17, 9:20 a.m.

In RTC 6.0.2 we added a feature that lets you lock streams and components to prevent deliveries to the files in those streams or components. Stream and component locks work in a similar manner to file locks but apply to the entire stream or the entire component in a stream. When a stream or component is locked, any attempted deliveries by users who do not own the lock will fail with an appropriate error message. The user that holds the lock can still perform deliveries to the stream. A lock does not only prevent deliveries, it also prevents any operation that affects the files in the locked component or stream. For example, a component replace is also prevented.

These features were added in this Story (and child work items):
As a user, I want to lock a stream to prevent deliveries by other users (372642)

See:
-New & Noteworthy Mention: https://jazz.net/downloads/rational-team-concert/releases/6.0.2?p=newsDetails#stream-locking
-Stream/Component Locking Demo Video: https://www.youtube.com/watch?v=b8QwzwUF2ZY
-SCM Command Line Client 'set lock' command: https://www.ibm.com/support/knowledgecenter/SSCP65_6.0.4/com.ibm.team.scm.doc/topics/set_lock.html

To answer your question directly though, here is the API involved for locking a stream:

ITeamRepository repo = ....
IWorkspaceHandle streamHandle = ...
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceConnection sConn = wm.getWorkspaceConnection(
streamHandle, monitor); wm.applyLockOperations(Collections.singletonList(wm.lockOperationFactory().acquireStream(sConn)), monitor);






Michael Valenta selected this answer as the correct answer

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.