From ff0f2891a296064c893f13bcc8c8059ef5048904 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Tue, 14 Jan 2020 23:22:03 +0100 Subject: [PATCH] suspect-manager: multiple challenges --- .../java/btools/server/SuspectManager.java | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 0cadfac..1055350 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -7,6 +7,7 @@ import java.io.FileReader; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.StringTokenizer; import java.util.TreeSet; @@ -57,10 +58,9 @@ public class SuspectManager extends Thread } - private static void markFalsePositive( long id ) throws IOException + private static void markFalsePositive( SuspectList suspects, long id ) throws IOException { new File( "falsepositives/" + id ).createNewFile(); - SuspectList suspects = getAllSuspects( new File( "worldsuspects.txt" ) ); for( int isuspect = 0; isuspectnew "; String linkCnf = " confirmed "; String linkAll = " all "; @@ -272,7 +284,6 @@ public class SuspectManager extends Thread bw.flush(); return; } - SuspectList suspects = getAllSuspects( suspectFile ); boolean showWatchList = false; if ( tk.hasMoreTokens() ) @@ -291,7 +302,7 @@ public class SuspectManager extends Thread if ( showWatchList ) { bw.write( "watchlist for " + country + "\n" ); - bw.write( "
back to country list

\n" ); + bw.write( "
back to country list

\n" ); long timeNow = System.currentTimeMillis(); @@ -331,7 +342,7 @@ public class SuspectManager extends Thread continue; // not in selected polygon } - String countryId = country + "/" + filter + "/" + id; + String countryId = challenge + country + "/" + filter + "/" + id; String dueTime = hideTime < 0 ? "(asap)" : formatAge( hideTime + 43200000 ); String hint = "   due in " + dueTime; int ilon = (int) ( id >> 32 ); @@ -359,7 +370,7 @@ public class SuspectManager extends Thread } else { - markFalsePositive( id ); + markFalsePositive( suspects, id ); message = "Marked issue " + id + " as false-positive"; id = 0L; } @@ -401,7 +412,7 @@ public class SuspectManager extends Thread } if ( id != 0L ) { - String countryId = country + "/" + filter + "/" + id; + String countryId = challenge + country + "/" + filter + "/" + id; int ilon = (int) ( id >> 32 ); int ilat = (int) ( id & 0xffffffff ); @@ -451,7 +462,7 @@ public class SuspectManager extends Thread bw.write( "
\n" ); if ( isFixed( id, suspects.timestamp ) ) { - bw.write( "

back to watchlist

\n" ); + bw.write( "

back to watchlist

\n" ); } else { @@ -480,7 +491,7 @@ public class SuspectManager extends Thread } if ( polygon != null ) { - bw.write( "

back to issue list

\n" ); + bw.write( "

back to issue list

\n" ); } } } @@ -491,7 +502,7 @@ public class SuspectManager extends Thread else { bw.write( filter + " suspect list for " + country + "\n" ); - bw.write( "
see watchlist\n" ); + bw.write( "
see watchlist\n" ); bw.write( "
back to country list

\n" ); int maxprio = 0; { @@ -537,7 +548,7 @@ public class SuspectManager extends Thread maxprio = nprio; bw.write( "current level: " + getLevelDecsription( maxprio ) + "

\n" ); } - String countryId = country + "/" + filter + "/" + id; + String countryId = challenge + country + "/" + filter + "/" + id; File confirmedEntry = new File( "confirmednegatives/" + id ); String hint = ""; if ( confirmedEntry.exists() ) @@ -586,13 +597,14 @@ public class SuspectManager extends Thread } } - private static SuspectList allSuspects; - private static Object allSuspectsSync = new Object(); + private static HashMap allSuspectsMap = new HashMap(); - private static SuspectList getAllSuspects( File suspectFile ) throws IOException + private static SuspectList getAllSuspects( String suspectFileName ) throws IOException { - synchronized( allSuspectsSync ) + synchronized( allSuspectsMap ) { + SuspectList allSuspects = allSuspectsMap.get( suspectFileName ); + File suspectFile = new File( suspectFileName ); if ( allSuspects != null && suspectFile.lastModified() == allSuspects.timestamp ) { return allSuspects; @@ -643,6 +655,7 @@ public class SuspectManager extends Thread allSuspects.falsePositive[pointer] = new File( "falsepositives/" + id ).exists(); } r.close(); + allSuspectsMap.put( suspectFileName, allSuspects ); return allSuspects; } }