summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2014-05-17 01:50:41 +0100
committerKHobbits <rob@khobbits.co.uk>2014-05-17 01:50:41 +0100
commit7a2414a43eaca3b294c78cfe9a799bbbd232e8e1 (patch)
treed73a3fd635e310be329f84972d4304ac0328f147
parent868088e2b2d00402a6c05334ed780e9b97b14fe5 (diff)
downloadEssentials-7a2414a43eaca3b294c78cfe9a799bbbd232e8e1.tar
Essentials-7a2414a43eaca3b294c78cfe9a799bbbd232e8e1.tar.gz
Essentials-7a2414a43eaca3b294c78cfe9a799bbbd232e8e1.tar.lz
Essentials-7a2414a43eaca3b294c78cfe9a799bbbd232e8e1.tar.xz
Essentials-7a2414a43eaca3b294c78cfe9a799bbbd232e8e1.zip
Prevent reading and writing the usermap at the same time.
-rw-r--r--Essentials/src/com/earth2me/essentials/UUIDMap.java71
-rw-r--r--Essentials/src/com/earth2me/essentials/UserMap.java7
2 files changed, 46 insertions, 32 deletions
diff --git a/Essentials/src/com/earth2me/essentials/UUIDMap.java b/Essentials/src/com/earth2me/essentials/UUIDMap.java
index f42ea48f4..e77a9149d 100644
--- a/Essentials/src/com/earth2me/essentials/UUIDMap.java
+++ b/Essentials/src/com/earth2me/essentials/UUIDMap.java
@@ -45,45 +45,56 @@ public class UUIDMap
userList.createNewFile();
}
- final BufferedReader reader = new BufferedReader(new FileReader(userList));
- try
+ synchronized (pendingDiskWrites)
{
- while (true)
+ if (ess.getSettings().isDebug())
{
- final String line = reader.readLine();
- if (line == null)
- {
- break;
- }
- else
+ ess.getLogger().log(Level.INFO, "Reading usermap from disk");
+ }
+
+ names.clear();
+ history.clear();
+
+ final BufferedReader reader = new BufferedReader(new FileReader(userList));
+ try
+ {
+ while (true)
{
- final String[] values = splitPattern.split(line);
- if (values.length == 2)
+ final String line = reader.readLine();
+ if (line == null)
{
- final String name = values[0];
- final UUID uuid = UUID.fromString(values[1]);
- names.put(name, uuid);
- if (!history.containsKey(uuid))
- {
- final ArrayList<String> list = new ArrayList<String>();
- list.add(name);
- history.put(uuid, list);
- }
- else
+ break;
+ }
+ else
+ {
+ final String[] values = splitPattern.split(line);
+ if (values.length == 2)
{
- final ArrayList<String> list = history.get(uuid);
- if (!list.contains(name))
+ final String name = values[0];
+ final UUID uuid = UUID.fromString(values[1]);
+ names.put(name, uuid);
+ if (!history.containsKey(uuid))
{
+ final ArrayList<String> list = new ArrayList<String>();
list.add(name);
+ history.put(uuid, list);
+ }
+ else
+ {
+ final ArrayList<String> list = history.get(uuid);
+ if (!list.contains(name))
+ {
+ list.add(name);
+ }
}
}
}
}
}
- }
- finally
- {
- reader.close();
+ finally
+ {
+ reader.close();
+ }
}
}
catch (IOException ex)
@@ -99,6 +110,10 @@ public class UUIDMap
public void forceWriteUUIDMap()
{
+ if (ess.getSettings().isDebug())
+ {
+ ess.getLogger().log(Level.INFO, "Forcing usermap write to disk");
+ }
try
{
Future<?> future = _writeUUIDMap();;
@@ -119,7 +134,7 @@ public class UUIDMap
public Future<?> _writeUUIDMap()
{
- final ConcurrentSkipListMap<String, UUID> names = ess.getUserMap().getNames().clone();
+ final ConcurrentSkipListMap<String, UUID> names = ess.getUserMap().getNames();
if (names.size() < 1)
{
return null;
diff --git a/Essentials/src/com/earth2me/essentials/UserMap.java b/Essentials/src/com/earth2me/essentials/UserMap.java
index 1e6b54c9b..50bbb8ff9 100644
--- a/Essentials/src/com/earth2me/essentials/UserMap.java
+++ b/Essentials/src/com/earth2me/essentials/UserMap.java
@@ -51,7 +51,6 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
return;
}
keys.clear();
- names.clear();
users.invalidateAll();
for (String string : userdir.list())
{
@@ -200,7 +199,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
public Set<UUID> getAllUniqueUsers()
{
- return Collections.unmodifiableSet(keys);
+ return Collections.unmodifiableSet(keys.clone());
}
public int getUniqueUsers()
@@ -208,12 +207,12 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
return keys.size();
}
- public ConcurrentSkipListMap<String, UUID> getNames()
+ protected ConcurrentSkipListMap<String, UUID> getNames()
{
return names;
}
- public ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
+ protected ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
{
return history;
}