Prevent reading and writing the usermap at the same time.

This commit is contained in:
KHobbits 2014-05-17 01:50:41 +01:00
parent ed9e4ecd28
commit 8e7abe325e
2 changed files with 46 additions and 32 deletions

View file

@ -45,6 +45,16 @@ public class UUIDMap
userList.createNewFile();
}
synchronized (pendingDiskWrites)
{
if (ess.getSettings().isDebug())
{
ess.getLogger().log(Level.INFO, "Reading usermap from disk");
}
names.clear();
history.clear();
final BufferedReader reader = new BufferedReader(new FileReader(userList));
try
{
@ -86,6 +96,7 @@ public class UUIDMap
reader.close();
}
}
}
catch (IOException ex)
{
Bukkit.getLogger().log(Level.SEVERE, ex.getMessage(), 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;

View file

@ -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;
}