Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
哆啦叮当
Rocketmq
提交
48476ae5
R
Rocketmq
项目概览
哆啦叮当
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
48476ae5
编写于
4月 08, 2018
作者:
Z
Zhanhui Li
提交者:
GitHub
4月 08, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Standardize the startup class structure (#243)
上级
bf848c14
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
99 addition
and
69 deletion
+99
-69
broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java
...c/main/java/org/apache/rocketmq/broker/BrokerStartup.java
+6
-0
namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
...main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
+93
-69
未找到文件。
broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java
浏览文件 @
48476ae5
...
@@ -79,6 +79,12 @@ public class BrokerStartup {
...
@@ -79,6 +79,12 @@ public class BrokerStartup {
return
null
;
return
null
;
}
}
public
static
void
shutdown
(
final
BrokerController
controller
)
{
if
(
null
!=
controller
)
{
controller
.
shutdown
();
}
}
public
static
BrokerController
createBrokerController
(
String
[]
args
)
{
public
static
BrokerController
createBrokerController
(
String
[]
args
)
{
System
.
setProperty
(
RemotingCommand
.
REMOTING_VERSION_KEY
,
Integer
.
toString
(
MQVersion
.
CURRENT_VERSION
));
System
.
setProperty
(
RemotingCommand
.
REMOTING_VERSION_KEY
,
Integer
.
toString
(
MQVersion
.
CURRENT_VERSION
));
...
...
namesrv/src/main/java/org/apache/rocketmq/namesrv/NamesrvStartup.java
浏览文件 @
48476ae5
...
@@ -18,8 +18,10 @@ package org.apache.rocketmq.namesrv;
...
@@ -18,8 +18,10 @@ package org.apache.rocketmq.namesrv;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.classic.joran.JoranConfigurator
;
import
ch.qos.logback.classic.joran.JoranConfigurator
;
import
ch.qos.logback.core.joran.spi.JoranException
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Callable
;
...
@@ -40,99 +42,121 @@ import org.apache.rocketmq.srvutil.ShutdownHookThread;
...
@@ -40,99 +42,121 @@ import org.apache.rocketmq.srvutil.ShutdownHookThread;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
public
class
NamesrvStartup
{
public
class
NamesrvStartup
{
public
static
Properties
properties
=
null
;
public
static
CommandLine
commandLine
=
null
;
private
static
InternalLogger
log
;
private
static
Properties
properties
=
null
;
private
static
CommandLine
commandLine
=
null
;
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
main0
(
args
);
main0
(
args
);
}
}
public
static
NamesrvController
main0
(
String
[]
args
)
{
public
static
NamesrvController
main0
(
String
[]
args
)
{
System
.
setProperty
(
RemotingCommand
.
REMOTING_VERSION_KEY
,
Integer
.
toString
(
MQVersion
.
CURRENT_VERSION
));
try
{
try
{
//PackageConflictDetect.detectFastjson();
NamesrvController
controller
=
createNamesrvController
(
args
);
start
(
controller
);
String
tip
=
"The Name Server boot success. serializeType="
+
RemotingCommand
.
getSerializeTypeConfigInThisServer
();
log
.
info
(
tip
);
System
.
out
.
printf
(
"%s%n"
,
tip
);
return
controller
;
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
System
.
exit
(-
1
);
}
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
return
null
;
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqnamesrv"
,
args
,
buildCommandlineOptions
(
options
),
new
PosixParser
());
}
if
(
null
==
commandLine
)
{
System
.
exit
(-
1
);
return
null
;
}
final
NamesrvConfig
namesrvConfig
=
new
NamesrvConfig
();
public
static
NamesrvController
createNamesrvController
(
String
[]
args
)
throws
IOException
,
JoranException
{
final
NettyServerConfig
nettyServerConfig
=
new
NettyServerConfig
();
System
.
setProperty
(
RemotingCommand
.
REMOTING_VERSION_KEY
,
Integer
.
toString
(
MQVersion
.
CURRENT_VERSION
));
nettyServerConfig
.
setListenPort
(
9876
);
//PackageConflictDetect.detectFastjson();
if
(
commandLine
.
hasOption
(
'c'
))
{
String
file
=
commandLine
.
getOptionValue
(
'c'
);
if
(
file
!=
null
)
{
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
properties
=
new
Properties
();
properties
.
load
(
in
);
MixAll
.
properties2Object
(
properties
,
namesrvConfig
);
MixAll
.
properties2Object
(
properties
,
nettyServerConfig
);
namesrvConfig
.
setConfigStorePath
(
file
);
System
.
out
.
printf
(
"load config properties file OK, %s%n"
,
file
);
in
.
close
();
}
}
if
(
commandLine
.
hasOption
(
'p'
))
{
Options
options
=
ServerUtil
.
buildCommandlineOptions
(
new
Options
());
MixAll
.
printObjectProperties
(
null
,
namesrvConfig
);
commandLine
=
ServerUtil
.
parseCmdLine
(
"mqnamesrv"
,
args
,
buildCommandlineOptions
(
options
),
new
PosixParser
());
MixAll
.
printObjectProperties
(
null
,
nettyServerConfig
);
if
(
null
==
commandLine
)
{
System
.
exit
(
0
);
System
.
exit
(-
1
);
return
null
;
}
final
NamesrvConfig
namesrvConfig
=
new
NamesrvConfig
();
final
NettyServerConfig
nettyServerConfig
=
new
NettyServerConfig
();
nettyServerConfig
.
setListenPort
(
9876
);
if
(
commandLine
.
hasOption
(
'c'
))
{
String
file
=
commandLine
.
getOptionValue
(
'c'
);
if
(
file
!=
null
)
{
InputStream
in
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
properties
=
new
Properties
();
properties
.
load
(
in
);
MixAll
.
properties2Object
(
properties
,
namesrvConfig
);
MixAll
.
properties2Object
(
properties
,
nettyServerConfig
);
namesrvConfig
.
setConfigStorePath
(
file
);
System
.
out
.
printf
(
"load config properties file OK, %s%n"
,
file
);
in
.
close
();
}
}
}
if
(
commandLine
.
hasOption
(
'p'
))
{
MixAll
.
printObjectProperties
(
null
,
namesrvConfig
);
MixAll
.
printObjectProperties
(
null
,
nettyServerConfig
);
System
.
exit
(
0
);
}
MixAll
.
properties2Object
(
ServerUtil
.
commandLine2Properties
(
commandLine
),
namesrvConfig
);
MixAll
.
properties2Object
(
ServerUtil
.
commandLine2Properties
(
commandLine
),
namesrvConfig
);
if
(
null
==
namesrvConfig
.
getRocketmqHome
())
{
if
(
null
==
namesrvConfig
.
getRocketmqHome
())
{
System
.
out
.
printf
(
"Please set the %s variable in your environment to match the location of the RocketMQ installation%n"
,
MixAll
.
ROCKETMQ_HOME_ENV
);
System
.
out
.
printf
(
"Please set the %s variable in your environment to match the location of the RocketMQ installation%n"
,
MixAll
.
ROCKETMQ_HOME_ENV
);
System
.
exit
(-
2
);
System
.
exit
(-
2
);
}
}
LoggerContext
lc
=
(
LoggerContext
)
LoggerFactory
.
getILoggerFactory
();
LoggerContext
lc
=
(
LoggerContext
)
LoggerFactory
.
getILoggerFactory
();
JoranConfigurator
configurator
=
new
JoranConfigurator
();
JoranConfigurator
configurator
=
new
JoranConfigurator
();
configurator
.
setContext
(
lc
);
configurator
.
setContext
(
lc
);
lc
.
reset
();
lc
.
reset
();
configurator
.
doConfigure
(
namesrvConfig
.
getRocketmqHome
()
+
"/conf/logback_namesrv.xml"
);
configurator
.
doConfigure
(
namesrvConfig
.
getRocketmqHome
()
+
"/conf/logback_namesrv.xml"
);
final
InternalLogger
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
NAMESRV_LOGGER_NAME
);
MixAll
.
printObjectProperties
(
log
,
namesrvConfig
);
log
=
InternalLoggerFactory
.
getLogger
(
LoggerName
.
NAMESRV_LOGGER_NAME
);
MixAll
.
printObjectProperties
(
log
,
nettyServerConfig
);
final
NamesrvController
controller
=
new
NamesrvController
(
namesrvConfig
,
nettyServerConfig
);
MixAll
.
printObjectProperties
(
log
,
namesrvConfig
);
MixAll
.
printObjectProperties
(
log
,
nettyServerConfig
);
// remember all configs to prevent discard
final
NamesrvController
controller
=
new
NamesrvController
(
namesrvConfig
,
nettyServerConfig
);
controller
.
getConfiguration
().
registerConfig
(
properties
);
boolean
initResult
=
controller
.
initialize
();
// remember all configs to prevent discard
if
(!
initResult
)
{
controller
.
getConfiguration
().
registerConfig
(
properties
);
controller
.
shutdown
();
System
.
exit
(-
3
);
}
Runtime
.
getRuntime
().
addShutdownHook
(
new
ShutdownHookThread
(
log
,
new
Callable
<
Void
>()
{
return
controller
;
@Override
}
public
Void
call
()
throws
Exception
{
controller
.
shutdown
();
return
null
;
}
}));
controller
.
start
();
public
static
NamesrvController
start
(
final
NamesrvController
controller
)
throws
Exception
{
String
tip
=
"The Name Server boot success. serializeType="
+
RemotingCommand
.
getSerializeTypeConfigInThisServer
();
if
(
null
==
controller
)
{
log
.
info
(
tip
);
throw
new
IllegalArgumentException
(
"NamesrvController is null"
);
System
.
out
.
printf
(
"%s%n"
,
tip
);
}
return
controller
;
boolean
initResult
=
controller
.
initialize
()
;
}
catch
(
Throwable
e
)
{
if
(!
initResult
)
{
e
.
printStackTrace
();
controller
.
shutdown
();
System
.
exit
(-
1
);
System
.
exit
(-
3
);
}
}
return
null
;
Runtime
.
getRuntime
().
addShutdownHook
(
new
ShutdownHookThread
(
log
,
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
Exception
{
controller
.
shutdown
();
return
null
;
}
}));
controller
.
start
();
return
controller
;
}
public
static
void
shutdown
(
final
NamesrvController
controller
)
{
controller
.
shutdown
();
}
}
public
static
Options
buildCommandlineOptions
(
final
Options
options
)
{
public
static
Options
buildCommandlineOptions
(
final
Options
options
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录