[1] | 1 | package geniusweb.partiesserver;
|
---|
| 2 |
|
---|
| 3 | import java.io.IOException;
|
---|
| 4 |
|
---|
| 5 | import javax.servlet.ServletException;
|
---|
| 6 | import javax.servlet.http.HttpServlet;
|
---|
| 7 | import javax.servlet.http.HttpServletRequest;
|
---|
| 8 | import javax.servlet.http.HttpServletResponse;
|
---|
| 9 |
|
---|
| 10 | import com.fasterxml.jackson.databind.ObjectMapper;
|
---|
| 11 |
|
---|
| 12 | import geniusweb.partiesserver.repository.RunningPartiesRepo;
|
---|
| 13 | import geniusweb.serverobjects.ServerInfo;
|
---|
| 14 |
|
---|
| 15 | /**
|
---|
| 16 | * Servlet implementation to get general info from the server.
|
---|
| 17 | */
|
---|
| 18 | public class Info extends HttpServlet {
|
---|
| 19 |
|
---|
| 20 | private final static RunningPartiesRepo repo = RunningPartiesRepo
|
---|
| 21 | .instance();
|
---|
| 22 | private final static ObjectMapper jackson = new ObjectMapper();
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
|
---|
| 26 | * response). Returns
|
---|
| 27 | * <ul>
|
---|
| 28 | * <li>URL with websocket address to contact the now running agent.
|
---|
| 29 | * <li>SC_NOT_FOUND (404) if attempt is made to access non-running
|
---|
| 30 | * party.
|
---|
| 31 | * <li>SC_SERVICE_UNAVAILABLE (503) if there are no free slots to run
|
---|
| 32 | * the party.
|
---|
| 33 | * <li>SC_EXPECTATION_FAILED (417) if something else goes wrong during
|
---|
| 34 | * instantiating the party (then see logs for more details)
|
---|
| 35 | * </ul>
|
---|
| 36 | */
|
---|
| 37 | @Override
|
---|
| 38 | protected void doGet(HttpServletRequest request,
|
---|
| 39 | HttpServletResponse response) throws ServletException, IOException {
|
---|
| 40 | response.getWriter().append(jackson.writeValueAsString(
|
---|
| 41 | new ServerInfo(repo.availableSlots(), repo.maximumSlots())));
|
---|
| 42 | }
|
---|
| 43 | }
|
---|