Skip to content

Commit

Permalink
Added Interface to avoid useless warning with store objects
Browse files Browse the repository at this point in the history
  • Loading branch information
fbacchella committed Jun 6, 2013
1 parent bd3b86a commit a42dcd4
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/jrds/Graph.java
Expand Up @@ -131,7 +131,7 @@ protected void fillGraphDef(RrdGraphDef graphDef) {
}
}

protected Extractor<?> setGraphDefData(RrdGraphDef graphDef, Probe<?, ?> defProbe, ExtractInfo ei,
protected Extractor setGraphDefData(RrdGraphDef graphDef, Probe<?, ?> defProbe, ExtractInfo ei,
Map<String, ? extends Plottable> customData) {
GraphDesc gd = node.getGraphDesc();
return gd.fillGraphDef(graphDef, node.getProbe(), ei, customData);
Expand Down
6 changes: 3 additions & 3 deletions src/jrds/GraphDesc.java
Expand Up @@ -860,13 +860,13 @@ public RrdGraphDef getEmptyGraphDef() {
* @param defProbe The probe to get values from
* @param customData some custom data, they override existing values in the associated probe
*/
public Extractor<?> fillGraphDef(RrdGraphDef graphDef, Probe<?, ?> defProbe, ExtractInfo ei,
public Extractor fillGraphDef(RrdGraphDef graphDef, Probe<?, ?> defProbe, ExtractInfo ei,
Map<String, ? extends Plottable> customData) {
HostsList hl = defProbe.getHostList();
List<DsDesc> toDo = new ArrayList<DsDesc>();
//The datasources already found
Set<String> datasources = new HashSet<String>();
Extractor<?> extract = defProbe.fetchData();
Extractor extract = defProbe.fetchData();

for(DsDesc ds: allds) {
boolean complete = false;
Expand Down Expand Up @@ -989,7 +989,7 @@ public RrdGraphDef getGraphDef(Probe<?,?> defProbe, ExtractInfo ei, Map<String,
*/
public DataProcessor getPlottedDatas(Probe<?,?> probe, ExtractInfo ei, Map<?, ?> ownData) throws IOException {
DataProcessor retValue = ei.getDataProcessor();
Extractor<?> extract = probe.fetchData();
Extractor extract = probe.fetchData();
String lastName = null;
for(DsDesc ds: allds) {
boolean stack = ds.graphType == GraphType.STACK;
Expand Down
11 changes: 11 additions & 0 deletions src/jrds/JrdsSample.java
@@ -0,0 +1,11 @@
package jrds;

import java.util.Date;
import java.util.Map;

public interface JrdsSample extends Map<String, Number>{
public Date getTime();
public void setTime(Date time);
public void put(Map.Entry<String, Double> e);
public Probe<?, ?> getProbe();
}
20 changes: 10 additions & 10 deletions src/jrds/Probe.java
Expand Up @@ -21,9 +21,9 @@
import jrds.probe.UrlProbe;
import jrds.starter.HostStarter;
import jrds.starter.StarterNode;
import jrds.store.AbstractStore;
import jrds.store.AbstractStoreFactory;
import jrds.store.Extractor;
import jrds.store.Store;
import jrds.store.StoreFactory;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
Expand Down Expand Up @@ -82,8 +82,8 @@ public Probe<KeyType,ValueType> getProbe() {
private String label = null;
private Logger namedLogger = Logger.getLogger("jrds.Probe.EmptyProbe");
private volatile boolean running = false;
private Set<AbstractStore<?, ?>> stores = new HashSet<AbstractStore<?, ?>>();
private AbstractStore<?, ?> mainStore;
private Set<Store> stores = new HashSet<Store>();
private Store mainStore;

/**
* A special case constructor, mainly used by virtual probe
Expand Down Expand Up @@ -282,7 +282,7 @@ public void collect() {
//during the reading of samples
if( sample.size() > 0 && isCollectRunning()) {
mainStore.commit(sample);
for(AbstractStore<?, ?> store: stores) {
for(Store store: stores) {
store.commit(sample);
}
interrupted = false;
Expand Down Expand Up @@ -551,37 +551,37 @@ private final String parseTemplate(String template) {
/**
* @return the stores
*/
public Set<AbstractStore<?, ?>> getStores() {
public Set<Store> getStores() {
return stores;
}

/**
* @param stores the stores to set
*/
public void addStore(AbstractStoreFactory<?> factory) {
public void addStore(StoreFactory factory) {
stores.add(factory.create(this));
}

/**
* @return the mainStore
*/
public AbstractStore<?, ?> getMainStore() {
public Store getMainStore() {
return mainStore;
}

/**
* @param mainStore the mainStore to set
* @throws InvocationTargetException
*/
public void setMainStore(AbstractStoreFactory<?> factory, Map<String, String> args) throws InvocationTargetException {
public void setMainStore(StoreFactory factory, Map<String, String> args) throws InvocationTargetException {
this.mainStore = factory.configure(this, args);
}

public Map<String, Number> getLastValues() {
return mainStore.getLastValues();
}

public Extractor<?> fetchData() {
public Extractor fetchData() {
return mainStore.fetchData();
}

Expand Down
4 changes: 2 additions & 2 deletions src/jrds/PropertiesManager.java
Expand Up @@ -28,8 +28,8 @@

import jrds.factories.ArgFactory;
import jrds.starter.Timer;
import jrds.store.AbstractStoreFactory;
import jrds.store.RrdDbStoreFactory;
import jrds.store.StoreFactory;
import jrds.webapp.ACL;
import jrds.webapp.RolesACL;

Expand Down Expand Up @@ -507,7 +507,7 @@ else if(log4jPropFile != null && ! "".equals(log4jPropFile.trim())) {
public ACL defaultACL = ACL.ALLOWEDACL;
public ACL adminACL = ACL.ALLOWEDACL;
public boolean readonly = false;
public AbstractStoreFactory storefactory = new RrdDbStoreFactory();
public StoreFactory storefactory = new RrdDbStoreFactory();
public static final String FILTERTAB = "filtertab";
public static final String CUSTOMGRAPHTAB = "customgraph";
public static final String SUMSTAB = "sumstab";
Expand Down
3 changes: 2 additions & 1 deletion src/jrds/graphe/Sum.java
Expand Up @@ -15,6 +15,7 @@

import jrds.store.ExtractInfo;
import jrds.store.Extractor;

import org.rrd4j.data.LinearInterpolator;
import org.rrd4j.data.Plottable;

Expand Down Expand Up @@ -78,7 +79,7 @@ public void configure(long start, long end, long step) {
.make(ConsolFun.AVERAGE);
logger.debug(Util.delayedFormatString("Configuring the sum %s from %d to %d, step %d", Sum.this.getName(), start, end, step));
//Used to kept the last fetched data and analyse the
Extractor<?> fd = null;
Extractor fd = null;

double[][] allvalues = null;
for(String name : graphList) {
Expand Down
80 changes: 80 additions & 0 deletions src/jrds/store/AbstractExtractor.java
@@ -0,0 +1,80 @@
package jrds.store;

import java.util.HashMap;
import java.util.Map;

import org.rrd4j.data.Plottable;

public abstract class AbstractExtractor<Source> implements Extractor {
private final Map<Integer, Source> plotted = new HashMap<Integer, Source>();

public AbstractExtractor() {
super();
}

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getNames()
*/
@Override
public abstract String[] getNames();

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getDsNames()
*/
@Override
public abstract String[] getDsNames();

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getValues(jrds.store.ExtractInfo)
*/
@Override
public abstract double[][] getValues(ExtractInfo ei);

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getSourceValues(jrds.store.ExtractInfo)
*/
@Override
public abstract double[] getSourceValues(ExtractInfo ei);

protected Source getSource(ExtractInfo ei) {
int signature = getSignature(ei);
if(! plotted.containsKey(signature) ) {
plotted.put(signature, newPlottableSource(ei));
}
return plotted.get(signature);
}

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getPlottable(jrds.store.ExtractInfo)
*/
@Override
public final Plottable getPlottable(ExtractInfo ei) {
Source s = getSource(ei);
return newPlottable(s, ei);
}

protected abstract Source newPlottableSource(ExtractInfo ei);

protected abstract Plottable newPlottable(Source s, ExtractInfo ei);

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getTimestamps(jrds.store.ExtractInfo)
*/
@Override
public abstract long[] getTimestamps(ExtractInfo ei);

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getColumnCount()
*/
@Override
public abstract int getColumnCount();

protected abstract int getSignature(ExtractInfo ei);

/* (non-Javadoc)
* @see jrds.store.ExtractorInterface#getValue(jrds.store.ExtractInfo)
*/
@Override
public abstract double getValue(ExtractInfo ei);

}
6 changes: 3 additions & 3 deletions src/jrds/store/AbstractStore.java
Expand Up @@ -3,19 +3,20 @@
import java.util.Date;
import java.util.Map;

import jrds.JrdsSample;
import jrds.Probe;

import org.apache.log4j.Level;

public abstract class AbstractStore<StoreObject, DataSource> {
public abstract class AbstractStore<StoreObject, DataSource> implements Store {
protected final Probe<?, ?> p;

public AbstractStore(Probe<?, ?> p) {
super();
this.p = p;
}

public abstract void commit(Probe.JrdsSample sample);
public abstract void commit(JrdsSample sample);
public abstract Map<String, Number> getLastValues();
public abstract boolean checkStoreFile();
public abstract Date getLastUpdate();
Expand All @@ -30,5 +31,4 @@ public void log(Level l, String format, Object... elements) {
p.log(l, format, elements);
}

public abstract Extractor<DataSource> fetchData();
}
8 changes: 4 additions & 4 deletions src/jrds/store/AbstractStoreFactory.java
Expand Up @@ -7,12 +7,12 @@
import jrds.Probe;
import jrds.factories.ArgFactory;

public abstract class AbstractStoreFactory<Store extends AbstractStore<?,?>> {
public abstract class AbstractStoreFactory<StoreType extends AbstractStore<?,?>> implements StoreFactory {

public abstract Store create(Probe<?,? > p);
public abstract StoreType create(Probe<?,? > p);

public Store configure(Probe<?,? > p, Map<String, String> properties) throws InvocationTargetException {
Store s = create(p);
public StoreType configure(Probe<?,? > p, Map<String, String> properties) throws InvocationTargetException {
StoreType s = create(p);
for(PropertyDescriptor bean: ArgFactory.getBeanPropertiesMap(s.getClass(), AbstractStore.class).values()) {
String beanName = bean.getName();
if(properties.containsKey(beanName)) {
Expand Down
2 changes: 1 addition & 1 deletion src/jrds/store/EmptyExtractor.java
Expand Up @@ -2,7 +2,7 @@

import org.rrd4j.data.Plottable;

public class EmptyExtractor extends Extractor<Object> {
public class EmptyExtractor extends AbstractExtractor<Object> {

@Override
public String[] getNames() {
Expand Down
51 changes: 10 additions & 41 deletions src/jrds/store/Extractor.java
@@ -1,48 +1,17 @@
package jrds.store;

import java.util.HashMap;
import java.util.Map;

import org.rrd4j.data.Plottable;

public abstract class Extractor<Source> {
private final Map<Integer, Source> plotted = new HashMap<Integer, Source>();

public Extractor() {
super();
}

public abstract String[] getNames();

public abstract String[] getDsNames();

public abstract double[][] getValues(ExtractInfo ei);

public abstract double[] getSourceValues(ExtractInfo ei);
public interface Extractor {

protected Source getSource(ExtractInfo ei) {
int signature = getSignature(ei);
if(! plotted.containsKey(signature) ) {
plotted.put(signature, newPlottableSource(ei));
}
return plotted.get(signature);
}
public String[] getNames();
public String[] getDsNames();
public double[][] getValues(ExtractInfo ei);
public double[] getSourceValues(ExtractInfo ei);
public Plottable getPlottable(ExtractInfo ei);
public long[] getTimestamps(ExtractInfo ei);
public int getColumnCount();
public double getValue(ExtractInfo ei);

public final Plottable getPlottable(ExtractInfo ei) {
Source s = getSource(ei);
return newPlottable(s, ei);
}

protected abstract Source newPlottableSource(ExtractInfo ei);

protected abstract Plottable newPlottable(Source s, ExtractInfo ei);

public abstract long[] getTimestamps(ExtractInfo ei);

public abstract int getColumnCount();

protected abstract int getSignature(ExtractInfo ei);

public abstract double getValue(ExtractInfo ei);

}
}
4 changes: 2 additions & 2 deletions src/jrds/store/RRDToolStore.java
Expand Up @@ -73,15 +73,15 @@ public Map<String, Number> getLastValues() {
}

@Override
public Extractor<DataChunk> fetchData() {
public AbstractExtractor<DataChunk> fetchData() {
final RRDatabase db;
try {
db = new RRDatabase(rrdpath);
} catch (IOException e1) {
return null;
}

return new Extractor<DataChunk>() {
return new AbstractExtractor<DataChunk>() {

@Override
public String[] getNames() {
Expand Down
9 changes: 3 additions & 6 deletions src/jrds/store/RrdDbStore.java
Expand Up @@ -252,10 +252,10 @@ public Date getLastUpdate() {
}

@Override
public jrds.store.Extractor<FetchData> fetchData() {
public AbstractExtractor<FetchData> fetchData() {
try {
final RrdDb rrdDb = StoreOpener.getRrd(getRrdName());
return new jrds.store.Extractor<FetchData>() {
return new jrds.store.AbstractExtractor<FetchData>() {
@Override
public String[] getNames() {
try {
Expand Down Expand Up @@ -349,10 +349,7 @@ public void commit(JrdsSample sample) {
try {
rrdDb = StoreOpener.getRrd(getRrdName());
Sample onesample = rrdDb.createSample(sample.getTime().getTime() / 1000);
@SuppressWarnings("unchecked")
// Bug in jvm ? sample.entrySet() can't be directly called in the for
Set<Map.Entry<String, Number>> es = sample.entrySet();
for(Map.Entry<String, Number> e: es) {
for(Map.Entry<String, Number> e: sample.entrySet()) {
onesample.setValue(e.getKey(), e.getValue().doubleValue());
}
if(p.getNamedLogger().isDebugEnabled())
Expand Down

0 comments on commit a42dcd4

Please sign in to comment.