|
@@ -1,7 +1,7 @@
|
1
|
1
|
package com.xxl.job.core.rpc.netcom.jetty.server;
|
2
|
2
|
|
3
|
3
|
import com.xxl.job.core.registry.RegistHelper;
|
4
|
|
-import com.xxl.job.core.util.IpUtil;
|
|
4
|
+import com.xxl.job.core.thread.ExecutorRegistryThread;
|
5
|
5
|
import org.eclipse.jetty.server.Connector;
|
6
|
6
|
import org.eclipse.jetty.server.Handler;
|
7
|
7
|
import org.eclipse.jetty.server.Server;
|
|
@@ -11,8 +11,6 @@ import org.eclipse.jetty.util.thread.ExecutorThreadPool;
|
11
|
11
|
import org.slf4j.Logger;
|
12
|
12
|
import org.slf4j.LoggerFactory;
|
13
|
13
|
|
14
|
|
-import java.util.concurrent.TimeUnit;
|
15
|
|
-
|
16
|
14
|
/**
|
17
|
15
|
* rpc jetty server
|
18
|
16
|
* @author xuxueli 2015-11-19 22:29:03
|
|
@@ -21,9 +19,9 @@ public class JettyServer {
|
21
|
19
|
private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
|
22
|
20
|
|
23
|
21
|
private Server server;
|
24
|
|
-
|
|
22
|
+ private Thread thread;
|
25
|
23
|
public void start(final int port, final String ip, final String appName, final RegistHelper registHelper) throws Exception {
|
26
|
|
- Thread thread = new Thread(new Runnable() {
|
|
24
|
+ thread = new Thread(new Runnable() {
|
27
|
25
|
@Override
|
28
|
26
|
public void run() {
|
29
|
27
|
server = new Server();
|
|
@@ -43,7 +41,7 @@ public class JettyServer {
|
43
|
41
|
try {
|
44
|
42
|
server.start();
|
45
|
43
|
logger.info(">>>>>>>>>>>> xxl-job jetty server start success at port:{}.", port);
|
46
|
|
- executorRegistryBeat(port, ip, appName, registHelper);
|
|
44
|
+ ExecutorRegistryThread.getInstance().start(port, ip, appName, registHelper);
|
47
|
45
|
server.join(); // block until thread stopped
|
48
|
46
|
logger.info(">>>>>>>>>>> xxl-rpc server start success, netcon={}, port={}", JettyServer.class.getName(), port);
|
49
|
47
|
} catch (Exception e) {
|
|
@@ -65,43 +63,10 @@ public class JettyServer {
|
65
|
63
|
logger.error("", e);
|
66
|
64
|
}
|
67
|
65
|
}
|
68
|
|
- logger.info(">>>>>>>>>>> xxl-rpc server destroy success, netcon={}", JettyServer.class.getName());
|
69
|
|
- }
|
70
|
|
-
|
71
|
|
- /**
|
72
|
|
- * registry beat
|
73
|
|
- * @param port
|
74
|
|
- * @param ip
|
75
|
|
- * @param appName
|
76
|
|
- * @param registHelper
|
77
|
|
- */
|
78
|
|
- private void executorRegistryBeat(final int port, final String ip, final String appName, final RegistHelper registHelper){
|
79
|
|
- if (registHelper==null && appName==null || appName.trim().length()==0) {
|
80
|
|
- return;
|
|
66
|
+ if (thread.isAlive()) {
|
|
67
|
+ thread.interrupt();
|
81
|
68
|
}
|
82
|
|
- Thread registryThread = new Thread(new Runnable() {
|
83
|
|
- @Override
|
84
|
|
- public void run() {
|
85
|
|
- while (true) {
|
86
|
|
- try {
|
87
|
|
- // generate addredd = ip:port
|
88
|
|
- String address = null;
|
89
|
|
- if (ip != null && ip.trim().length()>0) {
|
90
|
|
- address = ip.trim().concat(":").concat(String.valueOf(port));
|
91
|
|
- } else {
|
92
|
|
- address = IpUtil.getIpPort(port);
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- registHelper.registry(RegistHelper.RegistType.EXECUTOR.name(), appName, address);
|
96
|
|
- TimeUnit.SECONDS.sleep(RegistHelper.TIMEOUT);
|
97
|
|
- } catch (Exception e) {
|
98
|
|
- e.printStackTrace();
|
99
|
|
- }
|
100
|
|
- }
|
101
|
|
- }
|
102
|
|
- });
|
103
|
|
- registryThread.setDaemon(true);
|
104
|
|
- registryThread.start();
|
|
69
|
+ logger.info(">>>>>>>>>>> xxl-rpc server destroy success, netcon={}", JettyServer.class.getName());
|
105
|
70
|
}
|
106
|
71
|
|
107
|
72
|
}
|