Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
15af500d
authored
Aug 16, 2018
by
许雪里
Committed by
GitHub
Aug 16, 2018
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #403 from jackyRao2/master
修正xxl-job.xml端口自动获取的描述和执行器在指定ip自动获取端口时的错误
parents
8c2f50e9
76b629ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
xxl-job-core/src/main/java/com/xxl/job/core/util/NetUtil.java
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml
xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
View file @
15af500d
...
...
@@ -129,7 +129,7 @@ public class XxlJobExecutor implements ApplicationContextAware {
private
NetComServerFactory
serverFactory
=
new
NetComServerFactory
();
private
void
initExecutorServer
(
int
port
,
String
ip
,
String
appName
,
String
accessToken
)
throws
Exception
{
// valid param
port
=
port
>
0
?
port:
NetUtil
.
findAvailablePort
(
9999
);
port
=
port
>
0
?
port:
NetUtil
.
findAvailablePort
(
9999
,
ip
);
// start server
NetComServerFactory
.
putService
(
ExecutorBiz
.
class
,
new
ExecutorBizImpl
());
// rpc-service, base on jetty
...
...
xxl-job-core/src/main/java/com/xxl/job/core/util/NetUtil.java
View file @
15af500d
...
...
@@ -2,8 +2,10 @@ package com.xxl.job.core.util;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.StringUtils
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
import
java.net.ServerSocket
;
/**
...
...
@@ -15,23 +17,24 @@ public class NetUtil {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
NetUtil
.
class
);
/**
* find avaliable port
* find avaliable port
by ip
*
* @param defaultPort
* @param ip
* @return
*/
public
static
int
findAvailablePort
(
int
defaultPort
)
{
public
static
int
findAvailablePort
(
int
defaultPort
,
String
ip
)
{
int
portTmp
=
defaultPort
;
while
(
portTmp
<
65535
)
{
if
(!
isPortUsed
(
portTmp
))
{
if
(!
isPortUsed
(
portTmp
,
ip
))
{
return
portTmp
;
}
else
{
portTmp
++;
}
}
portTmp
=
defaultPort
--
;
portTmp
=
--
defaultPort
;
while
(
portTmp
>
0
)
{
if
(!
isPortUsed
(
portTmp
))
{
if
(!
isPortUsed
(
portTmp
,
ip
))
{
return
portTmp
;
}
else
{
portTmp
--;
...
...
@@ -41,17 +44,33 @@ public class NetUtil {
}
/**
* find avaliable port
*
* @param defaultPort
* @return
*/
public
static
int
findAvailablePort
(
int
defaultPort
)
{
return
findAvailablePort
(
defaultPort
,
null
);
}
/**
* check port used
*
* @param port
* @param ip 为空则为 InetAddress.anyLocalAddress()
* @return
*/
public
static
boolean
isPortUsed
(
int
port
)
{
public
static
boolean
isPortUsed
(
int
port
,
String
ip
)
{
boolean
used
=
false
;
ServerSocket
serverSocket
=
null
;
try
{
serverSocket
=
new
ServerSocket
(
port
);
used
=
false
;
if
(
StringUtils
.
isEmpty
(
ip
)){
serverSocket
=
new
ServerSocket
(
port
);
}
else
{
serverSocket
=
new
ServerSocket
();
serverSocket
.
bind
(
new
InetSocketAddress
(
ip
,
port
));
}
}
catch
(
IOException
e
)
{
logger
.
debug
(
">>>>>>>>>>> xxl-job, port[{}] is in use."
,
port
);
used
=
true
;
...
...
xxl-job-executor-samples/xxl-job-executor-sample-spring/src/main/resources/applicationcontext-xxl-job.xml
View file @
15af500d
...
...
@@ -29,7 +29,7 @@
<property
name=
"appName"
value=
"${xxl.job.executor.appname}"
/>
<!-- 执行器IP[选填],为空则自动获取 -->
<property
name=
"ip"
value=
"${xxl.job.executor.ip}"
/>
<!-- 执行器端口号[选填],为
空
则自动获取 -->
<!-- 执行器端口号[选填],为
<0
则自动获取 -->
<property
name=
"port"
value=
"${xxl.job.executor.port}"
/>
<!-- 访问令牌[选填],非空则进行匹配校验 -->
<property
name=
"accessToken"
value=
"${xxl.job.accessToken}"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment