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