Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_57962205
redisson
提交
635607af
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,发现更多精彩内容 >>
提交
635607af
编写于
9月 05, 2018
作者:
N
Nikita
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid to create connection per RRemoteService/RScheduledExecutorService worker #1623
上级
f65b5440
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
36 deletion
+71
-36
redisson/src/main/java/org/redisson/RedissonRemoteService.java
...son/src/main/java/org/redisson/RedissonRemoteService.java
+70
-35
redisson/src/test/java/org/redisson/executor/RedissonExecutorServiceTest.java
...va/org/redisson/executor/RedissonExecutorServiceTest.java
+1
-1
未找到文件。
redisson/src/main/java/org/redisson/RedissonRemoteService.java
浏览文件 @
635607af
...
...
@@ -17,12 +17,11 @@ package org.redisson;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicReference
;
import
org.redisson.api.RBlockingQueue
;
...
...
@@ -65,10 +64,33 @@ import io.netty.util.internal.PlatformDependent;
*/
public
class
RedissonRemoteService
extends
BaseRemoteService
implements
RRemoteService
{
public
static
class
Entry
{
RFuture
<
String
>
future
;
final
AtomicInteger
counter
;
public
Entry
(
int
workers
)
{
counter
=
new
AtomicInteger
(
workers
);
}
public
void
setFuture
(
RFuture
<
String
>
future
)
{
this
.
future
=
future
;
}
public
RFuture
<
String
>
getFuture
()
{
return
future
;
}
public
AtomicInteger
getCounter
()
{
return
counter
;
}
}
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RedissonRemoteService
.
class
);
private
final
Map
<
RemoteServiceKey
,
RemoteServiceMethod
>
beans
=
PlatformDependent
.
newConcurrentHashMap
();
private
final
Map
<
Class
<?>,
Set
<
RFuture
<
String
>>>
futures
=
PlatformDependent
.
newConcurrentHashMap
();
private
final
Map
<
Class
<?>,
Entry
>
remoteMap
=
PlatformDependent
.
newConcurrentHashMap
();
public
RedissonRemoteService
(
Codec
codec
,
RedissonClient
redisson
,
String
name
,
CommandExecutor
commandExecutor
,
String
executorId
,
ConcurrentMap
<
String
,
ResponseEntry
>
responses
)
{
super
(
codec
,
redisson
,
name
,
commandExecutor
,
executorId
,
responses
);
...
...
@@ -110,20 +132,19 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
beans
.
remove
(
key
);
}
Set
<
RFuture
<
String
>>
removedFutures
=
futures
.
remove
(
remoteInterface
);
if
(
removedFutures
==
null
)
{
return
;
}
for
(
RFuture
<
String
>
future
:
removedFutures
)
{
future
.
cancel
(
false
);
Entry
entry
=
remoteMap
.
remove
(
remoteInterface
);
if
(
entry
!=
null
&&
entry
.
getFuture
()
!=
null
)
{
entry
.
getFuture
().
cancel
(
false
);
}
}
@Override
public
int
getFreeWorkers
(
Class
<?>
remoteInterface
)
{
Set
<
RFuture
<
String
>>
futuresSet
=
futures
.
get
(
remoteInterface
);
return
futuresSet
.
size
();
Entry
entry
=
remoteMap
.
remove
(
remoteInterface
);
if
(
entry
==
null
)
{
return
0
;
}
return
entry
.
getCounter
().
get
();
}
@Override
...
...
@@ -144,32 +165,28 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
}
}
Set
<
RFuture
<
String
>>
values
=
Collections
.
newSetFromMap
(
PlatformDependent
.<
RFuture
<
String
>,
Boolean
>
newConcurrentHashMap
());
futures
.
put
(
remoteInterface
,
values
);
remoteMap
.
put
(
remoteInterface
,
new
Entry
(
workers
));
String
requestQueueName
=
getRequestQueueName
(
remoteInterface
);
RBlockingQueue
<
String
>
requestQueue
=
redisson
.
getBlockingQueue
(
requestQueueName
,
StringCodec
.
INSTANCE
);
for
(
int
i
=
0
;
i
<
workers
;
i
++)
{
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
private
<
T
>
void
subscribe
(
final
Class
<
T
>
remoteInterface
,
final
RBlockingQueue
<
String
>
requestQueue
,
final
ExecutorService
executor
)
{
Set
<
RFuture
<
String
>>
futuresSet
=
futures
.
get
(
remoteInterface
);
if
(
futuresSet
==
null
)
{
final
Entry
entry
=
remoteMap
.
get
(
remoteInterface
);
if
(
entry
==
null
)
{
return
;
}
final
RFuture
<
String
>
take
=
requestQueue
.
takeAsync
();
futuresSet
.
add
(
take
);
entry
.
setFuture
(
take
);
take
.
addListener
(
new
FutureListener
<
String
>()
{
@Override
public
void
operationComplete
(
Future
<
String
>
future
)
throws
Exception
{
Set
<
RFuture
<
String
>>
futuresSet
=
futures
.
get
(
remoteInterface
);
if
(
futuresSet
==
null
)
{
public
void
operationComplete
(
Future
<
String
>
future
)
throws
Exception
{
Entry
entry
=
remoteMap
.
get
(
remoteInterface
);
if
(
entry
==
null
)
{
return
;
}
futuresSet
.
remove
(
take
);
if
(!
future
.
isSuccess
())
{
if
(
future
.
cause
()
instanceof
RedissonShutdownException
)
{
...
...
@@ -184,6 +201,14 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
// do not subscribe now, see
// https://github.com/mrniko/redisson/issues/493
// subscribe(remoteInterface, requestQueue);
if
(
entry
.
getCounter
().
get
()
==
0
)
{
return
;
}
if
(
entry
.
getCounter
().
decrementAndGet
()
>
0
)
{
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
final
String
requestId
=
future
.
getNow
();
RMap
<
String
,
RemoteServiceRequest
>
tasks
=
redisson
.
getMap
(
requestQueue
.
getName
()
+
":tasks"
,
new
CompositeCodec
(
StringCodec
.
INSTANCE
,
codec
,
codec
));
...
...
@@ -197,16 +222,18 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
return
;
}
log
.
error
(
"Can't process the remote service request with id "
+
requestId
,
future
.
cause
());
// re-subscribe after a failed takeAsync
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
final
RemoteServiceRequest
request
=
future
.
getNow
();
if
(
request
==
null
)
{
log
.
debug
(
"Task can't be found for request: {}"
,
requestId
);
// re-subscribe after a skipped ackTimeout
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
...
...
@@ -215,8 +242,9 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
if
(
request
.
getOptions
().
isAckExpected
()
&&
elapsedTime
>
request
.
getOptions
().
getAckTimeoutInMillis
())
{
log
.
debug
(
"request: {} has been skipped due to ackTimeout. Elapsed time: {}ms"
,
request
.
getId
(),
elapsedTime
);
// re-subscribe after a skipped ackTimeout
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
...
...
@@ -247,13 +275,14 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
return
;
}
log
.
error
(
"Can't send ack for request: "
+
request
,
future
.
cause
());
// re-subscribe after a failed send (ack)
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
if
(!
future
.
getNow
())
{
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
...
...
@@ -269,13 +298,14 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
return
;
}
log
.
error
(
"Can't send ack for request: "
+
request
,
future
.
cause
());
// re-subscribe after a failed send (ack)
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
if
(!
future
.
getNow
())
{
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
re
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
return
;
}
...
...
@@ -374,7 +404,7 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
@Override
public
void
operationComplete
(
Future
<
Void
>
future
)
throws
Exception
{
// interface has been deregistered
if
(
futures
.
get
(
remoteInterface
)
==
null
)
{
if
(
!
remoteMap
.
containsKey
(
remoteInterface
)
)
{
return
;
}
...
...
@@ -386,12 +416,17 @@ public class RedissonRemoteService extends BaseRemoteService implements RRemoteS
future
.
cause
());
}
// re-subscribe anyways (fail or success) after the send
// (response)
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
resubscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
});
}
else
{
resubscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
}
private
<
T
>
void
resubscribe
(
Class
<
T
>
remoteInterface
,
RBlockingQueue
<
String
>
requestQueue
,
ExecutorService
executor
)
{
if
(
remoteMap
.
get
(
remoteInterface
).
getCounter
().
getAndIncrement
()
==
0
)
{
// re-subscribe anyways after the method invocation
subscribe
(
remoteInterface
,
requestQueue
,
executor
);
}
...
...
redisson/src/test/java/org/redisson/executor/RedissonExecutorServiceTest.java
浏览文件 @
635607af
...
...
@@ -299,7 +299,7 @@ public class RedissonExecutorServiceTest extends BaseTest {
e
.
execute
(
new
RunnableTask
());
}
e
.
shutdown
();
assertThat
(
e
.
awaitTermination
(
1
0
00
,
TimeUnit
.
MILLISECONDS
)).
isTrue
();
assertThat
(
e
.
awaitTermination
(
1
5
00
,
TimeUnit
.
MILLISECONDS
)).
isTrue
();
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录