diff --git a/README.md b/README.md index 329db5d3..5f85d5cd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ Bench4Q-Agent ============= -Agent node of Bench4Q +Agent Node of Bench4Q diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..8d41cc37 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + org.bench4q + bench4q-agent + jar + 0.0.1-SNAPSHOT + Bench4Q Agent + Bench4Q Agent + + TCSE, ISCAS + + + + junit + junit + 4.11 + test + + + org.eclipse.jetty + jetty-server + 8.1.11.v20130520 + + + org.eclipse.jetty + jetty-servlet + 8.1.11.v20130520 + + + org.springframework + spring-webmvc + 3.2.3.RELEASE + + + org.codehaus.jackson + jackson-mapper-asl + 1.9.12 + + + + bench4q-agent + + \ No newline at end of file diff --git a/src/main/java/org/bench4q/agent/AgentServer.java b/src/main/java/org/bench4q/agent/AgentServer.java new file mode 100644 index 00000000..f3a4023b --- /dev/null +++ b/src/main/java/org/bench4q/agent/AgentServer.java @@ -0,0 +1,67 @@ +package org.bench4q.agent; + +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.bio.SocketConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.springframework.web.servlet.DispatcherServlet; + +public class AgentServer { + private Server server; + private int port; + + private Server getServer() { + return server; + } + + private void setServer(Server server) { + this.server = server; + } + + private int getPort() { + return port; + } + + private void setPort(int port) { + this.port = port; + } + + public AgentServer(int port) { + this.setPort(port); + } + + public boolean start() { + try { + this.setServer(new Server()); + Connector connector = new SocketConnector(); + connector.setPort(this.getPort()); + this.getServer().addConnector(connector); + ServletContextHandler servletContextHandler = new ServletContextHandler(); + ServletHolder servletHolder = servletContextHandler.addServlet( + DispatcherServlet.class, "/"); + servletHolder.setInitParameter("contextConfigLocation", + "classpath*:/application-context.xml"); + this.getServer().setHandler(servletContextHandler); + this.getServer().start(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + public boolean stop() { + try { + if (this.getServer() != null) { + this.getServer().stop(); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + this.setServer(null); + } + } +} diff --git a/src/main/java/org/bench4q/agent/Main.java b/src/main/java/org/bench4q/agent/Main.java new file mode 100644 index 00000000..4ce89fc6 --- /dev/null +++ b/src/main/java/org/bench4q/agent/Main.java @@ -0,0 +1,9 @@ +package org.bench4q.agent; + +public class Main { + + public static void main(String[] args) { + AgentServer agentServer = new AgentServer(6565); + agentServer.start(); + } +} diff --git a/src/main/java/org/bench4q/agent/api/HomeController.java b/src/main/java/org/bench4q/agent/api/HomeController.java new file mode 100644 index 00000000..6203417b --- /dev/null +++ b/src/main/java/org/bench4q/agent/api/HomeController.java @@ -0,0 +1,16 @@ +package org.bench4q.agent.api; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("/") +public class HomeController { + @RequestMapping(value = { "/" }, method = RequestMethod.GET) + @ResponseBody + public String index() { + return "It works!"; + } +} \ No newline at end of file diff --git a/src/main/resources/application-context.xml b/src/main/resources/application-context.xml new file mode 100644 index 00000000..6c72d7ff --- /dev/null +++ b/src/main/resources/application-context.xml @@ -0,0 +1,10 @@ + + + + +