@SuppressWarnings("unchecked") public <StarterClass extends Starter> StarterClass find(String key) { return (StarterClass) find(Starter.class, key); }
@Deprecated public Starter registerStarter(Starter s, StarterNode parent) { return registerStarter(s); }
public HostsList getHostList() { if(root == null && getParent() != null) root = getParent().getHostList(); return root; }
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; }
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 Resolver getResolver() { String hostName = getHostName(); Resolver r = getLevel().find(Resolver.class); if(r == null) { r = new Resolver(hostName); getLevel().registerStarter(r); } return r; }
@Test public void twoLevel() { StarterNode n1 = new StarterNode() { }; Starter s1 = new LocalStarter(0); n1.registerStarter(s1); StarterNode n2 = new StarterNode() { }; n2.setParent(n1); Starter s2 = new LocalStarter(1); n2.registerStarter(s2); Assert.assertNotNull(n2.find(LocalStarter.class, 1)); Assert.assertNotNull(n2.find(LocalStarter.class, 0)); }
@Override public boolean startConnection() { Resolver resolver = getLevel().find(Resolver.class); if(!resolver.isStarted()) return false; if(!getLevel().find(MainStarter.class).isStarted()) return false; snmpTarget = new CommunityTarget(address, new OctetString(community)); snmpTarget.setVersion(version); snmpTarget.setTimeout(getLevel().getTimeout() * 1000 / 2); snmpTarget.setRetries(1);
@Override public void configure(PropertiesManager pm) { super.configure(pm); starterKey = getLevel().getParent().registerStarter(new Resolver(bmcname)).getKey(); }
@Test public void testHostList2() { StarterNode n2 = new StarterNode() { }; StarterNode n3 = new StarterNode(n2) { }; HostsList hl = new HostsList(); n2.setParent(hl); Assert.assertEquals(hl, n3.getHostList()); }
/** * @return the timeout */ public int getTimeout() { return getLevel().getTimeout(); }
public StarterNode(StarterNode parent) { setParent(parent); }
@Test public void testHostList1() { HostsList hl = new HostsList(); StarterNode n2 = new StarterNode(hl) { }; StarterNode n3 = new StarterNode(n2) { }; Assert.assertEquals(hl, n3.getHostList()); }
Timer timer = (Timer) getParent().getParent(); if((end - start) > (timer.getSlowCollectTime() * 1000)) { log(Level.WARN, "slow collect time %.0fs", 1.0 * (end - start) / 1000);
@Test public void simpleStarter() { StarterNode n = new StarterNode() { }; Starter s = new Starter() { }; n.registerStarter(s); Assert.assertNotNull(n.find(s.getClass())); }
@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 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(); }
/** * To get the default time out * * @return the connection timeout in second */ public int getTimeout() { return getLevel().getTimeout(); }
@Deprecated public void setParent(StartersSet s) { setParent((StarterNode) s); }
@Deprecated public Starter find(Object key) { return find(Starter.class, key); }