mirror of
https://github.com/i2p/i2p.i2p.git
synced 2024-12-06 19:27:00 +01:00
RRD4J 3.8
Merged in our previous javadoc fixes Their updated font-selector code remains commented out in RrdGraphConstants.getFont() Now requires Java 8
This commit is contained in:
@@ -7,7 +7,10 @@ import java.awt.Stroke;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
@@ -17,11 +20,13 @@ import java.util.TimeZone;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.rrd4j.ConsolFun;
|
||||
import org.rrd4j.core.DataHolder;
|
||||
import org.rrd4j.core.FetchData;
|
||||
import org.rrd4j.core.RrdBackendFactory;
|
||||
import org.rrd4j.core.RrdDbPool;
|
||||
import org.rrd4j.core.Util;
|
||||
import org.rrd4j.data.DataProcessor;
|
||||
import org.rrd4j.data.Plottable;
|
||||
import org.rrd4j.data.IPlottable;
|
||||
import org.rrd4j.data.Variable;
|
||||
|
||||
/**
|
||||
@@ -52,7 +57,7 @@ import org.rrd4j.data.Variable;
|
||||
* without forcing a newline, you can use the special tag \J at the end of
|
||||
* the string to disable the auto justification.</p>
|
||||
*/
|
||||
public class RrdGraphDef implements RrdGraphConstants {
|
||||
public class RrdGraphDef implements RrdGraphConstants, DataHolder {
|
||||
|
||||
/**
|
||||
* <p>Implementations of this class can be used to generate image than can be
|
||||
@@ -96,7 +101,8 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
}
|
||||
}
|
||||
|
||||
boolean poolUsed = false; // ok
|
||||
boolean poolUsed = DEFAULT_POOL_USAGE_POLICY;
|
||||
private RrdDbPool pool = null;
|
||||
boolean antiAliasing = false; // ok
|
||||
boolean textAntiAliasing = false; // ok
|
||||
String filename = RrdGraphConstants.IN_MEMORY_IMAGE; // ok
|
||||
@@ -173,17 +179,47 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
/**
|
||||
* Creates RrdGraphDef object and sets default time span (default ending time is 'now',
|
||||
* default starting time is 'end-1day'.
|
||||
* @deprecated Uses default value that will be probably overriden.
|
||||
*/
|
||||
@Deprecated
|
||||
public RrdGraphDef() {
|
||||
setTimeSpan(Util.getTimestamps(DEFAULT_START, DEFAULT_END));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates RrdGraphDef object.
|
||||
* @since 3.7
|
||||
*/
|
||||
public RrdGraphDef(long t1, long t2) {
|
||||
if ((t1 < t2 && t1 > 0 && t2 > 0) || (t1 > 0 && t2 == 0)) {
|
||||
this.startTime = t1;
|
||||
this.endTime = t2;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid timestamps specified: " + t1 + ", " + t2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new DataProcessor object for the given time duration. The given duration will be
|
||||
* substracted from current time.
|
||||
*
|
||||
* @param d duration to substract.
|
||||
* @since 3.7
|
||||
*/
|
||||
public RrdGraphDef(TemporalAmount d) {
|
||||
Instant now = Instant.now();
|
||||
this.endTime = now.getEpochSecond();
|
||||
this.startTime = now.minus(d).getEpochSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time when the graph should begin. Time in seconds since epoch
|
||||
* (1970-01-01) is required. Negative numbers are relative to the current time.
|
||||
*
|
||||
* @param time Starting time for the graph in seconds since epoch
|
||||
*/
|
||||
@Override
|
||||
public void setStartTime(long time) {
|
||||
this.startTime = time;
|
||||
if (time <= 0) {
|
||||
@@ -197,6 +233,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*
|
||||
* @param time Ending time for the graph in seconds since epoch
|
||||
*/
|
||||
@Override
|
||||
public void setEndTime(long time) {
|
||||
this.endTime = time;
|
||||
if (time <= 0) {
|
||||
@@ -211,6 +248,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param startTime Starting time in seconds since epoch
|
||||
* @param endTime Ending time in seconds since epoch
|
||||
*/
|
||||
@Override
|
||||
public void setTimeSpan(long startTime, long endTime) {
|
||||
setStartTime(startTime);
|
||||
setEndTime(endTime);
|
||||
@@ -234,10 +272,36 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*
|
||||
* @param poolUsed true, if RrdDbPool class should be used. False otherwise.
|
||||
*/
|
||||
@Override
|
||||
public void setPoolUsed(boolean poolUsed) {
|
||||
this.poolUsed = poolUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public boolean isPoolUsed() {
|
||||
return poolUsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public RrdDbPool getPool() {
|
||||
return pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public void setPool(RrdDbPool pool) {
|
||||
this.poolUsed = true;
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the graph to generate. Since Rrd4j outputs GIFs, PNGs,
|
||||
* and JPEGs it's recommended that the filename end in either .gif,
|
||||
@@ -781,6 +845,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*
|
||||
* @param step Desired time step (don't use this method if you don't know what you're doing).
|
||||
*/
|
||||
@Override
|
||||
public void setStep(long step) {
|
||||
this.step = step;
|
||||
}
|
||||
@@ -821,7 +886,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* font is selected.
|
||||
*
|
||||
* @param smallFont Default font for graphing. Use only monospaced fonts.
|
||||
* @deprecated Use {@link Variable} based method instead.
|
||||
* @deprecated Use {@link FontTag} based method instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSmallFont(final Font smallFont) {
|
||||
@@ -832,7 +897,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* Sets title font.
|
||||
*
|
||||
* @param largeFont Font to be used for graph title.
|
||||
* @deprecated Use {@link Variable} based method instead.
|
||||
* @deprecated Use {@link FontTag} based method instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLargeFont(final Font largeFont) {
|
||||
@@ -948,8 +1013,27 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param dsName Datasource name in the specified RRD file
|
||||
* @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, String rrdPath, String dsName, ConsolFun consolFun) {
|
||||
sources.add(new Def(name, rrdPath, dsName, consolFun));
|
||||
RrdBackendFactory factory = RrdBackendFactory.getDefaultFactory();
|
||||
sources.add(new Def(name, factory.getUri(rrdPath), dsName, consolFun, factory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines virtual datasource. This datasource can then be used
|
||||
* in other methods like {@link #datasource(String, String)} or
|
||||
* {@link #gprint(String, ConsolFun, String)}.
|
||||
*
|
||||
* @param name Source name
|
||||
* @param rrdUri URI to RRD file
|
||||
* @param dsName Datasource name in the specified RRD file
|
||||
* @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, URI rrdUri, String dsName,
|
||||
ConsolFun consolFun) {
|
||||
sources.add(new Def(name, rrdUri, dsName, consolFun, RrdBackendFactory.findFactory(rrdUri)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -967,7 +1051,8 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*/
|
||||
@Deprecated
|
||||
public void datasource(String name, String rrdPath, String dsName, ConsolFun consolFun, String backend) {
|
||||
sources.add(new Def(name, rrdPath, dsName, consolFun, RrdBackendFactory.getFactory(backend)));
|
||||
RrdBackendFactory factory = RrdBackendFactory.getFactory(backend);
|
||||
sources.add(new Def(name, factory.getUri(rrdPath), dsName, consolFun, factory));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -981,8 +1066,27 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
|
||||
* @param backend Backend to be used while fetching data from a RRD file.
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, String rrdPath, String dsName, ConsolFun consolFun, RrdBackendFactory backend) {
|
||||
sources.add(new Def(name, rrdPath, dsName, consolFun, backend));
|
||||
sources.add(new Def(name, backend.getUri(rrdPath), dsName, consolFun, backend));
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines virtual datasource. This datasource can then be used
|
||||
* in other methods like {@link #datasource(String, String)} or
|
||||
* {@link #gprint(String, ConsolFun, String)}.
|
||||
*
|
||||
* @param name Source name
|
||||
* @param rrdUri Path to RRD file
|
||||
* @param dsName Datasource name in the specified RRD file
|
||||
* @param consolFun Consolidation function (AVERAGE, MIN, MAX, LAST)
|
||||
* @param backend Backend to be used while fetching data from a RRD file.
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, URI rrdUri, String dsName,
|
||||
ConsolFun consolFun, RrdBackendFactory backend) {
|
||||
sources.add(new Def(name, rrdUri, dsName, consolFun, backend));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -992,6 +1096,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param name Source name
|
||||
* @param rpnExpression RPN expression.
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, String rpnExpression) {
|
||||
sources.add(new CDef(name, rpnExpression));
|
||||
}
|
||||
@@ -1010,6 +1115,19 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
datasource(name, defName, consolFun.getVariable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a datasource that performs a variable calculation on an
|
||||
* another named datasource to yield a single combined timestamp/value.
|
||||
*
|
||||
* Requires that the other datasource has already been defined; otherwise, it'll
|
||||
* end up with no data
|
||||
*
|
||||
* @param name - the new virtual datasource name
|
||||
* @param defName - the datasource from which to extract the percentile. Must be a previously
|
||||
* defined virtual datasource
|
||||
* @param var - a new instance of a Variable used to do the calculation
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, String defName, Variable var) {
|
||||
sources.add(new VDef(name, defName, var));
|
||||
}
|
||||
@@ -1020,8 +1138,10 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*
|
||||
* @param name Source name.
|
||||
* @param plottable Plottable object.
|
||||
* @since 3.7
|
||||
*/
|
||||
public void datasource(String name, Plottable plottable) {
|
||||
@Override
|
||||
public void datasource(String name, IPlottable plottable) {
|
||||
sources.add(new PDef(name, plottable));
|
||||
}
|
||||
|
||||
@@ -1032,6 +1152,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param name Source name.
|
||||
* @param fetchData FetchData object.
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, FetchData fetchData) {
|
||||
sources.add(new TDef(name, name, fetchData));
|
||||
}
|
||||
@@ -1045,6 +1166,7 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
* @param dsName Source name in fetchData.
|
||||
* @param fetchData FetchData object.
|
||||
*/
|
||||
@Override
|
||||
public void datasource(String name, String dsName, FetchData fetchData) {
|
||||
sources.add(new TDef(name, dsName, fetchData));
|
||||
}
|
||||
@@ -1723,10 +1845,19 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
*
|
||||
* @param tz the time zone to set
|
||||
*/
|
||||
@Override
|
||||
public void setTimeZone(TimeZone tz) {
|
||||
this.tz = tz;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public TimeZone getTimeZone() {
|
||||
return this.tz;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Stroke used to draw grid
|
||||
*
|
||||
@@ -1784,4 +1915,28 @@ public class RrdGraphDef implements RrdGraphConstants {
|
||||
return colors[element.ordinal()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public long getEndTime() {
|
||||
return this.endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 3.7
|
||||
*/
|
||||
@Override
|
||||
public long getStep() {
|
||||
return this.step;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user