1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.anyflow.lannister.httphandler.api;
18
19 import com.hazelcast.core.IdGenerator;
20
21 import net.anyflow.lannister.cluster.ClusterDataFactory;
22 import net.anyflow.lannister.http.HttpRequestHandler;
23 import net.anyflow.lannister.session.Session;
24
25 @HttpRequestHandler.Handles(paths = { "api/clients" }, httpMethods = { "POST" })
26 public class Clients extends HttpRequestHandler {
27 @SuppressWarnings("unused")
28 private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(Clients.class);
29
30 @Override
31 public String service() {
32 IdGenerator idgen = ClusterDataFactory.INSTANCE.createIdGenerator("CLIENT_ID_GENERATOR");
33
34 String clientId = null;
35 while (clientId == null) {
36 clientId = String.format("laniClientId%011d", idgen.newId());
37
38 if (Session.NEXUS.get(clientId) != null) {
39 clientId = null;
40 }
41 }
42
43 return String.format("{\"id\":\"%s\"}", clientId);
44 }
45 }