Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
Rocketmq
提交
6755cad7
R
Rocketmq
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
Rocketmq
与 Fork 源项目一致
Fork自
Apache RocketMQ / Rocketmq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6755cad7
编写于
5月 25, 2017
作者:
wu-sheng
提交者:
dongeforever
6月 06, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-39] avoid duplicated codes closes apache/incubator-rocketmq#34
上级
ac832830
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
39 deletion
+85
-39
filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java
.../java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java
+7
-17
namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
...main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
+9
-22
srvutil/src/main/java/org/apache/rocketmq/srvutil/ShutdownHookThread.java
.../java/org/apache/rocketmq/srvutil/ShutdownHookThread.java
+69
-0
未找到文件。
filtersrv/src/main/java/org/apache/rocketmq/filtersrv/FiltersrvStartup.java
浏览文件 @
6755cad7
...
...
@@ -22,7 +22,7 @@ import java.io.BufferedInputStream;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.Properties
;
import
java.util.concurrent.
atomic.AtomicInteger
;
import
java.util.concurrent.
Callable
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Options
;
...
...
@@ -34,6 +34,7 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import
org.apache.rocketmq.remoting.netty.NettySystemConfig
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
import
org.apache.rocketmq.srvutil.ShutdownHookThread
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -135,24 +136,13 @@ public class FiltersrvStartup {
System
.
exit
(-
3
);
}
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
new
Runnable
()
{
private
volatile
boolean
hasShutdown
=
false
;
private
AtomicInteger
shutdownTimes
=
new
AtomicInteger
(
0
);
Runtime
.
getRuntime
().
addShutdownHook
(
new
ShutdownHookThread
(
log
,
new
Callable
<
Void
>()
{
@Override
public
void
run
()
{
synchronized
(
this
)
{
log
.
info
(
"shutdown hook was invoked, "
+
this
.
shutdownTimes
.
incrementAndGet
());
if
(!
this
.
hasShutdown
)
{
this
.
hasShutdown
=
true
;
long
begineTime
=
System
.
currentTimeMillis
();
controller
.
shutdown
();
long
consumingTimeTotal
=
System
.
currentTimeMillis
()
-
begineTime
;
log
.
info
(
"shutdown hook over, consuming time total(ms): "
+
consumingTimeTotal
);
}
}
public
Void
call
()
throws
Exception
{
controller
.
shutdown
();
return
null
;
}
}
,
"ShutdownHook"
));
}));
return
controller
;
}
catch
(
Throwable
e
)
{
...
...
namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
浏览文件 @
6755cad7
...
...
@@ -22,7 +22,7 @@ import java.io.BufferedInputStream;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.Properties
;
import
java.util.concurrent.
atomic.AtomicInteger
;
import
java.util.concurrent.
Callable
;
import
org.apache.commons.cli.CommandLine
;
import
org.apache.commons.cli.Option
;
import
org.apache.commons.cli.Options
;
...
...
@@ -35,6 +35,7 @@ import org.apache.rocketmq.remoting.netty.NettyServerConfig;
import
org.apache.rocketmq.remoting.netty.NettySystemConfig
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.srvutil.ServerUtil
;
import
org.apache.rocketmq.srvutil.ShutdownHookThread
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -61,9 +62,7 @@ public class NamesrvStartup {
//PackageConflictDetect.detectFastjson();
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqnamesrv"
,
args
,
buildCommandlineOptions
(
options
),
new
PosixParser
());
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqnamesrv"
,
args
,
buildCommandlineOptions
(
options
),
new
PosixParser
());
if
(
null
==
commandLine
)
{
System
.
exit
(-
1
);
return
null
;
...
...
@@ -97,8 +96,7 @@ public class NamesrvStartup {
MixAll
.
properties2Object
(
ServerUtil
.
commandLine2Properties
(
commandLine
),
namesrvConfig
);
if
(
null
==
namesrvConfig
.
getRocketmqHome
())
{
System
.
out
.
printf
(
"Please set the "
+
MixAll
.
ROCKETMQ_HOME_ENV
+
" variable in your environment to match the location of the RocketMQ installation%n"
);
System
.
out
.
printf
(
"Please set the "
+
MixAll
.
ROCKETMQ_HOME_ENV
+
" variable in your environment to match the location of the RocketMQ installation%n"
);
System
.
exit
(-
2
);
}
...
...
@@ -123,24 +121,13 @@ public class NamesrvStartup {
System
.
exit
(-
3
);
}
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(
new
Runnable
()
{
private
volatile
boolean
hasShutdown
=
false
;
private
AtomicInteger
shutdownTimes
=
new
AtomicInteger
(
0
);
Runtime
.
getRuntime
().
addShutdownHook
(
new
ShutdownHookThread
(
log
,
new
Callable
<
Void
>()
{
@Override
public
void
run
()
{
synchronized
(
this
)
{
log
.
info
(
"shutdown hook was invoked, "
+
this
.
shutdownTimes
.
incrementAndGet
());
if
(!
this
.
hasShutdown
)
{
this
.
hasShutdown
=
true
;
long
begineTime
=
System
.
currentTimeMillis
();
controller
.
shutdown
();
long
consumingTimeTotal
=
System
.
currentTimeMillis
()
-
begineTime
;
log
.
info
(
"shutdown hook over, consuming time total(ms): "
+
consumingTimeTotal
);
}
}
public
Void
call
()
throws
Exception
{
controller
.
shutdown
();
return
null
;
}
}
,
"ShutdownHook"
));
}));
controller
.
start
();
...
...
srvutil/src/main/java/org/apache/rocketmq/srvutil/ShutdownHookThread.java
0 → 100644
浏览文件 @
6755cad7
/*
* 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.
*/
package
org.apache.rocketmq.srvutil
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.slf4j.Logger
;
/**
* {@link ShutdownHookThread} is the standard hook for filtersrv and namesrv modules.
* Through {@link Callable} interface, this hook can customization operations in anywhere.
*/
public
class
ShutdownHookThread
extends
Thread
{
private
volatile
boolean
hasShutdown
=
false
;
private
AtomicInteger
shutdownTimes
=
new
AtomicInteger
(
0
);
private
final
Logger
log
;
private
final
Callable
callback
;
/**
* Create the standard hook thread, with a call back, by using {@link Callable} interface.
*
* @param log The log instance is used in hook thread.
* @param callback The call back function.
*/
public
ShutdownHookThread
(
Logger
log
,
Callable
callback
)
{
super
(
"ShutdownHook"
);
this
.
log
=
log
;
this
.
callback
=
callback
;
}
/**
* Thread run method.
* Invoke when the jvm shutdown.
* 1. count the invocation times.
* 2. execute the {@link ShutdownHookThread#callback}, and time it.
*/
@Override
public
void
run
()
{
synchronized
(
this
)
{
log
.
info
(
"shutdown hook was invoked, "
+
this
.
shutdownTimes
.
incrementAndGet
()
+
" times."
);
if
(!
this
.
hasShutdown
)
{
this
.
hasShutdown
=
true
;
long
beginTime
=
System
.
currentTimeMillis
();
try
{
this
.
callback
.
call
();
}
catch
(
Exception
e
)
{
log
.
error
(
"shutdown hook callback invoked failure."
,
e
);
}
long
consumingTimeTotal
=
System
.
currentTimeMillis
()
-
beginTime
;
log
.
info
(
"shutdown hook done, consuming time total(ms): "
+
consumingTimeTotal
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录