blob: 6f1f9ee4b57d5629c516b81c3f08ccbdf78dde0c [file] [log] [blame]
///////////////////////////////////////////////////////////////
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
///////////////////////////////////////////////////////////////
[[library-locking, Locking Library]]
= Locking =
[devstatus]
--------------
source=libraries/locking/dev-status.xml
--------------
The Locking Library is a simple way to mark method with Read or Write locks, and the details is handled by this
library.
This library is heavily used in EntityStore implementations.
include::../../build/docs/buildinfo/artifact.txt[]
The library creates a +java.util.concurrent.ReentrantReadWriteLock+ which is shared for all methods within the
composite. It then acquires the read or write lock in a concern that is applied to the methods of the composite, which
have the corresponding annotations.
== +@ReadLock+ ==
This annotation will apply the +ReadLockConcern+ to the method, and acquire the +lock.readLock()+ on entry and relase
it on exit of the method. See the +ReentrantReadWriteLock+ for details on how/when to use it and the exact semantics.
== +@WriteLock+ ==
This annotation will apply the +WriteLockConcern+ to the method, and acquire the +lock.writeLock()+ on entry and relase
it on exit of the method. See the +ReentrantReadWriteLock+ for details on how/when to use it and the exact semantics.
== +LockingAbstractComposite+ ==
This composite type is the easiest way to use this library. Simple extend you composite type interface with this
interface and start marking the methods with the above annotations. No other complex assembly is required.
[source,java]
----
public interface SomeService
extends ServiceComposite, LockingAbstractComposite
{
}
----
or apply it during assembly, in case that is the only choice (such as existing/external interfaces)
[snippet,java]
----
source=libraries/locking/src/test/java/org/qi4j/library/locking/DocumentationSupport.java
tag=assembly
----