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

📄 maddressmanager.java

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

import java.util.*;

import net.jumperz.util.MCount;

public final class MAddressManager
{
private static MAddressManager instance	= new MAddressManager();
private static final int INIT_MAP_SIZE	= 200;
private static final int INIT_MAX_COUNT	= 30;

private int maxCount			= INIT_MAX_COUNT;

private Map addressCountMap;
private Set allowedAddressSet;
//---------------------------------------------------------------------------------------
private MAddressManager()
{
	// Singleton
addressCountMap = new HashMap( INIT_MAP_SIZE );
}
//---------------------------------------------------------------------------------------
public static MAddressManager getInstance()
{
return instance;
}
//---------------------------------------------------------------------------------------
public void setMaxCount( int in_maxCount )
{
maxCount = in_maxCount;
}
//---------------------------------------------------------------------------------------
public synchronized boolean isFull( String address )
{
	// if address is allowed, always return false
if( allowedAddressSet.contains( address ) )
	{
	return false;
	}

if( addressCountMap.containsKey( address ) )
	{
	MCount count = ( MCount )addressCountMap.get( address );
	if( count.getValue() == maxCount )
		{
		return true;
		}
	else
		{
		return false;
		}
	}
else
	{
	return false;
	}
}
//---------------------------------------------------------------------------------------
public synchronized void add( String address )
{
if( addressCountMap.containsKey( address ) )
	{
	MCount count = ( MCount )addressCountMap.get( address );
	count.inc();
	}
else
	{
	addressCountMap.put( address, new MCount() );
	}
}
//---------------------------------------------------------------------------------------
public synchronized void remove( String address )
{
if( !addressCountMap.containsKey( address ) )
	{
	Exception e = new Exception( "Should not happen. address not found." );
	e.printStackTrace();
	return;
	}

MCount count = ( MCount )addressCountMap.get( address );
count.dec();
if( count.getValue() == 0 )
	{
	addressCountMap.remove( address );
	}
}
//---------------------------------------------------------------------------------------
public synchronized void setAllowedAddress( Set in_allowedAddressSet )
{
allowedAddressSet = in_allowedAddressSet;
}
//---------------------------------------------------------------------------------------
public void print()
{
System.out.println( addressCountMap );
}
//---------------------------------------------------------------------------------------
}

⌨️ 快捷键说明

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