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

📄 rrdexporter.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			vStartTime				= Util.normalize( startTime, minStep );
			vStartTime				= ( vStartTime > startTime ? vStartTime - minStep : vStartTime );

			if ( !changingEndTime )
			{
				vEndTime			= Util.normalize( endTime, minStep );
				vEndTime			= ( vEndTime < endTime ? vEndTime + minStep : vEndTime );
			}
			else
			{
				vEndTime			= Util.normalize( Util.getTime(), minStep );
				vEndTime			= ( vEndTime < endTime ? vEndTime + minStep : vEndTime );
			}

			reducedEndTime			= vEndTime;
			reducedStartTime		= vStartTime;
			reducedStep				= minStep;
			reducedNumRows			= (int) ((reducedEndTime - reducedStartTime) / reducedStep) + 1;
			finalEndTime			= endTime;

			vEndTime				+= minStep;
			numRows					= reducedNumRows; //(int) ((vEndTime - vStartTime) / minStep) + 1;
		}

		// -- Add all Export datasources to the source table
		for ( int i = 0; i < edefList.length; i++ )
		{
			sources[tblPos] = new Def( edefList[i].getName(), numRows, reducedNumRows );
			sources[tblPos].setFetchedStep( edefList[i].getStep() );
			sourceIndex.put( edefList[i].getName(), new Integer(tblPos++) );
		}

		// -- Add all Pdefs to the source table
		for ( int i = 0; i < pdefList.length; i++ )
		{
			pdefList[i].prepare( numRows, reducedNumRows );
			pdefList[i].setFetchedStep( minStep );

			sources[tblPos] = pdefList[i];
			sourceIndex.put( pdefList[i].getName(), new Integer(tblPos++) );
		}

		int cdefStart = tblPos;		// First Cdef element, necessary for tree descend calculation

		// -- Add all Cdefs to the source table
		// Reparse all RPN datasources to use indices of the correct variables
		for ( int i = 0; i < cdefList.length; i++ )
		{
			cdefList[i].prepare( sourceIndex, numRows, reducedNumRows );
			cdefList[i].setFetchedStep( minStep );

			sources[tblPos]	= cdefList[i];
			sourceIndex.put( cdefList[i].getName(), new Integer(tblPos++) );
		}

		// Fill the array for all datasources
		timestamps 				= new long[numRows];

		// RPN calculator for the Cdefs
		RpnCalculator rpnCalc 	= new RpnCalculator( sources, minStep );

		int pos = 0;
		for (int j = 0; j < veList.length; j++)
			pos = veList[j].prepareSources( sources, pos );

		// **************************************************************************************** //
		// If there are Sdefs, we should determine a tree-descend order for calculation.			//
		// An Sdef is completely dependant on another datasource and can only be calculated			//
		// after the datasource it depends on has been calculated itself entirely.					//
		//  e.g. The Sdef giving the AVG of a Def should be one lower in the calculation tree		//
		//		 than the corresponding Def.  Lower = higher level.									//
		// Since Sdefs can be nested and combined into new Cdefs and possibly resulting in new		//
		// Sdefs, the worst case calculation could result in every datasource being calculated		//
		// separately, resulting in more overhead.  However the impact of this should remain fairly	//
		// small in CPU time.																		//
		// **************************************************************************************** //
		if ( numSdefs > 0 )
		{
			// Initalize level for each def on 0
			int treeDepth	= 0;
			int[] treeLevel = new int[ sources.length ];

			// First level contains all fetched datasources, custom datasources and combined datasources that use other first levels
			for ( int i = cdefStart; i < sources.length; i++ )
			{
				// Get the level of all defs needed, take the maximum level
				int level 		= ((Cdef) sources[i]).calculateLevel( treeLevel );
				treeDepth		= (level > treeDepth ? level : treeDepth);

				treeLevel[i]	= level;
			}

			// Run through each level of the tree
			long t;

			for ( int l = 0; l <= treeDepth; l++ )
			{
				t 	= vStartTime - minStep;
				for ( int i = 0; i < numRows; i++ )
				{
					pos = cdefStart;

					// First level of the tree includes fetched datasources and pdefs,
					// since these values can never depend on others in the list.
					if ( l == 0 )
					{
						// Calculate new timestamp
						pos	= 0;
						t 	+= minStep;

						// Get all fetched datasources
						for (int j = 0; j < veList.length; j++)
							pos = veList[j].extract( t, sources, i, pos );

						// Get all export datasources
						for (int j = pos; j < pos + numEdefs; j++ )
							sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) );
						pos += numEdefs;

						// Get all custom datasources
						for (int j = pos; j < pos + numPdefs; j++)
							((Pdef) sources[j]).set( i, t );
						pos += numPdefs;

						timestamps[i] = t;
					}
					else
						t = timestamps[i];

					// Calculate the cdefs of this level
					for ( int j = pos; j < sources.length; j++ )
					{
						if ( treeLevel[j] == l )
						{
							// This Cdef/Sdef can be calculated
							if ( sources[j] instanceof Sdef )
								((Sdef) sources[j]).set( sources );
							else
								sources[j].set( i, t, rpnCalc.evaluate( (Cdef) sources[j], i, t ) );
						}
					}
				}
			}
		}
		else
		{
			// Traditional way of calculating all datasources, slightly faster
			long t = vStartTime - minStep;
			for ( int i = 0; i < numRows; i++ )
			{
				t		+= minStep;
				pos 	= 0;

				// Get all fetched datasources
				for (int j = 0; j < veList.length; j++)
					pos = veList[j].extract( t, sources, i, pos );

				// Get all export datasources
				for (int j = pos; j < pos + numEdefs; j++ )
					sources[j].set( i, t, edefList[j - pos].get( t, edata[ edefTs[j - pos] ].getTimestamps() ) );
				pos += numEdefs;

				// Get all custom datasources
				for (int j = pos; j < pos + numPdefs; j++)
					((Pdef) sources[j]).set( i, t );
				pos += numPdefs;

				// Get all combined datasources
				for (int j = pos; j < sources.length; j++)
					sources[j].set(i, t, rpnCalc.evaluate( (Cdef) sources[j], i, t ) );

				timestamps[i] = t;
			}
		}

		// Clean up the fetched datasources forcibly
		veList = null;

		this.startTime 	= startTime;
		this.endTime	= ( changingEndTime ? finalEndTime : endTime );
	}

	private Source getSource( String name ) throws RrdException
	{
		if ( !sourceIndex.containsKey(name) )
			throw new RrdException( "No such datasource: " + name );

		return sources[ ( (Integer) sourceIndex.get(name) ).intValue() ];
	}

	/**
	 * Creates an ExportData object corresponding to the reduced dataset
	 * contained in the RrdExporter.  This assumes that the reduced dataset
	 * has been calculated already!
	 *
	 * @return ExportData object created.
	 * @throws RrdException Thrown in case of JRobin specific error.
	 */
	protected ExportData createExportData() throws RrdException
	{
		if ( sources == null)
			throw new RrdException( "Sources not calculated, no data to return." );
		
		// Now create a RrdDataSet object containing the results
		Source[] sourceSet;
		String[][] export 	= def.getExportDatasources();
		HashMap legends		= new HashMap( export.length );

		if ( def.isStrict() )
		{
			sourceSet			= new Def[ export.length ];
			for ( int i = 0; i < export.length; i++ )
				sourceSet[i] = createReducedDef( getSource( export[i][0] ) );
		}
		else
		{
			sourceSet			= new Def[ sources.length ];
			for ( int i = 0; i < sources.length; i++ )
			{
				sourceSet[i] = createReducedDef( sources[i] );
				legends.put( sourceSet[i].getName(), sourceSet[i].getName() );
			}
		}

		for ( int i = 0; i < export.length; i++ )
			legends.put( export[i][0], export[i][1] );

		long[] reducedTs = new long[ reducedNumRows ];
		System.arraycopy( timestamps, 0, reducedTs, 0, reducedNumRows );

		return new ExportData( reducedTs, sourceSet, legends );
	}

	private Def createReducedDef( Source origSrc )
	{
		Def src = new Def( origSrc.getName(), reducedNumRows, reducedNumRows );
		src.setFetchedStep( reducedStep );

		for ( int i = 0; i < reducedNumRows; i++ )
			src.set( i, timestamps[i], origSrc.get(i) );

		return src;
	}

	/**
	 * Provides a convenient synchronized wrapper around calculateSeries and createExportData.
	 */
	protected synchronized ExportData fetch( int maxRows ) throws RrdException, IOException
	{
		// Calculate the requested reduced data set
		calculateSeries( maxRows );

		return createExportData();
	}

	public RrdExportDef getExportDef() {
		return def;
	}

	public RrdOpener getRrdOpener() {
		return rrdOpener;
	}
}

⌨️ 快捷键说明

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