Reformat whole codebase using Android Studio

This commit is contained in:
Manuel Fuhr 2022-07-11 06:30:17 +02:00
parent d5322667d5
commit c15913c1ab
161 changed files with 15124 additions and 18537 deletions

View file

@ -3,50 +3,41 @@ package btools.server;
import java.util.HashMap;
import java.util.Map;
public class IpAccessMonitor
{
public class IpAccessMonitor {
private static Object sync = new Object();
private static HashMap<String,Long> ipAccess = new HashMap<String,Long>();
private static HashMap<String, Long> ipAccess = new HashMap<String, Long>();
private static long MAX_IDLE = 900000; // 15 minutes
private static long CLEANUP_INTERVAL = 10000; // 10 seconds
private static long lastCleanup;
public static boolean touchIpAccess( String ip )
{
public static boolean touchIpAccess(String ip) {
long t = System.currentTimeMillis();
synchronized( sync )
{
Long lastTime = ipAccess.get( ip );
ipAccess.put( ip, Long.valueOf( t ) );
synchronized (sync) {
Long lastTime = ipAccess.get(ip);
ipAccess.put(ip, Long.valueOf(t));
return lastTime == null || t - lastTime.longValue() > MAX_IDLE;
}
}
public static int getSessionCount()
{
public static int getSessionCount() {
long t = System.currentTimeMillis();
synchronized( sync )
{
if ( t - lastCleanup > CLEANUP_INTERVAL )
{
cleanup( t );
synchronized (sync) {
if (t - lastCleanup > CLEANUP_INTERVAL) {
cleanup(t);
lastCleanup = t;
}
return ipAccess.size();
}
}
private static void cleanup( long t )
{
HashMap<String,Long> newMap = new HashMap<String,Long>(ipAccess.size());
for( Map.Entry<String,Long> e : ipAccess.entrySet() )
{
if ( t - e.getValue().longValue() <= MAX_IDLE )
{
newMap.put( e.getKey(), e.getValue() );
private static void cleanup(long t) {
HashMap<String, Long> newMap = new HashMap<String, Long>(ipAccess.size());
for (Map.Entry<String, Long> e : ipAccess.entrySet()) {
if (t - e.getValue().longValue() <= MAX_IDLE) {
newMap.put(e.getKey(), e.getValue());
}
}
ipAccess = newMap;
}
}