亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? floodcontrol.java

?? 解觖java技術中后臺無法上傳數給的情況
?? JAVA
字號:
/*
 * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/security/FloodControl.java,v 1.12 2006/04/15 02:59:19 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.12 $
 * $Date: 2006/04/15 02:59:19 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * All copyright notices regarding MyVietnam and MyVietnam CoreLib
 * MUST remain intact in the scripts and source code.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Correspondence and Marketing Questions can be sent to:
 * info at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package net.myvietnam.mvncore.security;

import java.util.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.myvietnam.mvncore.exception.FloodException;
import net.myvietnam.mvncore.util.DateUtil;

/**
 * This class is used to control the number of actions per hour. This is usually
 * used to prevent the flood of any action. You should call FloodControl.setOption()
 * when your application is inited.
 * <p>
 * Note that the action id from 0 to 999 is belong to mvnCore, application used it
 * should not use the value in this range
 */
public class FloodControl {

    private static Log log = LogFactory.getLog(FloodControl.class);

    /** The value from 0 to 999 should belong to mvnCore */
    public static int MAX_MVNCORE_ACTION_ID = 999;

    private static Map actionControlMap = new TreeMap();

    static final long REMOVE_INTERVAL = DateUtil.MINUTE * 2;//2 minutes

    private FloodControl() {
    }

    /**
     * To set the mamximum number of actions per hour for an action.
     * If the caller does not call this method, the the action has no limit
     * @param action Integer the action that want to set the option
     * @param actionsPerHour int the maximum number of actions per hour
     */
    public static void setOption(Integer action, int actionsPerHour) {
        getControlledAction(action).setActionsPerHour(actionsPerHour);
    }

    public static int getActionsPerHour(Integer action) {
        return getControlledAction(action).getActionsPerHour();
    }

    /**
     * Check that an action of an IP has reach the maximum number of allowed times
     * @param action Integer the action to check
     * @param strIP String the IP to check
     * @return boolean true if it has reached the maximum
     */
    public static boolean reachMaximum(Integer action, String strIP) {
        return getControlledAction(action).reachMaximum(strIP);
    }

    /**
     * This is a utility method to ensure that the action has not reached the mamximum.
     * It calls the method reachMaximum and throw an exception if it reached the maximum.
     * A program could use this method to use the default error message, otherwise
     * it has to use reachMaximum
     * @param action Integer the action to ensure
     * @param strIP String the IP to ensure
     * @throws FloodException if it reached the maximum
     * @see FloodControl#reachMaximum(Integer, String)
     */
    public static void ensureNotReachMaximum(Integer action, String strIP) throws FloodException {
        if (reachMaximum(action, strIP)) {
            log.info("Attempt to exceed the maximum number of actions: ActionID = " + action + " and IP = " + strIP);
            //@todo : localize me
            throw new FloodException("You have reached the maximum number of actions for this page (actionID = " + action + "). Please try this page later. This is to prevent forum from being flooded.");
        }
    }

    /**
     * Increase the number of action. This method should be called the the program
     * has done this action. Forget to call this method will void the reachMaximum method.
     * @param action Integer the action to increase the number of times
     * @param strIP String the IP to increase the number of times
     */
    public static void increaseCount(Integer action, String strIP) {
        getControlledAction(action).increaseCount(strIP);
    }

    /**
     * Reset the action history. This method is useful in such a case in the login
     * process that after login successfully, the value should be reset. Please note
     * that this is just an example and usually no need to use this method.
     * @param action Integer
     * @param strIP String
     */
    public static void resetActionHistory(Integer action, String strIP) {
        getControlledAction(action).resetActionHistory(strIP);
    }

    /**
     * Return the instance of ControlledAction for the action. It will create
     * new instance if no previous instance for this action exist.
     * @param action Integer
     * @return ControlledAction
     */
    private static synchronized ControlledAction getControlledAction(Integer action) {
        ControlledAction controlledAction = (ControlledAction)actionControlMap.get(action);
        if (controlledAction == null) {
            controlledAction = new ControlledAction();
            actionControlMap.put(action, controlledAction);
        }
        return controlledAction;
    }
}

/**
 * For one action that handles a list of all IP
 */
class ControlledAction {
    private int actionsPerHour = 0;
    private Map ipMap = new TreeMap();
    private long lastRemoveTime = 0;

    void setActionsPerHour(int actionsPerHour) {
        if (actionsPerHour >= 0) {
            this.actionsPerHour = actionsPerHour;
        }
    }

    int getActionsPerHour() {
        return actionsPerHour;
    }

    boolean reachMaximum(String strIP) {
        removeTimeoutControlledIP();
        return getControlledIP(strIP).reachMaximum();
    }

    void increaseCount(String strIP) {
        removeTimeoutControlledIP();
        getControlledIP(strIP).increaseCount();
    }

    void resetActionHistory(String strIP) {
        removeTimeoutControlledIP();
        getControlledIP(strIP).resetActionHistory();
    }

    private synchronized ControlledIP getControlledIP(String strIP) {
        ControlledIP controlledIP = (ControlledIP)ipMap.get(strIP);
        if (controlledIP == null) {
            controlledIP = new ControlledIP(actionsPerHour);
            ipMap.put(strIP, controlledIP);
        } else {
            // there is a ControlledIP, update the actionsPerHour
            controlledIP.setActionsPerHour(actionsPerHour);
        }
        return controlledIP;
    }

    private synchronized void removeTimeoutControlledIP() {
        long now = System.currentTimeMillis();
        if ((now - lastRemoveTime) > FloodControl.REMOVE_INTERVAL) {
            lastRemoveTime = now;
            Collection ipList = ipMap.values();
            for (Iterator iter = ipList.iterator(); iter.hasNext(); ) {
                ControlledIP currentControlledIP = (ControlledIP)iter.next();
                if (now - currentControlledIP.getLastIncrementTime() > DateUtil.HOUR) {
                    iter.remove();
                }
            }
        }
    }
}

/**
 * For one action per one IP
 */
class ControlledIP {
    private int actionsPerHour = 0;
    private long lastRemoveTime = 0;
    private long lastIncrementTime = 0;
    private ArrayList actionHistoryList = new ArrayList();

    ControlledIP(int actionsPerHour) {
        if (actionsPerHour >= 0) {
            this.actionsPerHour = actionsPerHour;
        }
    }

    void setActionsPerHour(int actionsPerHour) {
        if (actionsPerHour >= 0) {
            this.actionsPerHour = actionsPerHour;
        }
    }

    long getLastIncrementTime() {
        return lastIncrementTime;
    }

    void increaseCount() {
        long now = System.currentTimeMillis();
        lastIncrementTime = now;
        actionHistoryList.add(new Long(now));
    }

    void resetActionHistory() {
        lastRemoveTime = 0;
        lastIncrementTime = 0;
        actionHistoryList.clear();
    }

    boolean reachMaximum() {
        if (actionsPerHour == 0) {//unlimited
            return false;
        }

        if (actionHistoryList.size() < actionsPerHour) {
            return false;
        }

        // now try to remove timeout actions
        removeTimeoutActions();

        return (actionHistoryList.size() >= actionsPerHour);
    }

    private synchronized void removeTimeoutActions() {
        long now = System.currentTimeMillis();
        if (now - lastRemoveTime > FloodControl.REMOVE_INTERVAL) {
            lastRemoveTime = now;
            for (Iterator iter = actionHistoryList.iterator(); iter.hasNext(); ) {
                Long currentAction = (Long)iter.next();
                if ((now - currentAction.longValue()) > DateUtil.HOUR) {
                    iter.remove();
                }
            } //for
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99国产精品国产精品毛片| 欧美疯狂性受xxxxx喷水图片| 色综合久久天天综合网| 欧美一级欧美三级| 亚洲欧美日韩在线不卡| 六月婷婷色综合| 91美女精品福利| 国产精品天美传媒沈樵| 五月婷婷另类国产| 91浏览器在线视频| 久久久99精品免费观看不卡| 日韩精品电影在线| 亚洲人成小说网站色在线| 亚洲欧洲av在线| 美洲天堂一区二卡三卡四卡视频 | 国产一区二区剧情av在线| 在线国产电影不卡| 国产精品传媒视频| 国产.欧美.日韩| 精品免费国产二区三区 | 国产91在线看| 欧美不卡一区二区三区四区| 香蕉成人啪国产精品视频综合网| 91亚洲精华国产精华精华液| 国产精品网站在线观看| 国产精品资源在线观看| 久久免费精品国产久精品久久久久| 毛片基地黄久久久久久天堂| 欧美精选午夜久久久乱码6080| 亚洲自拍偷拍综合| 欧美性欧美巨大黑白大战| 亚洲啪啪综合av一区二区三区| 国产成人三级在线观看| 国产三级一区二区| 国产成人亚洲精品青草天美| 国产三级三级三级精品8ⅰ区| 精彩视频一区二区| 久久综合色播五月| 国产成人精品免费看| 国产欧美日本一区二区三区| 成人黄色国产精品网站大全在线免费观看| 欧美电视剧免费全集观看| 久久精品99久久久| 久久亚洲综合av| 不卡视频在线观看| 一区二区三区成人| 欧美日韩一区二区三区不卡| 日韩精品一卡二卡三卡四卡无卡| 欧美色成人综合| 老司机免费视频一区二区| 久久天堂av综合合色蜜桃网| 成人伦理片在线| 亚洲一区二区三区影院| 欧美一级片在线观看| 国产精品一区在线观看你懂的| 国产亚洲精品超碰| 91视频免费播放| 午夜精品一区在线观看| 精品国产sm最大网站| 春色校园综合激情亚洲| 亚洲女性喷水在线观看一区| 在线观看91av| 国产一区二区免费在线| ...中文天堂在线一区| 欧美三区在线视频| 国产成人超碰人人澡人人澡| 亚洲人成网站精品片在线观看| 欧美肥妇毛茸茸| 成人综合在线视频| 视频在线观看一区二区三区| 久久久久国产精品免费免费搜索| 91免费看视频| 国产在线播精品第三| 亚洲免费观看高清完整版在线 | 色天天综合久久久久综合片| 丝袜亚洲精品中文字幕一区| 国产午夜精品一区二区三区四区| 在线亚洲+欧美+日本专区| 国产一区福利在线| 午夜国产精品一区| 国产精品久久毛片a| 日韩一级免费一区| 一本色道久久综合亚洲精品按摩| 麻豆精品在线看| 亚洲一区免费观看| 欧美激情综合网| 精品国产一区二区三区久久久蜜月| 一本久久综合亚洲鲁鲁五月天 | 色婷婷综合中文久久一本| 久久精品国产一区二区三| 亚洲狠狠丁香婷婷综合久久久| 久久综合九色综合97_久久久| 欧美日韩三级一区二区| 91亚洲国产成人精品一区二三| 国模一区二区三区白浆| 天堂影院一区二区| 亚洲国产综合在线| 亚洲女人****多毛耸耸8| 久久久久久久久久久久电影| 欧美精品亚洲二区| 欧美亚洲一区二区在线观看| 国产精品亚洲一区二区三区在线 | 日韩精品一区二区三区在线观看| 91网站黄www| 粉嫩欧美一区二区三区高清影视| 老司机精品视频一区二区三区| 性做久久久久久免费观看| 一区二区三区在线视频播放| 国产精品久久久久9999吃药| 久久视频一区二区| 精品国产伦一区二区三区观看方式 | 亚洲一区二区在线观看视频 | 国产精品色在线观看| 久久综合狠狠综合久久激情| 欧美一级欧美三级在线观看 | 国产精品久久久久久久蜜臀| 久久日韩粉嫩一区二区三区| 久久久久久麻豆| 久久麻豆一区二区| 欧美激情艳妇裸体舞| 国产精品私房写真福利视频| 国产精品国产自产拍高清av| 国产精品久久久久一区二区三区 | 亚洲欧洲国产日本综合| 亚洲伦理在线精品| 亚洲最大色网站| 亚洲va国产天堂va久久en| 日韩国产欧美在线播放| 久久精品国产亚洲一区二区三区 | 在线观看区一区二| 欧美日韩国产高清一区| 欧美人体做爰大胆视频| 91精品国产91久久久久久一区二区| 91精品国产综合久久久蜜臀图片| 欧美电影免费提供在线观看| 欧美激情一区二区三区全黄| 亚洲乱码国产乱码精品精98午夜| 亚洲一区二区视频| 极品美女销魂一区二区三区| 国产高清在线观看免费不卡| 91在线国内视频| 欧美人体做爰大胆视频| 久久精品夜色噜噜亚洲a∨| 亚洲欧美偷拍卡通变态| 午夜免费欧美电影| 久久99精品久久久久久久久久久久| 国产精品影音先锋| 不卡的电影网站| 欧美视频一区二区三区在线观看| 91精品国产综合久久精品app | 一区二区三区在线不卡| 日本怡春院一区二区| 粉嫩高潮美女一区二区三区| 在线看国产一区二区| 欧美精品一区二区高清在线观看| 亚洲欧洲在线观看av| 日韩电影在线观看网站| 成人美女视频在线看| 91精品婷婷国产综合久久性色| 国产日产精品1区| 日韩精品一区第一页| av不卡一区二区三区| 日韩欧美久久久| 亚洲精品ww久久久久久p站| 国内精品自线一区二区三区视频| 色呦呦日韩精品| 久久亚洲精精品中文字幕早川悠里 | 激情综合色综合久久| 91成人在线精品| 国产午夜精品久久| 天堂蜜桃91精品| 色又黄又爽网站www久久| 亚洲国产精品t66y| 蜜臀av国产精品久久久久| 91黄色激情网站| 亚洲欧洲性图库| 国产精品自在欧美一区| 在线成人免费视频| 一区二区三区资源| kk眼镜猥琐国模调教系列一区二区| 欧美久久一区二区| 亚洲制服丝袜av| 不卡av在线网| 国产日产精品1区| 国产真实乱对白精彩久久| 欧美偷拍一区二区| 亚洲人成网站在线| 97se亚洲国产综合自在线| 欧美精彩视频一区二区三区| 极品美女销魂一区二区三区免费| 91精品黄色片免费大全| 亚洲高清一区二区三区| 91福利视频久久久久| 亚洲精品高清在线观看| 色噜噜狠狠色综合欧洲selulu| 日本一区二区成人在线| 国产98色在线|日韩| 国产精品久久久久久久久久久免费看 | 午夜精品久久久久久久久久久| 99久久精品免费看国产|