public boolean isCollectRunning() { if(Thread.interrupted()) { started = false; log(Level.TRACE, "thread is stopped", this); return false; } if(parent != null && !parent.isCollectRunning()) return false; return started; }
@SuppressWarnings("unchecked") public <StarterClass extends Starter> StarterClass find(Class<StarterClass> sc, Object key) { StarterClass s = null; if(allStarters != null) log(Level.TRACE, "Looking for starter %s with key %s in %s", sc, key, allStarters); if(allStarters != null && allStarters.containsKey(key)) { Starter stemp = allStarters.get(key); if(sc.isInstance(stemp)) { s = (StarterClass) stemp; } else { log(Level.ERROR, "Starter key error, got a %s expecting a %s", stemp.getClass(), sc); return null; } } else if(parent != null) s = parent.find(sc, key); else log(Level.DEBUG, "Starter class %s not found for key %s", sc.getName(), key); return s; }
public <StarterClass extends Starter> StarterClass find(Class<StarterClass> sc) { Object key; try { Method m = sc.getMethod("makeKey", StarterNode.class); key = m.invoke(null, this); } catch (NoSuchMethodException e) { // Not an error, the key is the the class key = sc.getName(); } catch (Exception e) { log(Level.ERROR, e, "Error for %s with %s: %s", this, sc, e); return null; } return find(sc, key); }
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(); }
/** * 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); } } }
/** * @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); } }
public synchronized void stopCollect() { started = false; if(allStarters != null) for(Starter s: allStarters.values()) { try { s.doStop(); } catch (Exception e) { log(Level.ERROR, e, "Unable to stop timer %s: %s", s.getKey(), e); } } }