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

📄 mguardianconsole.java

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

import net.jumperz.app.MGuardian.*;
import net.jumperz.util.*;
import java.util.*;
import java.io.*;
import java.net.*;

public final class MGuardianConsole
implements MObserver2, MObserver1, MCommand
{
private static final int INTERVAL = 300; // 5 minute
private static final MGuardianConsole instance = new MGuardianConsole();
private static final String[] webFileNameList = new String[]{
"logo.gif",
"index.html",
"v2.html",
"v3.html",
"v4.html",
"0.html",
"1.html",
"2.html",
"3.html",
"4.html",
"5.html",
"6.html",
"7.html",
"8.html",
"9.html",
"10.html",
"11.html",
"12.html",
"13.html",
};
private static final String resourceBase = "net/jumperz/app/MGuardian/console/resource";

private String consoleWorkDirName;
private String consoleWebDirName;
private List statusList = new ArrayList();
private MThreadPool threadPool;
private int time = 0;
//--------------------------------------------------------------------------------
public static MGuardianConsole getInstance()
{
return instance;
}
//--------------------------------------------------------------------------------
private MGuardianConsole()
{
statusList.add( new MTotalAccessStatus() );
statusList.add( new MMemoryStatus() );
statusList.add( new MGetStatus() );
statusList.add( new MPostStatus() );
statusList.add( new MOtherMethodStatus() );
statusList.add( new MAlertStatus() );
statusList.add( new MRunningThreadStatus() );
statusList.add( new MUniqueIpStatus() );
statusList.add( new MMaxAccessStatus() );
statusList.add( new M10XStatus() );
statusList.add( new M20XStatus() );
statusList.add( new M30XStatus() );
statusList.add( new M4XXStatus() );
statusList.add( new M50XStatus() );
threadPool = MGuardianImpl.getInstance().getThreadPool();
}
//--------------------------------------------------------------------------------
public void update()
{
time++;
if( time == INTERVAL )
	{
	time = 0;
	threadPool.addCommand( this );
	}
}
//--------------------------------------------------------------------------------
public void update( Object eventName, Object source )
{
int count = statusList.size();
for( int i = 0; i < count; ++i )
	{
	MAbstractStatus status = ( MAbstractStatus )statusList.get( i );
	status.update( eventName, source );
	}
}
//--------------------------------------------------------------------------------
public void setConsoleWorkDirName( String s )
throws IOException
{
consoleWorkDirName =  MSystemUtil.createDir( s );
}
//--------------------------------------------------------------------------------
public void setConsoleWebDirName( String s )
throws IOException
{
consoleWebDirName = MSystemUtil.createDir( s );
}
//--------------------------------------------------------------------------------
public void init()
throws IOException
{
loadDb();
createWebFiles();
}
//--------------------------------------------------------------------------------
private void createWebFiles()
throws IOException
{
for( int i = 0; i < webFileNameList.length; ++i )
	{
	FileInputStream fin	= null;
	FileOutputStream fos	= null;
	InputStream bin	= null;
	try
		{
		boolean needUpdate = false;
	
		String htmlFileName = webFileNameList[ i ];
		File htmlFile = new File( consoleWebDirName + "/" + htmlFileName );
	
		ClassLoader classLoader = MGuardianConsole.class.getClassLoader();
		URL url = classLoader.getResource( resourceBase + "/" + htmlFileName );
		bin = url.openStream();
		
		if( !htmlFile.exists() )
			{
			needUpdate = true;
			}
		else
			{
			fin = new FileInputStream( htmlFile );
			int fileSize = fin.available();
			int resourceSize = bin.available();
			
			if( fileSize != resourceSize )
				{
				needUpdate = true;
				}
			}
		if( needUpdate )
			{
			fos = new FileOutputStream( htmlFile );
			MStreamUtil.connectStream( bin, fos );		
			}
		}
	finally
		{
		MStreamUtil.closeStream( fin );
		MStreamUtil.closeStream( fos );
		MStreamUtil.closeStream( bin );
		}
	}
}
//--------------------------------------------------------------------------------
private void loadDb()
throws IOException
{
int count = statusList.size();
for( int i = 0; i < count; ++i )
	{
	MAbstractStatus status = ( MAbstractStatus )statusList.get( i );
	status.loadDb( consoleWorkDirName );
	}	
}
//--------------------------------------------------------------------------------
public void shutdown()
{
int count = statusList.size();
for( int i = 0; i < count; ++i )
	{
	MAbstractStatus status = ( MAbstractStatus )statusList.get( i );
	status.shutdown();
	}	
}
//--------------------------------------------------------------------------------
public void execute()
{
try
	{
	int count = statusList.size();
	for( int i = 0; i < count; ++i )
		{
		MAbstractStatus status = ( MAbstractStatus )statusList.get( i );
		status.updateRrd();
		status.drawGraph
			(
			consoleWorkDirName + "/" + status.getStatusName() + ".rrd",
			consoleWebDirName + "/" + status.getStatusName()
			);
		}
	}
catch( Exception e )
	{
	e.printStackTrace();
	}
}
//--------------------------------------------------------------------------------
public void breakCommand()
{
}
//--------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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