"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "moskito-webui/src/main/java/net/anotheria/moskito/webui/gauges/api/GaugeAPIImpl.java" between
moskito-moskito-2.8.9.tar.gz and moskito-moskito-2.9.0.tar.gz

About: MoSKito (Monitoring System Kit) is a framework for java application monitoring. Sources.

GaugeAPIImpl.java  (moskito-moskito-2.8.9):GaugeAPIImpl.java  (moskito-moskito-2.9.0)
package net.anotheria.moskito.webui.gauges.api; package net.anotheria.moskito.webui.gauges.api;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import net.anotheria.anoplass.api.APIException; import net.anotheria.anoplass.api.APIException;
import net.anotheria.anoplass.api.APIInitException; import net.anotheria.anoplass.api.APIInitException;
import net.anotheria.moskito.core.config.MoskitoConfiguration; import net.anotheria.moskito.core.config.MoskitoConfiguration;
import net.anotheria.moskito.core.config.MoskitoConfigurationHolder; import net.anotheria.moskito.core.config.MoskitoConfigurationHolder;
import net.anotheria.moskito.core.config.gauges.GaugeConfig; import net.anotheria.moskito.core.config.gauges.GaugeConfig;
import net.anotheria.moskito.core.config.gauges.GaugeValueConfig; import net.anotheria.moskito.core.config.gauges.GaugeValueConfig;
import net.anotheria.moskito.core.config.gauges.GaugeZoneConfig; import net.anotheria.moskito.core.config.gauges.GaugeZoneConfig;
import net.anotheria.moskito.core.config.gauges.GaugesConfig; import net.anotheria.moskito.core.config.gauges.GaugesConfig;
import net.anotheria.moskito.core.decorators.value.DoubleValueAO; import net.anotheria.moskito.core.decorators.value.DoubleValueAO;
import net.anotheria.moskito.core.decorators.value.LongValueAO; import net.anotheria.moskito.core.decorators.value.LongValueAO;
import net.anotheria.moskito.core.decorators.value.StatValueAO; import net.anotheria.moskito.core.decorators.value.StatValueAO;
import net.anotheria.moskito.core.decorators.value.StringValueAO; import net.anotheria.moskito.core.decorators.value.StringValueAO;
import net.anotheria.moskito.core.producers.IStats; import net.anotheria.moskito.core.producers.IStats;
import net.anotheria.moskito.core.producers.IStatsProducer; import net.anotheria.moskito.core.producers.IStatsProducer;
import net.anotheria.moskito.core.registry.IProducerRegistryAPI; import net.anotheria.moskito.core.registry.IProducerRegistryAPI;
import net.anotheria.moskito.core.registry.NoSuchProducerException; import net.anotheria.moskito.core.registry.NoSuchProducerException;
import net.anotheria.moskito.core.registry.ProducerRegistryAPIFactory; import net.anotheria.moskito.core.registry.ProducerRegistryAPIFactory;
import net.anotheria.moskito.core.stats.TimeUnit; import net.anotheria.moskito.core.stats.TimeUnit;
import net.anotheria.moskito.webui.shared.api.AbstractMoskitoAPIImpl; import net.anotheria.moskito.webui.shared.api.AbstractMoskitoAPIImpl;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* Gauge api implementation. * Gauge api implementation.
* *
* @author lrosenberg * @author lrosenberg
* @since 25.03.15 11:41 * @since 25.03.15 11:41
*/ */
public class GaugeAPIImpl extends AbstractMoskitoAPIImpl implements GaugeAPI { public class GaugeAPIImpl extends AbstractMoskitoAPIImpl implements GaugeAPI {
/** /**
* RegistryAPI. * RegistryAPI.
*/ */
private IProducerRegistryAPI producerRegistryAPI; private IProducerRegistryAPI producerRegistryAPI;
private List<GaugeZoneAO> defaultZones; private List<GaugeZoneAO> defaultZones;
/**
* This map is used to save previous values in case we might need them la
ter. The logic: if a producer exists, but there is no value (which can actually
only happen for duration values) we take last value.
*/
private ConcurrentHashMap<String, StatValueAO> previousValues = new Concu
rrentHashMap<>();
@Override @Override
public void init() throws APIInitException { public void init() throws APIInitException {
super.init(); super.init();
producerRegistryAPI = new ProducerRegistryAPIFactory().createProd ucerRegistryAPI(); producerRegistryAPI = new ProducerRegistryAPIFactory().createProd ucerRegistryAPI();
MoskitoConfiguration configuration = getConfiguration(); MoskitoConfiguration configuration = getConfiguration();
GaugeZoneConfig[] defaultZonesConfig = configuration.getGaugesCon fig().getDefaultZones(); GaugeZoneConfig[] defaultZonesConfig = configuration.getGaugesCon fig().getDefaultZones();
if (defaultZonesConfig == null || defaultZonesConfig.length == 0) { if (defaultZonesConfig == null || defaultZonesConfig.length == 0) {
defaultZones = createDefaultZones(); defaultZones = createDefaultZones();
}else{ }else{
skipping to change at line 168 skipping to change at line 174
}catch(NoSuchProducerException e){ }catch(NoSuchProducerException e){
//this is alternative to producer == null and is handled in next if. //this is alternative to producer == null and is handled in next if.
} }
if (producer == null ) if (producer == null )
return new StringValueAO(null, "no producer"); return new StringValueAO(null, "no producer");
for (IStats s : producer.getStats()){ for (IStats s : producer.getStats()){
if (s.getName().equals(config.getStatName())){ if (s.getName().equals(config.getStatName())){
String value = s.getValueByNameAsString(config.ge tValueName(), config.getIntervalName(), TimeUnit.valueOf(config.getTimeUnit())); String value = s.getValueByNameAsString(config.ge tValueName(), config.getIntervalName(), TimeUnit.valueOf(config.getTimeUnit()));
if ("NaN".equals(value) || value == null) { if ("NaN".equals(value) || value == null) {
//Obviously producer exists, but there ar
e no values in THIS interval. Probably it is something like AVG (because NaN can
't come from legal values).
//lets check if we have a previous value
we can re-use.
StatValueAO previousValue = getPreviousVa
lue(config);
if (previousValue!=null)
return previousValue;
return new StringValueAO(null, "n.A."); return new StringValueAO(null, "n.A.");
} }
StatValueAO numericValue = null;
try { try {
return new LongValueAO(null, Long.valueOf (value)); numericValue = new LongValueAO(null, Lon g.valueOf(value));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
try { try {
return new DoubleValueAO(null, Do uble.valueOf(value)); numericValue = new DoubleValueAO( null, Double.valueOf(value));
} catch (NumberFormatException e2) { } catch (NumberFormatException e2) {
this.log.error("Can't parse long/ double value, probably invalid value for gauge " + config); log.error("Can't parse long/doubl e value, probably invalid value for gauge " + config);
return new StringValueAO(null, "E rror"); return new StringValueAO(null, "E rror");
} }
} }
saveValueForLater(config, numericValue);
return numericValue;
} }
} }
return new StringValueAO(null, "n.A."); return new StringValueAO(null, "n.A.");
} }
private void saveValueForLater(GaugeValueConfig valueConfig, StatValueAO
valueAO){
previousValues.put(valueConfig.getKey(), valueAO);
}
private StatValueAO getPreviousValue(GaugeValueConfig valueConfig){
return previousValues.get(valueConfig.getKey());
}
} }
 End of changes. 10 change blocks. 
7 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)