JAL-3851 fix caching and tidy up old methods
[jalview.git] / src / jalview / rest / API.java
1 package jalview.rest;
2
3 import java.net.BindException;
4 import java.util.HashMap;
5 import java.util.Map;
6
7 import jalview.bin.Cache;
8
9 public class API extends RestHandler
10 {
11   private static final String MY_PATH = "api";
12
13   private static final String MY_NAME = "Jalview API";
14
15   private static Map<String, Status> statusMap = new HashMap<>();
16
17   private static Map<String, String> requestMap = new HashMap<>();
18
19   private static API instance = null;
20
21   public static API getInstance() throws BindException
22   {
23     synchronized (API.class)
24     {
25       if (instance == null)
26       {
27         instance = new API();
28       }
29     }
30     return instance;
31   }
32
33   private API() throws BindException
34   {
35     super();
36   }
37
38   private boolean init = false;
39
40   @Override
41   protected void init() throws BindException
42   {
43     if (init)
44       return;
45     super.init(MY_PATH);
46
47     // add endpoints here
48     addEndpoint(new FetchSequenceEndpoint(this));
49     addEndpoint(new OpenAlignmentEndpoint(this));
50     addEndpoint(new HighlightSequenceEndpoint(this));
51
52     Cache.info("REMOVEME setting path to " + MY_PATH);
53     Cache.info("REMOVEME endpoints keys:");
54     for (String key : getEndpoints().keySet())
55     {
56       Cache.info("REMOVEME keyname=" + key);
57     }
58     setPath(MY_PATH);
59     this.registerHandler();
60
61     init = true;
62   }
63
64   /*
65    * Shared methods below here
66    */
67
68   @Override
69   public String getPath()
70   {
71     return MY_PATH;
72   }
73
74   protected static Map<String, Status> getStatusMap()
75   {
76     return statusMap;
77   }
78
79   protected static Map<String, String> getRequestMap()
80   {
81     return requestMap;
82   }
83 }