⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rrdexportdef.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * Static graph sources are the result of a consolidation function applied
	 * to *any* other graph source that has been defined previously.</p>
	 *
	 * @param name Graph source name.
	 * @param defName Name of the datasource to calculate the value from.
	 * @param consolFunc Consolidation function to use for value calculation
	 */
	public void datasource( String name, String defName, String consolFunc ) throws RrdException
	{
		cdefList.add( new Sdef(name, defName, consolFunc) );
		numSdefs++;
	}

	/**
	 * <p>Adds a custom graph source with the given name to the graph definition.
	 * The datapoints should be made available by a class extending Plottable.</p>
	 *
	 * @param name Graph source name.
	 * @param plottable Class that extends Plottable class and is suited for graphing.
	 */
	public void datasource( String name, Plottable plottable )
	{
		pdefList.add( new Pdef(name, plottable) );
	}

	/**
	 * <p>Adds a custom graph source with the given name to the graph definition.
	 * The datapoints should be made available by a class extending Plottable.</p>
	 *
	 * @param name Graph source name.
	 * @param plottable Class that extends Plottable class and is suited for graphing.
	 * @param index Integer referring to the datasource in the Plottable class.
	 */
	public void datasource( String name, Plottable plottable, int index )
	{
		pdefList.add( new Pdef(name, plottable, index) );
	}

	/**
	 * <p>Adds a custom graph source with the given name to the graph definition.
	 * The datapoints should be made available by a class extending Plottable.</p>
	 *
	 * @param name Graph source name.
	 * @param plottable Class that extends Plottable class and is suited for graphing.
	 * @param sourceName String name referring to the datasource in the Plottable class.
	 */
	public void datasource( String name, Plottable plottable, String sourceName )
	{
		pdefList.add( new Pdef(name, plottable, sourceName) );
	}

	/**
	 * Adds a set of ExportData to the datasource list.
	 *
	 * @param edata ExportData to add.
	 */
	public void addExportData( ExportData edata )
	{
		edefList.add( edata );
	}

	/**
	 * Sets a specific datasource to be exported (if export is strict).
	 * The expor legend for this datasource will be empty. 
	 *
	 * @param name Name of the datasource
	 */
	public void export( String name )
	{
		export( name, "" );
	}

	/**
	 * Sets a specific datasource to be exported (if export is strict).
	 * And maps an export legend to this datasource.
	 *
	 * @param name Name of the datasource
	 * @param legend Legend text
	 */
	public void export( String name, String legend )
	{
		if ( strict == STRICT_IMPLICIT_OFF )
			strict = STRICT_IMPLICIT_ON;

		exportList.add( new String[] { name, legend } );
	}

	/**
	 * <p>Sets the strict flag for the export functionality.  By default, the
	 * export is in implicit not-strict, this means that by default, all
	 * datasources specified in the RrdExportDef will be exported into
	 * the ExportData.</p>
	 *
	 * <p>If the strict flag is not specified explicitly by calling this method,
	 * the export will convert to implicitly strict as soon as a particular
	 * export() mapping is defined.  Explicit settings will override implicit.</p>
	 *
	 * <p>When explicit is off, the legend for datasources will by default be
	 * the same as the datasource name, the legend can be overridden by setting
	 * mappings using export() method.</p>
	 *
	 * <p>Strict export is the same behaviour as RRDtool's XPORT.</p>
	 *
	 * @param strict True if strict export should on, false if not.
	 */
	public void setStrictExport( boolean strict )
	{
		this.strict = ( strict ? STRICT_EXPLICIT_ON : STRICT_EXPLICIT_OFF );
	}

	/**
	 * Exports RrdExportDef (export definition) object in XML format to output stream.
	 * Generated code can be parsed with {@link RrdExportDefTemplate} class.
	 *
	 * @param stream Output stream to send XML code to.
	 */
	public void exportXmlTemplate( OutputStream stream )
	{
		XmlWriter xml = new XmlWriter( stream );

		xml.startTag("rrd_export_def");

        // SPAN
		xml.startTag("span");
		xml.writeTag("start", getStartTime() );
		xml.writeTag("end", getEndTime() );
		xml.closeTag(); // span

		// OPTIONS
		xml.startTag( "options" );
		if ( resolution > 1 )
			xml.writeTag( "resolution", resolution );
		xml.writeTag( "strict_export", ( strict == STRICT_IMPLICIT_ON || strict == STRICT_EXPLICIT_ON ? "true" : "false" ) );
		xml.closeTag();

		// DATASOURCES
		xml.startTag("datasources");
		// defs
		for ( int i = 0; i < fetchSources.size(); i++ )
			fetchSources.get( i ).exportXml(xml);
		// cdefs and sdefs
		for (int i = 0; i < cdefList.size(); i++ )
		{
			Cdef cdef = (Cdef) cdefList.get(i);
			cdef.exportXml(xml);
		}
		xml.closeTag(); // datasources

		// EXPORTS
		xml.startTag("exports");
		String[][] list = getExportDatasources();
		for ( int i = 0; i < list.length; i++ )
		{
			xml.startTag( "export" );
			xml.writeTag( "datasource", list[i][0] );
			xml.writeTag( "legend", list[i][1] );
			xml.closeTag();
		}
		xml.closeTag(); // exports

		xml.closeTag(); // rrd_export_def
		xml.flush();

		xml.flush();
	}

	/**
	 * Exports RrdExportDef (export definition) object in XML format to string.
	 * Generated code can be parsed with {@link RrdExportDefTemplate} class, see
	 * {@link RrdExportDef#exportXmlTemplate()}.
	 *
	 * @return String representing graph definition in XML format.
	 */
	public String getXmlTemplate()
	{
		return exportXmlTemplate();
	}

	/**
	 * Exports RrdExportDef (export definition) object in XML format to string.
	 * Generated code can be parsed with {@link RrdExportDefTemplate} class.
	 *
	 * @return String representing graph definition in XML format.
	 */
	public String exportXmlTemplate()
	{
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		exportXmlTemplate(outputStream);
		return outputStream.toString();
	}

	/**
	 * Exports RrdExportDef (export definition) object in XML format to file.
	 * Generated code can be parsed with {@link RrdExportDefTemplate} class.
	 *
	 * @param filePath destination file
	 */
	public void exportXmlTemplate(String filePath) throws IOException
	{
		FileOutputStream outputStream = new FileOutputStream(filePath, false);
		exportXmlTemplate(outputStream);
		outputStream.close();
	}

	// ================================================================
	// -- Protected (package) methods
	// ================================================================
	protected long getStartTime() {
		return startTime;
	}

	protected long getEndTime() {
		return endTime;
	}

	protected long getResolution() {
		return resolution;
	}

	protected int getNumDefs()
	{
		return numDefs;
	}

	protected Cdef[] getCdefs()
	{
		return (Cdef[]) cdefList.toArray( new Cdef[] {} );
	}

	protected Pdef[] getPdefs()
	{
		return (Pdef[]) pdefList.toArray( new Pdef[] {} );
	}

	protected ExportData[] getExportData()
	{
		return (ExportData[]) edefList.toArray( new ExportData[] {} );
	}

	protected int getNumSdefs()
	{
		return numSdefs;
	}

	protected FetchSourceList getFetchSources()
	{
		return fetchSources;
	}

	protected boolean isStrict() {
		return ( strict == STRICT_IMPLICIT_ON || strict == STRICT_EXPLICIT_ON );
	}

	protected String[][] getExportDatasources() {
		return (String[][]) exportList.toArray( new String[0][2] );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -