@Override public void configure(PropertiesManager pm) { super.configure(pm); maxConnect = pm.numCollectors; timeout = pm.timeout; }
public void startTimers() { if(started) collectTimer = new Timer("jrds-main-timer/" + thisgeneration, true); for(jrds.starter.Timer t: timers.values()) { t.startTimer(collectTimer); } for(Starter s: this.topStarters) { s.doStart(); } }
/** * It's called after the starter registration but in host list configuration * A starter can uses it to tweaks it's configuration It can be overriden to * contains delayed initialization but it must begin with a call to * super.configuration(pm) * * @param pm */ public void configure(PropertiesManager pm) { log(Level.DEBUG, "registred to %s", getLevel()); }
public final void doStart() { log(Level.TRACE, "Starting"); try { long begin = new Date().getTime(); started = start(); long end = new Date().getTime(); log(Level.DEBUG, "Starting connection took %d ms", end - begin); } catch (Exception e) { log(Level.ERROR, e, "Error while starting: %s", e.getMessage()); } catch (NoClassDefFoundError e) { log(Level.ERROR, e, e.getMessage().replace('/', '.')); } if(!started) { log(Level.ERROR, "starting failed"); } }
/** * @param s the starter to register * @return the starter that will be used */ public Starter registerStarter(Starter s) { Object key = s.getKey(); if(allStarters == null) // Must be a linked hashed map, order of insertion might be // important allStarters = new LinkedHashMap<Object, Starter>(2); if(!allStarters.containsKey(key)) { s.initialize(this); allStarters.put(key, s); log(Level.DEBUG, "registering %s with key %s", s.getClass().getName(), key); return s; } else { return allStarters.get(key); } }
@Override public String toString() { String levelString = "''"; String keyString; if(level != null) levelString = level.toString(); Object key = getKey(); if(key instanceof Class<?>) { keyString = ((Class<?>) key).getName(); } else { keyString = key.toString(); } return keyString + "@" + levelString; }
@Override public boolean isCollectRunning() { if(resolver == null || !resolver.isStarted()) return false; return super.isCollectRunning(); }
/** * Ensure that all collects are stopped, some slow probes might need a * little help */ public void stop() { started = false; if(collectTimer != null) collectTimer.cancel(); collectTimer = null; for(Starter s: topStarters) { s.doStop(); } for(jrds.starter.Timer t: timers.values()) { t.stopCollect(); for(HostStarter h: t.getAllHosts()) { h.stopCollect(); for(Probe<?, ?> p: h.getAllProbes()) { p.stopCollect(); } } t.interrupt(); } }
@Override public void configure(PropertiesManager pm) { super.configure(pm); starterKey = getLevel().getParent().registerStarter(new Resolver(bmcname)).getKey(); }
public boolean isStarted(Object key) { boolean s = false; Starter st = find(Starter.class, key); if(st != null) s = st.isStarted(); return s; }
/** * Called in the host list configuration, used to finished the configuration * of the starters * * @param pm the configuration */ public void configureStarters(PropertiesManager pm) { if(allStarters == null) return; // needed because started can failed (and be removed) or add other // starters List<Map.Entry<Object, Starter>> buffer = new ArrayList<>(allStarters.entrySet()); for(Map.Entry<Object, Starter> me: buffer) { try { me.getValue().configure(pm); } catch (Exception e) { allStarters.remove(me.getKey()); log(Level.ERROR, e, "Starter %s failed to configure: %s", me.getValue(), e); } } }
@Override public boolean start() { boolean started = false; Starter resolver = getLevel().find(Resolver.class); if(resolver.isStarted()) { Properties p = getProperties(); p.put("user", user); p.put("password", passwd); try { DriverManager.setLoginTimeout(10); con = DriverManager.getConnection(url, user, passwd); started = true; } catch (SQLException e) { log(Level.ERROR, e, "SQL error: %s", e); } } return started; }
public boolean startCollect() { if(parent != null && !parent.isCollectRunning()) { log(Level.TRACE, "parent of %s prevent starting", this); return false; } if(allStarters != null) { log(Level.DEBUG, "Starting %d starters for %s", allStarters.size(), this); for(Starter s: allStarters.values()) { // If collect is stopped while we're starting, drop it if(parent != null && !parent.isCollectRunning()) return false; try { s.doStart(); } catch (Exception e) { log(Level.ERROR, e, "starting %s failed: %s", s, e); } } } started = true; log(Level.DEBUG, "Starting for %s done", this); return isCollectRunning(); }
@Override public void configure(PropertiesManager pm) { super.configure(pm); protocol = pm.getProperty("ssl.protocol", null); // Default is false, because it was the default setting in previous release strict = pm.parseBoolean(pm.getProperty("ssl.strict", "false")); truststore = pm.getProperty("ssl.truststore", null); trustpassword = pm.getProperty("ssl.trustpassword", ""); format = pm.getProperty("ssl.trusttype", KeyStore.getDefaultType()); securerandom = pm.getProperty("ssl.securerandom", null); }
topStarters.add(top); registerStarter(top); top.configure(pm); } catch (Throwable e) { log(Level.ERROR, e, "Top level starter %s failed to register: %s", starterClass, e.getMessage());
private HostStarter addConnection(Starter cnx) throws IOException { String truststore = getClass().getClassLoader().getResource("localhost.jks").getFile(); PropertiesManager pm = Tools.makePm(testFolder, "timeout=1", "collectorThreads=1", "ssl.protocol=TLS", "ssl.strict=true", "ssl.truststore=" + truststore, "ssl.trustpassword=123456"); HostStarter localhost = new HostStarter(new HostInfo("localhost")); Timer t = Tools.getDefaultTimer(); localhost.setParent(t); localhost.getHost().setHostDir(testFolder.getRoot()); t.registerStarter(new SSLStarter()); t.registerStarter(new SocketFactory()); t.configureStarters(pm); localhost.registerStarter(cnx); cnx.configure(pm); return localhost; }