@Override public String toString() { return getKey() + "@" + getHostName(); }
public Resolver getResolver() { String hostName = getHostName(); Resolver r = getLevel().find(Resolver.class); if(r == null) { r = new Resolver(hostName); getLevel().registerStarter(r); } return r; }
@Override public boolean start() { if(!getResolver().isStarted()) return false; boolean started = startConnection(); if(started) { uptime = setUptime(); log(Level.DEBUG, "Uptime for %s = %ds", this, uptime); } return started; }
@Override public void configure(PropertiesManager pm) { url = jrds.Util.parseTemplate(url, this, getLevel()); super.configure(pm); }
public void register(StarterNode node) throws InvocationTargetException { try { Class<?>[] constArgsType = new Class[args.size()]; Object[] constArgsVal = new Object[args.size()]; int index = 0; for(Object arg: args) { constArgsType[index] = arg.getClass(); constArgsVal[index] = arg; index++; } Connection<?> cnx = type.getConstructor(constArgsType).newInstance(constArgsVal); for(Map.Entry<String, String> e: beansValue.entrySet()) { String textValue = Util.parseTemplate(e.getValue(), cnx); ArgFactory.beanSetter(cnx, e.getKey(), textValue); cnx.log(Level.TRACE, "Setting bean '%s' to value '%s' for %s", e.getKey(), textValue, node); } if(name != null && !name.trim().isEmpty()) cnx.setName(name.trim()); node.registerStarter(cnx); logger.debug(Util.delayedFormatString("Connexion registred: %s for %s", cnx, node)); } catch (InvocationTargetException ex) { String message = ex.getCause() != null ? ex.getCause().getMessage(): ex.getMessage(); throw new InvocationTargetException(ex.getCause(), "Error during connection creation of type " + type.getName() + " for " + node + ": " + message); } catch (Exception ex) { throw new InvocationTargetException(ex, "Error during connection creation of type " + type.getName() + " for " + node); } }
/** * To get the default time out * * @return the connection timeout in second */ public int getTimeout() { return getLevel().getTimeout(); }
@Override public boolean isCollectRunning() { String cnxName = getConnectionName(); Connection<?> cnx = find(Connection.class, cnxName); if(getNamedLogger().isTraceEnabled()) log(Level.TRACE, "Connection %s started: %s", cnxName, (cnx != null ? Boolean.toString(cnx.isStarted()) : "null")); if(cnx == null || !cnx.isStarted()) return false; return super.isCollectRunning(); }
/** * This method is used by getNewSampleValues to define the uptime for the * probe.<br> * The default way is to read it using the connection. It might be * overridden if needed. * * @param cnx */ protected void setUptime(ConnectionClass cnx) { setUptime(cnx.getUptime()); }
@Override public void configure(PropertiesManager pm) { super.configure(pm); starterKey = getLevel().getParent().registerStarter(new Resolver(bmcname)).getKey(); }
Socket makeSocket(String host, int port) throws IOException { SocketFactory sf = getLevel().find(SocketFactory.class); return sf.createSocket(host, port); }
/** * * The method that return a map of data collected.<br> * It should return return as raw as possible, they can even be opaque data * tied to the probe. the key is resolved using the <code>ProbeDesc</code>. * A key not associated with an existent datastore will generate a warning * but will not prevent the other values to be stored.<br> * the value should be a <code>java.lang.Number</code><br> * It also set the uptime for the probe, using connection data. One should * override setUptime if a probe use a specific uptime, that can't be * provided using the connection. * * @return the map of collected object */ @Override public Map<KeyType, ValueType> getNewSampleValues() { ConnectionClass cnx = getConnection(); if(cnx == null) { log(Level.WARN, "No connection found with name %s", getConnectionName()); } log(Level.DEBUG, "find connection %s", connectionName); if(cnx == null || !cnx.isStarted()) { return Collections.emptyMap(); } // Uptime is collected only once, by the connexion setUptime(cnx); return getNewSampleValuesConnected(cnx); }
@Override public void configure(PropertiesManager pm) { switch(protocol) { case jolokia: cnx = new JolokiaJmxConnection(); break; default: cnx = new NativeJmxConnection(); break; } cnx.setParent(this); cnx.setProtocol(protocol); if (port != null) { cnx.setPort(port); } if (path != null) { cnx.setPath(path); } if (url != null) { cnx.setUrl(url); } cnx.setSsl(ssl); cnx.setUser(user); cnx.setPassword(password); cnx.configure(pm); super.configure(pm); }
/** * Return the host name associated * * @return */ public String getHostName() { StarterNode level = getLevel(); if(level instanceof HostStarter) { return ((HostStarter) level).getDnsName(); } if(level instanceof Probe<?, ?>) { return ((Probe<?, ?>) level).getHost().getDnsName(); } return null; }