parent
1b2fb26140
commit
1df79bc940
@ -1,2 +1,3 @@
|
||||
/.settings/
|
||||
/.project
|
||||
/xxl-job.iml
|
||||
|
@ -1,6 +1,5 @@
|
||||
/target/
|
||||
/.settings/
|
||||
/target/
|
||||
/.classpath
|
||||
/.project
|
||||
/target/
|
||||
/xxl-job-admin.iml
|
@ -0,0 +1,55 @@
|
||||
package com.xxl.job.client.netcom.jetty;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Created by xuxueli on 2016/3/2 21:14.
|
||||
*/
|
||||
public class XxlJobJettyServer {
|
||||
private static final Logger logger = LoggerFactory.getLogger(XxlJobJettyServer.class);
|
||||
|
||||
private int port = 9999;
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Server server = new Server();
|
||||
server.setThreadPool(new ExecutorThreadPool(200, 200, 30000)); // 非阻塞
|
||||
|
||||
// connector
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
connector.setPort(port);
|
||||
connector.setMaxIdleTime(30000);
|
||||
server.setConnectors(new Connector[] { connector });
|
||||
|
||||
// handler
|
||||
HandlerCollection handlerc =new HandlerCollection();
|
||||
handlerc.setHandlers(new Handler[]{new XxlJobJettyServerHandler()});
|
||||
server.setHandler(handlerc);
|
||||
|
||||
try {
|
||||
server.start();
|
||||
logger.info(">>>>>>>>>>>> xxl-job jetty server start success at port:{}.", port);
|
||||
server.join(); // block until server ready
|
||||
logger.info(">>>>>>>>>>>> xxl-job jetty server join success at port:{}.", port);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.xxl.job.client.netcom.jetty;
|
||||
|
||||
import com.xxl.job.client.handler.HandlerRepository;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by xuxueli on 2016/3/2 21:23.
|
||||
*/
|
||||
public class XxlJobJettyServerHandler extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public void handle(String s, Request baseRequest, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
|
||||
|
||||
httpServletRequest.setCharacterEncoding("UTF-8");
|
||||
httpServletResponse.setCharacterEncoding("UTF-8");
|
||||
|
||||
Map<String, String> _param = new HashMap<String, String>();
|
||||
if (httpServletRequest.getParameterMap()!=null && httpServletRequest.getParameterMap().size()>0) {
|
||||
for (Object paramKey : httpServletRequest.getParameterMap().keySet()) {
|
||||
if (paramKey!=null) {
|
||||
String paramKeyStr = paramKey.toString();
|
||||
_param.put(paramKeyStr, httpServletRequest.getParameter(paramKeyStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String resp = HandlerRepository.pushHandleQueue(_param);
|
||||
|
||||
httpServletResponse.setContentType("text/html;charset=utf-8");
|
||||
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
|
||||
baseRequest.setHandled(true);
|
||||
httpServletResponse.getWriter().println(resp);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue