@@ -94,6 +94,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
9494
9595 protected HashMap <String , Adapters <? extends Adapter >> _adapterMap ;
9696 protected HashMap <String , ComponentInfo <Manager >> _managerMap ;
97+ protected HashMap <String , ComponentInfo <SystemIntegrityChecker >> _checkerMap ;
9798 protected LinkedHashMap <String , ComponentInfo <GenericDao <?, ? extends Serializable >>> _daoMap ;
9899 protected String _serverName ;
99100 protected Object _component ;
@@ -123,12 +124,13 @@ public String getName() {
123124 return getLocatorName ();
124125 }
125126
126- protected Ternary <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>, List < SystemIntegrityChecker >> parse2 (String filename ) {
127+ protected Pair <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>> parse2 (String filename ) {
127128 try {
128129 SAXParserFactory spfactory = SAXParserFactory .newInstance ();
129130 SAXParser saxParser = spfactory .newSAXParser ();
130131 _daoMap = new LinkedHashMap <String , ComponentInfo <GenericDao <?, ? extends Serializable >>>();
131132 _managerMap = new LinkedHashMap <String , ComponentInfo <Manager >>();
133+ _checkerMap = new HashMap <String , ComponentInfo <SystemIntegrityChecker >>();
132134 _adapterMap = new HashMap <String , Adapters <? extends Adapter >>();
133135 _factories = new HashMap <Class <?>, Class <?>>();
134136 File file = PropertiesUtil .findConfigFile (filename );
@@ -157,23 +159,21 @@ protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, Lis
157159 }
158160
159161 ComponentLibrary library = null ;
160- List <SystemIntegrityChecker > checkers = null ;
161162 if (handler .library != null ) {
162163 Class <?> clazz = Class .forName (handler .library );
163164 library = (ComponentLibrary )clazz .newInstance ();
164165 _daoMap .putAll (library .getDaos ());
165166 _managerMap .putAll (library .getManagers ());
166167 adapters .putAll (library .getAdapters ());
167168 _factories .putAll (library .getFactories ());
168- checkers = library .getSystemIntegrityCheckers ();
169169 }
170170
171171 _daoMap .putAll (handler .daos );
172172 _managerMap .putAll (handler .managers );
173+ _checkerMap .putAll (handler .checkers );
173174 adapters .putAll (handler .adapters );
174175
175- return new Ternary <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>, List <SystemIntegrityChecker >>(handler , adapters , checkers );
176-
176+ return new Pair <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>>(handler , adapters );
177177 } catch (ParserConfigurationException e ) {
178178 s_logger .error ("Unable to load " + _serverName + " due to errors while parsing " + filename , e );
179179 System .exit (1 );
@@ -194,7 +194,7 @@ protected Ternary<XmlHandler, HashMap<String, List<ComponentInfo<Adapter>>>, Lis
194194 }
195195
196196 protected void parse (String filename ) {
197- Ternary <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>, List < SystemIntegrityChecker >> result = parse2 (filename );
197+ Pair <XmlHandler , HashMap <String , List <ComponentInfo <Adapter >>>> result = parse2 (filename );
198198 if (result == null ) {
199199 s_logger .info ("Skipping configuration using " + filename );
200200 return ;
@@ -203,11 +203,7 @@ protected void parse(String filename) {
203203 XmlHandler handler = result .first ();
204204 HashMap <String , List <ComponentInfo <Adapter >>> adapters = result .second ();
205205 try {
206- if (result .third () != null ) {
207- for (SystemIntegrityChecker checker : result .third ()) {
208- checker .check ();
209- }
210- }
206+ runCheckers ();
211207 startDaos (); // daos should not be using managers and adapters.
212208 instantiateAdapters (adapters );
213209 instantiateManagers ();
@@ -227,6 +223,19 @@ protected void parse(String filename) {
227223 }
228224 }
229225
226+ protected void runCheckers () {
227+ Set <Map .Entry <String , ComponentInfo <SystemIntegrityChecker >>> entries = _checkerMap .entrySet ();
228+ for (Map .Entry <String , ComponentInfo <SystemIntegrityChecker >> entry : entries ) {
229+ ComponentInfo <SystemIntegrityChecker > info = entry .getValue ();
230+ try {
231+ info .instance = (SystemIntegrityChecker )createInstance (info .clazz , false , info .singleton );
232+ info .instance .check ();
233+ } catch (Exception e ) {
234+ s_logger .error ("Problems with running checker:" + info .name , e );
235+ System .exit (1 );
236+ }
237+ }
238+ }
230239 /**
231240 * Daos should not refer to any other components so it is safe to start them
232241 * here.
@@ -848,6 +857,7 @@ public void addParameter(String name, String value) {
848857 protected class XmlHandler extends DefaultHandler {
849858 public HashMap <String , List <ComponentInfo <Adapter >>> adapters ;
850859 public HashMap <String , ComponentInfo <Manager >> managers ;
860+ public HashMap <String , ComponentInfo <SystemIntegrityChecker >> checkers ;
851861 public LinkedHashMap <String , ComponentInfo <GenericDao <?, ?>>> daos ;
852862 public String parent ;
853863 public String library ;
@@ -865,6 +875,7 @@ public XmlHandler(String serverName) {
865875 parse = false ;
866876 adapters = new HashMap <String , List <ComponentInfo <Adapter >>>();
867877 managers = new HashMap <String , ComponentInfo <Manager >>();
878+ checkers = new HashMap <String , ComponentInfo <SystemIntegrityChecker >>();
868879 daos = new LinkedHashMap <String , ComponentInfo <GenericDao <?, ?>>>();
869880 value = null ;
870881 parent = null ;
@@ -966,6 +977,12 @@ public void startElement(String namespaceURI, String localName, String qName, At
966977 daos .put (key , info );
967978 }
968979 currentInfo = info ;
980+ } else if (qName .equals ("checker" )) {
981+ ComponentInfo <SystemIntegrityChecker > info = new ComponentInfo <SystemIntegrityChecker >();
982+ fillInfo (atts , SystemIntegrityChecker .class , info );
983+ checkers .put (info .name , info );
984+ s_logger .info ("Adding system integrity checker: " + info .name );
985+ currentInfo = info ;
969986 } else {
970987 // ignore
971988 }
0 commit comments