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

📄 mabstractstatus.java

📁 httptunnel.jar httptunnel java 源码
💻 JAVA
字号:
package net.jumperz.app.MGuardian.console;

import java.io.*;
import net.jumperz.ext.org.jrobin.core.*;
import net.jumperz.ext.org.jrobin.graph.*;
import net.jumperz.util.*;
import java.awt.Color;
import java.awt.Font;

public abstract class MAbstractStatus
{
private static final String DATA_SOURCE_NAME = "ds";

protected static final Color c6		= new Color( 0x80, 0x80, 0x90 );
protected static final Color white	= new Color( 0xFF, 0xFF, 0xFF );
protected static final Color orange	= new Color( 0xFF, 0xCC, 0x66 );
protected static final Color gray	= new Color( 0xDD, 0xDD, 0xDD );
protected static final Color black	= new Color( 0, 0, 0 );
/*
protected static final Color c1 = new Color( 0xC1, 0xD6, 0xE0 );
protected static final Color c2 = new Color( 0x2b, 0x2d, 0x3c );
protected static final Color c3 = new Color( 0x23, 0x25, 0x32 );
protected static final Color c4 = new Color( 0xd1, 0xe1, 0xe9 );
protected static final Color c5 = new Color( 0x50, 0x50, 0x50 );
protected static final Color green = new Color( 0, 0xF0, 0 );
*/

public abstract void update( Object eventName, Object source  );
public abstract String getStatusName();
public abstract String getStatusValue();
public abstract String getTitle();

protected RrdDb rrdDb;
//--------------------------------------------------------------------------------
public final void loadDb( String consoleWorkDirName )
throws IOException
{
File workDir = new File( consoleWorkDirName );
if( !workDir.exists() )
	{
	if( !workDir.mkdirs() )
		{
		throw new IOException( "Could not create directory : " + consoleWorkDirName );
		}
	}
else
	{
	if( !workDir.isDirectory() )
		{
		throw new IOException( consoleWorkDirName + " is not a directory." );
		}
	}

String rrdFileName = workDir.getCanonicalPath() + "/" + getStatusName() + ".rrd";
File rrdFile = new File( rrdFileName );
if( !rrdFile.exists() )
	{
	rrdDb = MRrdUtil.createStandardRrdFile( rrdFileName, DATA_SOURCE_NAME );
	}
else
	{
	if( !rrdFile.isFile() )
		{
		throw new IOException( rrdFileName + " is not a file." );
		}
	try
		{
		rrdDb = new RrdDb( rrdFileName );	
		}
	catch( RrdException e )
		{
		throw new IOException( e.getMessage() );
		}
	}
}
//--------------------------------------------------------------------------------
public void shutdown()
{
try
	{
	rrdDb.close();
	}
catch( IOException e )
	{
	e.printStackTrace();
	}
}
//--------------------------------------------------------------------------------
public final void updateRrd()
throws IOException, RrdException
{
	//update
Sample sample = rrdDb.createSample();
sample.setAndUpdate( "N:" + getStatusValue() );
}
//--------------------------------------------------------------------------------
public final void drawGraph( String rrdFileName, String graphFileNamePrefix )
throws IOException, RrdException
{
drawGraph( rrdFileName, graphFileNamePrefix + "1.png", ( 60 * 60 * 12 ), "last 12 hours" );
drawGraph( rrdFileName, graphFileNamePrefix + "2.png", ( 60 * 60 * 24 * 7 ), "last 7 days" );
drawGraph( rrdFileName, graphFileNamePrefix + "3.png", ( 60 * 60 * 24 * 30 ), "last 30 days" );
}
//--------------------------------------------------------------------------------
protected final void drawGraph( String rrdFileName, String graphFileName, long period, String titleSuffix )
throws IOException, RrdException
{
	//create graph
RrdGraphDef gd = new RrdGraphDef();
long end = System.currentTimeMillis() / 1000;
long start = end - period;
gd.setTimePeriod( start, end );
	
String graphSourceName = getStatusName();
	
gd.datasource( graphSourceName, rrdFileName, DATA_SOURCE_NAME, "AVERAGE" );
gd.area(graphSourceName, getAreaColor(), null );

gd.setTitle( getTitle() + " ( " + titleSuffix + " ) " );
Font verdana = Font.decode( "Verdana-BOLD-11" );
gd.setTitleFont( verdana );
gd.setTitleFontColor( black );
gd.setMinorGridY(true);
gd.setGridY(true);
gd.setDefaultFontColor( black );
gd.setAntiAliasing( false );
gd.setBackColor( gray );
gd.setCanvasColor( white );
gd.setMinorGridColor( gray );
gd.setMajorGridColor( c6 );
gd.setShowSignature(false);
gd.setImageBorder( null, 0 );

RrdGraph rrdGraph = new RrdGraph( gd );
	
		// save to file
if( graphFileName.toLowerCase().indexOf( ".gif" ) > -1 )
	{
	rrdGraph.saveAsGIF( graphFileName );
	}
else
	{
	rrdGraph.saveAsPNG( graphFileName );		
	}	
}
//--------------------------------------------------------------------------------
protected Color getAreaColor()
{
return orange;
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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