Commit 8122ae89 by fukai

删除误提交的文件

parent 13addc6b
package org.sss.presentation.noui.jwt;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class VisitCounter{
private int timeSpan;
private int count;
private Map<String,VisitCounterItem> couterMap = new ConcurrentHashMap<>();
public VisitCounter(int timeSpan,int count){
this.timeSpan = timeSpan;
this.count = count;
}
public boolean addCount(String token)
{
VisitCounterItem item = null;
synchronized (couterMap)
{
item = couterMap.get(token);
if(item == null)
{
item = new VisitCounterItem(timeSpan,count);
couterMap.put(token,item);
}
}
return item.addCount();
}
public void removeCount(String token)
{
}
public static class VisitCounterItem {
private int timeSpan;
private int count;
private long timestamp;
private int visited;
public VisitCounterItem(int timeSpan, int count) {
this.timeSpan = timeSpan * 1000;
this.count = count;
this.timestamp = new Date().getTime();
}
public synchronized boolean addCount() {
long time = new Date().getTime();
if (time - this.timestamp > timeSpan) {
resetCount();
this.visited++;
return true;
} else {
this.visited++;
if (this.visited > count) //超过单位时间内访问次数
{
return false;
} else
return true;
}
}
private void resetCount() {
this.timestamp = new Date().getTime();
this.visited = 0;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment