Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
0e3d4158
R
redisson
项目概览
weixin_57962205
/
redisson
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redisson
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0e3d4158
编写于
3月 11, 2019
作者:
N
Nikita Koksharov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
RedissonMultiLock should implement RLock interface #1973
上级
4a630ac4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
113 addition
and
18 deletion
+113
-18
redisson/src/main/java/org/redisson/RedissonMultiLock.java
redisson/src/main/java/org/redisson/RedissonMultiLock.java
+86
-12
redisson/src/main/java/org/redisson/api/RLock.java
redisson/src/main/java/org/redisson/api/RLock.java
+9
-2
redisson/src/main/java/org/redisson/api/RLockAsync.java
redisson/src/main/java/org/redisson/api/RLockAsync.java
+2
-2
redisson/src/main/java/org/redisson/api/RLockReactive.java
redisson/src/main/java/org/redisson/api/RLockReactive.java
+8
-1
redisson/src/main/java/org/redisson/api/RLockRx.java
redisson/src/main/java/org/redisson/api/RLockRx.java
+8
-1
未找到文件。
redisson/src/main/java/org/redisson/RedissonMultiLock.java
浏览文件 @
0e3d4158
...
...
@@ -24,7 +24,6 @@ import java.util.concurrent.ThreadLocalRandom;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.Lock
;
import
org.redisson.api.RFuture
;
import
org.redisson.api.RLock
;
...
...
@@ -39,7 +38,7 @@ import org.redisson.misc.TransferListener;
* @author Nikita Koksharov
*
*/
public
class
RedissonMultiLock
implements
Lock
{
public
class
RedissonMultiLock
implements
R
Lock
{
class
LockState
{
...
...
@@ -74,7 +73,7 @@ public class RedissonMultiLock implements Lock {
lockWaitTime
=
calcLockWaitTime
(
remainTime
);
failedLocksLimit
=
failedLocksLimit
();
acquiredLocks
=
new
ArrayList
<
RLock
>(
locks
.
size
());
acquiredLocks
=
new
ArrayList
<>(
locks
.
size
());
}
void
tryAcquireLockAsync
(
ListIterator
<
RLock
>
iterator
,
RPromise
<
Boolean
>
result
)
{
...
...
@@ -147,7 +146,7 @@ public class RedissonMultiLock implements Lock {
if
(
leaseTime
!=
-
1
)
{
AtomicInteger
counter
=
new
AtomicInteger
(
acquiredLocks
.
size
());
for
(
RLock
rLock
:
acquiredLocks
)
{
RFuture
<
Boolean
>
future
=
rLock
.
expireAsync
(
unit
.
toMillis
(
leaseTime
),
TimeUnit
.
MILLISECONDS
);
RFuture
<
Boolean
>
future
=
((
RedissonLock
)
rLock
)
.
expireAsync
(
unit
.
toMillis
(
leaseTime
),
TimeUnit
.
MILLISECONDS
);
future
.
onComplete
((
res
,
e
)
->
{
if
(
e
!=
null
)
{
result
.
tryFailure
(
e
);
...
...
@@ -187,7 +186,7 @@ public class RedissonMultiLock implements Lock {
}
final
List
<
RLock
>
locks
=
new
ArrayList
<
RLock
>();
final
List
<
RLock
>
locks
=
new
ArrayList
<>();
/**
* Creates instance with multiple {@link RLock} objects.
...
...
@@ -211,6 +210,7 @@ public class RedissonMultiLock implements Lock {
}
}
@Override
public
void
lock
(
long
leaseTime
,
TimeUnit
unit
)
{
try
{
lockInterruptibly
(
leaseTime
,
unit
);
...
...
@@ -219,10 +219,12 @@ public class RedissonMultiLock implements Lock {
}
}
@Override
public
RFuture
<
Void
>
lockAsync
(
long
leaseTime
,
TimeUnit
unit
)
{
return
lockAsync
(
leaseTime
,
unit
,
Thread
.
currentThread
().
getId
());
}
@Override
public
RFuture
<
Void
>
lockAsync
(
long
leaseTime
,
TimeUnit
unit
,
long
threadId
)
{
long
baseWaitTime
=
locks
.
size
()
*
1500
;
long
waitTime
=
-
1
;
...
...
@@ -266,6 +268,7 @@ public class RedissonMultiLock implements Lock {
lockInterruptibly
(-
1
,
null
);
}
@Override
public
void
lockInterruptibly
(
long
leaseTime
,
TimeUnit
unit
)
throws
InterruptedException
{
long
baseWaitTime
=
locks
.
size
()
*
1500
;
long
waitTime
=
-
1
;
...
...
@@ -301,7 +304,7 @@ public class RedissonMultiLock implements Lock {
}
protected
void
unlockInner
(
Collection
<
RLock
>
locks
)
{
List
<
RFuture
<
Void
>>
futures
=
new
ArrayList
<
RFuture
<
Void
>
>(
locks
.
size
());
List
<
RFuture
<
Void
>>
futures
=
new
ArrayList
<>(
locks
.
size
());
for
(
RLock
lock
:
locks
)
{
futures
.
add
(
lock
.
unlockAsync
());
}
...
...
@@ -362,7 +365,7 @@ public class RedissonMultiLock implements Lock {
long
lockWaitTime
=
calcLockWaitTime
(
remainTime
);
int
failedLocksLimit
=
failedLocksLimit
();
List
<
RLock
>
acquiredLocks
=
new
ArrayList
<
RLock
>(
locks
.
size
());
List
<
RLock
>
acquiredLocks
=
new
ArrayList
<>(
locks
.
size
());
for
(
ListIterator
<
RLock
>
iterator
=
locks
.
listIterator
();
iterator
.
hasNext
();)
{
RLock
lock
=
iterator
.
next
();
boolean
lockAcquired
;
...
...
@@ -414,9 +417,9 @@ public class RedissonMultiLock implements Lock {
}
if
(
leaseTime
!=
-
1
)
{
List
<
RFuture
<
Boolean
>>
futures
=
new
ArrayList
<
RFuture
<
Boolean
>
>(
acquiredLocks
.
size
());
List
<
RFuture
<
Boolean
>>
futures
=
new
ArrayList
<>(
acquiredLocks
.
size
());
for
(
RLock
rLock
:
acquiredLocks
)
{
RFuture
<
Boolean
>
future
=
rLock
.
expireAsync
(
unit
.
toMillis
(
leaseTime
),
TimeUnit
.
MILLISECONDS
);
RFuture
<
Boolean
>
future
=
((
RedissonLock
)
rLock
)
.
expireAsync
(
unit
.
toMillis
(
leaseTime
),
TimeUnit
.
MILLISECONDS
);
futures
.
add
(
future
);
}
...
...
@@ -428,7 +431,7 @@ public class RedissonMultiLock implements Lock {
return
true
;
}
@Override
public
RFuture
<
Boolean
>
tryLockAsync
(
long
waitTime
,
long
leaseTime
,
TimeUnit
unit
,
long
threadId
)
{
RPromise
<
Boolean
>
result
=
new
RedissonPromise
<
Boolean
>();
LockState
state
=
new
LockState
(
waitTime
,
leaseTime
,
unit
,
threadId
);
...
...
@@ -436,6 +439,7 @@ public class RedissonMultiLock implements Lock {
return
result
;
}
@Override
public
RFuture
<
Boolean
>
tryLockAsync
(
long
waitTime
,
long
leaseTime
,
TimeUnit
unit
)
{
return
tryLockAsync
(
waitTime
,
leaseTime
,
unit
,
Thread
.
currentThread
().
getId
());
}
...
...
@@ -445,13 +449,14 @@ public class RedissonMultiLock implements Lock {
return
remainTime
;
}
@Override
public
RFuture
<
Void
>
unlockAsync
(
long
threadId
)
{
return
unlockInnerAsync
(
locks
,
threadId
);
}
@Override
public
void
unlock
()
{
List
<
RFuture
<
Void
>>
futures
=
new
ArrayList
<
RFuture
<
Void
>
>(
locks
.
size
());
List
<
RFuture
<
Void
>>
futures
=
new
ArrayList
<>(
locks
.
size
());
for
(
RLock
lock
:
locks
)
{
futures
.
add
(
lock
.
unlockAsync
());
...
...
@@ -462,10 +467,79 @@ public class RedissonMultiLock implements Lock {
}
}
@Override
public
Condition
newCondition
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
RFuture
<
Boolean
>
forceUnlockAsync
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
RFuture
<
Void
>
unlockAsync
()
{
return
unlockAsync
(
Thread
.
currentThread
().
getId
());
}
@Override
public
RFuture
<
Boolean
>
tryLockAsync
()
{
return
tryLockAsync
(
Thread
.
currentThread
().
getId
());
}
@Override
public
RFuture
<
Void
>
lockAsync
()
{
return
lockAsync
(
Thread
.
currentThread
().
getId
());
}
@Override
public
RFuture
<
Void
>
lockAsync
(
long
threadId
)
{
return
lockAsync
(-
1
,
null
,
threadId
);
}
@Override
public
RFuture
<
Boolean
>
tryLockAsync
(
long
threadId
)
{
return
tryLockAsync
(-
1
,
-
1
,
null
,
threadId
);
}
@Override
public
RFuture
<
Boolean
>
tryLockAsync
(
long
waitTime
,
TimeUnit
unit
)
{
return
tryLockAsync
(
waitTime
,
-
1
,
unit
);
}
@Override
public
RFuture
<
Integer
>
getHoldCountAsync
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
String
getName
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
forceUnlock
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isLocked
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isHeldByThread
(
long
threadId
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isHeldByCurrentThread
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
int
getHoldCount
()
{
throw
new
UnsupportedOperationException
();
}
}
redisson/src/main/java/org/redisson/api/RLock.java
浏览文件 @
0e3d4158
...
...
@@ -27,8 +27,15 @@ import java.util.concurrent.locks.Lock;
*
*/
public
interface
RLock
extends
Lock
,
R
Expirable
,
R
LockAsync
{
public
interface
RLock
extends
Lock
,
RLockAsync
{
/**
* Returns name of object
*
* @return name - name of object
*/
String
getName
();
/**
* Acquires the lock.
*
...
...
@@ -87,7 +94,7 @@ public interface RLock extends Lock, RExpirable, RLockAsync {
/**
* Unlocks lock independently of state
*
* @return <code>true</code> if unlocked otherwise <code>false</code>
* @return <code>true</code> if
lock existed and now
unlocked otherwise <code>false</code>
*/
boolean
forceUnlock
();
...
...
redisson/src/main/java/org/redisson/api/RLockAsync.java
浏览文件 @
0e3d4158
...
...
@@ -23,12 +23,12 @@ import java.util.concurrent.TimeUnit;
* @author Nikita Koksharov
*
*/
public
interface
RLockAsync
extends
RExpirableAsync
{
public
interface
RLockAsync
{
/**
* Unlocks the lock independently of state
*
* @return <code>true</code> if unlocked otherwise <code>false</code>
* @return <code>true</code> if
lock existed and now
unlocked otherwise <code>false</code>
*/
RFuture
<
Boolean
>
forceUnlockAsync
();
...
...
redisson/src/main/java/org/redisson/api/RLockReactive.java
浏览文件 @
0e3d4158
...
...
@@ -25,8 +25,15 @@ import reactor.core.publisher.Mono;
* @author Nikita Koksharov
*
*/
public
interface
RLockReactive
extends
RExpirableReactive
{
public
interface
RLockReactive
{
/**
* Returns name of object
*
* @return name - name of object
*/
String
getName
();
/**
* Unlocks the lock independently of state
*
...
...
redisson/src/main/java/org/redisson/api/RLockRx.java
浏览文件 @
0e3d4158
...
...
@@ -25,8 +25,15 @@ import io.reactivex.Flowable;
* @author Nikita Koksharov
*
*/
public
interface
RLockRx
extends
RExpirableRx
{
public
interface
RLockRx
{
/**
* Returns name of object
*
* @return name - name of object
*/
String
getName
();
/**
* Unlocks the lock independently of state
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录