JAL-3253 jalview.bin.Instance streamlining
[jalview.git] / src / jalview / bin / Instance.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin;
22
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.scoremodels.ScoreModels;
25 import jalview.api.StructureSelectionManagerProvider;
26 import jalview.ext.ensembl.EnsemblInfo;
27 import jalview.fts.service.pdb.PDBFTSRestClient;
28 import jalview.fts.service.uniprot.UniProtFTSRestClient;
29 import jalview.gui.Desktop;
30 import jalview.httpserver.HttpServer;
31 import jalview.io.gff.SequenceOntologyFactory;
32 import jalview.rest.RestHandler;
33 import jalview.schemes.ColourSchemes;
34 import jalview.structure.StructureImportSettings;
35 import jalview.structure.StructureSelectionManager;
36 import jalview.urls.IdOrgSettings;
37 import jalview.ws.jws1.Discoverer;
38 import jalview.ws.jws2.Jws2Discoverer;
39 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
40 import jalview.ws.rest.RestClient;
41 import jalview.ws.sifts.SiftsSettings;
42
43 import java.util.IdentityHashMap;
44
45 /**
46  * A class to hold singleton instances so that they are not shared among
47  * multiple JavaScript apps on a page. Fields are all formerly static class or
48  * object references are preserved in this singleton as "pseudo" static
49  * references that will be unique for each JavaScript applet or Java
50  * application.
51  * 
52  * There are three kinds of references:
53  * 
54  * Class references for classes with public getInstance() calls and a private
55  * constructor.
56  * 
57  * Class references for classes with private getInstance() calls and a private
58  * constructor.
59  * 
60  * Object references held here for a class as "pseudo" static field and
61  * referenced by Instance.getInstance().fieldName. These classes
62  * 
63  * @author hansonr
64  *
65  */
66 public class Instance
67 {
68
69   private Instance()
70   {
71     // singleton -- use getInstance();
72   }
73
74   private static Instance instance;
75
76   /**
77    * 
78    * Creates a static reference to this class, either as a static field (Java)
79    * or as an element in the applet's ThreadGroup object.
80    * 
81    * @return new Instance()
82    */
83   public static Instance getInstance()
84   {
85     Instance i;
86     @SuppressWarnings("unused")
87     ThreadGroup g = Thread.currentThread().getThreadGroup();
88     /**
89      * @j2sNative i = g._jalviewInstance;
90      */
91     {
92       i = instance;
93     }
94     if (i == null)
95     {
96       i = instance = new Instance();
97       /**
98        * @j2sNative g._jalviewInstance = i;
99        */
100     }
101     return i;
102   }
103
104   public Jalview jalview;
105
106   public Desktop desktop;
107
108
109
110   // The following are PUBLIC singletons; their class has a private constructor
111   // that is assigned by the class as part of a public static getInstance()
112   // call.
113
114   public ColourSchemes colourSchemes;
115
116   public Discoverer discoverer;
117
118   public HttpServer httpServer;
119
120   public RestClient restClient;
121
122   public RestHandler restHandler;
123
124   public ScoreModels scoreModels;
125
126   public jalview.ws.SequenceFetcher sequenceFetcher;
127
128   public SiftsSettings siftsSettings;
129
130
131   // The following are PRIVATE singletons; their class has only static public
132   // methods and a private constructor that is assigned by the class as part of
133   // a private static getInstance() call.
134
135   public AlignmentSorter alignmentSorter;
136
137   public Cache cache;
138
139   public EnsemblInfo ensemblInfo;
140
141   public IdOrgSettings idOrgSettings;
142
143   public Jws2Discoverer j2s2discoverer;
144
145   public Jws2InstanceFactory jws2InstanceFactory;
146
147   public PDBFTSRestClient pdbFTSRestClient;
148
149   public SequenceOntologyFactory sequenceOntologyFactory;
150
151   public StructureImportSettings structureImportSettings;
152
153   public UniProtFTSRestClient uniprotFTSRestClient;
154
155   // The following formerly static Object references are
156   // preserved in this singleton as "pseudo" static references
157   // that will be unique for each JavaScript applet or Java application.
158
159   /**
160    * StructureSelectionManager "static"
161    */
162   public IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
163
164 }