Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
c86d7d1c
提交
c86d7d1c
authored
1月 21, 2017
作者:
xueli.xue
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
IP工具类优化,本地IP地址静态缓存;
上级
e229a824
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
100 行增加
和
23 行删除
+100
-23
README.md
README.md
+4
-3
XxlJobLogCallbackServer.java
.../xxl/job/admin/core/callback/XxlJobLogCallbackServer.java
+2
-3
XxlJobExecutor.java
.../java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java
+1
-1
IpUtil.java
xxl-job-core/src/main/java/com/xxl/job/core/util/IpUtil.java
+93
-16
没有找到文件。
README.md
浏览文件 @
c86d7d1c
...
@@ -700,6 +700,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
...
@@ -700,6 +700,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
-
4、Jetty升级版本至8.2.0.v20160908;
-
4、Jetty升级版本至8.2.0.v20160908;
-
5、已推送V1.5.0和V1.5.1至Maven中央仓库;
-
5、已推送V1.5.0和V1.5.1至Maven中央仓库;
#### 6.10 版本 V1.5.2 特性
-
1、IP工具类优化,IP静态缓存;
#### 规划中
#### 规划中
-
1、集群执行器选择规则自定义:单点=选择第一个,随机=随机选择一个;
-
1、集群执行器选择规则自定义:单点=选择第一个,随机=随机选择一个;
...
@@ -712,9 +714,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
...
@@ -712,9 +714,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
-
5、兼容oracle;
-
5、兼容oracle;
-
6、跨天日志write问题修复;
-
6、跨天日志write问题修复;
-
7、rolling日志;
-
7、rolling日志;
-
8、IP工具类优化,IP静态缓存;
-
8、执行器,server启动,注册逻辑调整;
-
9、执行器,server启动,注册逻辑调整;
-
9、通过listener或stop方法,容器销毁时销毁线程;Daemon方式有时不太理想;
-
10、通过listener或stop方法,容器销毁时销毁线程;Daemon方式有时不太理想;
## 七、其他
## 七、其他
...
...
xxl-job-admin/src/main/java/com/xxl/job/admin/core/callback/XxlJobLogCallbackServer.java
浏览文件 @
c86d7d1c
...
@@ -24,10 +24,9 @@ public class XxlJobLogCallbackServer {
...
@@ -24,10 +24,9 @@ public class XxlJobLogCallbackServer {
Server
server
=
null
;
Server
server
=
null
;
public
void
start
(
int
callBackPort
)
throws
Exception
{
public
void
start
(
int
callBackPort
)
throws
Exception
{
// init address
// init address
trigger_log_address
=
IpUtil
.
getIpPort
(
callBackPort
);
String
ip
=
IpUtil
.
getIp
();
trigger_log_address
=
ip
.
concat
(
":"
).
concat
(
String
.
valueOf
(
callBackPort
));
final
int
port
=
Integer
.
valueOf
(
callBackPort
);
final
int
port
=
Integer
.
valueOf
(
callBackPort
);
new
Thread
(
new
Runnable
()
{
new
Thread
(
new
Runnable
()
{
...
...
xxl-job-core/src/main/java/com/xxl/job/core/executor/jetty/XxlJobExecutor.java
浏览文件 @
c86d7d1c
...
@@ -94,7 +94,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
...
@@ -94,7 +94,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
public
void
run
()
{
public
void
run
()
{
while
(
true
)
{
while
(
true
)
{
try
{
try
{
String
address
=
IpUtil
.
getIp
().
concat
(
":"
).
concat
(
String
.
valueOf
(
port
)
);
String
address
=
IpUtil
.
getIp
Port
(
port
);
registHelper
.
registry
(
RegistHelper
.
RegistType
.
EXECUTOR
.
name
(),
appName
,
address
);
registHelper
.
registry
(
RegistHelper
.
RegistType
.
EXECUTOR
.
name
(),
appName
,
address
);
TimeUnit
.
SECONDS
.
sleep
(
RegistHelper
.
TIMEOUT
);
TimeUnit
.
SECONDS
.
sleep
(
RegistHelper
.
TIMEOUT
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
xxl-job-core/src/main/java/com/xxl/job/core/util/IpUtil.java
浏览文件 @
c86d7d1c
...
@@ -7,6 +7,7 @@ import java.net.InetAddress;
...
@@ -7,6 +7,7 @@ import java.net.InetAddress;
import
java.net.NetworkInterface
;
import
java.net.NetworkInterface
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.Enumeration
;
import
java.util.Enumeration
;
import
java.util.regex.Pattern
;
/**
/**
* get ip
* get ip
...
@@ -15,36 +16,112 @@ import java.util.Enumeration;
...
@@ -15,36 +16,112 @@ import java.util.Enumeration;
public
class
IpUtil
{
public
class
IpUtil
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
IpUtil
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
IpUtil
.
class
);
public
static
final
String
ANYHOST
=
"0.0.0.0"
;
public
static
final
String
LOCALHOST
=
"127.0.0.1"
;
private
static
final
Pattern
IP_PATTERN
=
Pattern
.
compile
(
"\\d{1,3}(\\.\\d{1,3}){3,5}$"
);
private
static
volatile
InetAddress
LOCAL_ADDRESS
=
null
;
/**
* valid address
* @param address
* @return
*/
private
static
boolean
isValidAddress
(
InetAddress
address
)
{
if
(
address
==
null
||
address
.
isLoopbackAddress
())
return
false
;
String
name
=
address
.
getHostAddress
();
return
(
name
!=
null
&&
!
ANYHOST
.
equals
(
name
)
&&
!
LOCALHOST
.
equals
(
name
)
&&
IP_PATTERN
.
matcher
(
name
).
matches
());
}
/**
/**
*
获取本机ip
*
get first valid addredd
* @return
ip
* @return
*/
*/
public
static
String
getIp
()
{
private
static
InetAddress
getFirstValidAddress
()
{
InetAddress
localAddress
=
null
;
try
{
localAddress
=
InetAddress
.
getLocalHost
();
if
(
isValidAddress
(
localAddress
))
{
return
localAddress
;
}
}
catch
(
Throwable
e
)
{
logger
.
warn
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
try
{
try
{
Enumeration
<
NetworkInterface
>
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
Enumeration
<
NetworkInterface
>
interfaces
=
NetworkInterface
.
getNetworkInterfaces
();
InetAddress
address
=
null
;
if
(
interfaces
!=
null
)
{
while
(
interfaces
.
hasMoreElements
())
{
while
(
interfaces
.
hasMoreElements
())
{
NetworkInterface
ni
=
interfaces
.
nextElement
();
try
{
Enumeration
<
InetAddress
>
addresses
=
ni
.
getInetAddresses
();
NetworkInterface
network
=
interfaces
.
nextElement
();
while
(
addresses
.
hasMoreElements
())
{
Enumeration
<
InetAddress
>
addresses
=
network
.
getInetAddresses
();
address
=
addresses
.
nextElement
();
if
(
addresses
!=
null
)
{
if
(!
address
.
isLoopbackAddress
()
&&
address
.
getHostAddress
().
indexOf
(
":"
)
==
-
1
)
{
while
(
addresses
.
hasMoreElements
())
{
return
address
.
getHostAddress
();
try
{
InetAddress
address
=
addresses
.
nextElement
();
if
(
isValidAddress
(
address
))
{
return
address
;
}
}
catch
(
Throwable
e
)
{
logger
.
warn
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
}
}
}
catch
(
Throwable
e
)
{
logger
.
warn
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
}
}
}
}
}
logger
.
info
(
"xxl job getHostAddress fail"
);
}
catch
(
Throwable
e
)
{
logger
.
warn
(
"Failed to retriving ip address, "
+
e
.
getMessage
(),
e
);
}
logger
.
error
(
"Could not get local host ip address, will use 127.0.0.1 instead."
);
return
localAddress
;
}
/**
* get address
* @return
*/
private
static
InetAddress
getAddress
()
{
if
(
LOCAL_ADDRESS
!=
null
)
return
LOCAL_ADDRESS
;
InetAddress
localAddress
=
getFirstValidAddress
();
LOCAL_ADDRESS
=
localAddress
;
return
localAddress
;
}
/**
* get ip
* @return
*/
public
static
String
getIp
(){
InetAddress
address
=
getAddress
();
if
(
address
==
null
)
{
return
null
;
return
null
;
}
catch
(
Throwable
t
)
{
}
logger
.
error
(
"xxl job getHostAddress error, {}"
,
t
);
return
address
.
getHostAddress
();
}
/**
* get ip:port
* @param port
* @return
*/
public
static
String
getIpPort
(
int
port
){
String
ip
=
getIp
();
if
(
ip
==
null
)
{
return
null
;
return
null
;
}
}
return
ip
.
concat
(
":"
).
concat
(
String
.
valueOf
(
port
));
}
}
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
System
.
out
.
println
(
InetAddress
.
getLocalHost
().
getCanonicalHostName
());
System
.
out
.
println
(
InetAddress
.
getLocalHost
().
getHostName
());
System
.
out
.
println
(
getIp
());
System
.
out
.
println
(
getIp
());
System
.
out
.
println
(
getIpPort
(
8080
));
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论