mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Prevent reading and writing the usermap at the same time.
This commit is contained in:
parent
ed9e4ecd28
commit
8e7abe325e
2 changed files with 46 additions and 32 deletions
|
@ -45,45 +45,56 @@ public class UUIDMap
|
||||||
userList.createNewFile();
|
userList.createNewFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
final BufferedReader reader = new BufferedReader(new FileReader(userList));
|
synchronized (pendingDiskWrites)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
while (true)
|
if (ess.getSettings().isDebug())
|
||||||
{
|
{
|
||||||
final String line = reader.readLine();
|
ess.getLogger().log(Level.INFO, "Reading usermap from disk");
|
||||||
if (line == null)
|
}
|
||||||
|
|
||||||
|
names.clear();
|
||||||
|
history.clear();
|
||||||
|
|
||||||
|
final BufferedReader reader = new BufferedReader(new FileReader(userList));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
break;
|
final String line = reader.readLine();
|
||||||
}
|
if (line == null)
|
||||||
else
|
|
||||||
{
|
|
||||||
final String[] values = splitPattern.split(line);
|
|
||||||
if (values.length == 2)
|
|
||||||
{
|
{
|
||||||
final String name = values[0];
|
break;
|
||||||
final UUID uuid = UUID.fromString(values[1]);
|
}
|
||||||
names.put(name, uuid);
|
else
|
||||||
if (!history.containsKey(uuid))
|
{
|
||||||
|
final String[] values = splitPattern.split(line);
|
||||||
|
if (values.length == 2)
|
||||||
{
|
{
|
||||||
final ArrayList<String> list = new ArrayList<String>();
|
final String name = values[0];
|
||||||
list.add(name);
|
final UUID uuid = UUID.fromString(values[1]);
|
||||||
history.put(uuid, list);
|
names.put(name, uuid);
|
||||||
}
|
if (!history.containsKey(uuid))
|
||||||
else
|
|
||||||
{
|
|
||||||
final ArrayList<String> list = history.get(uuid);
|
|
||||||
if (!list.contains(name))
|
|
||||||
{
|
{
|
||||||
|
final ArrayList<String> list = new ArrayList<String>();
|
||||||
list.add(name);
|
list.add(name);
|
||||||
|
history.put(uuid, list);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final ArrayList<String> list = history.get(uuid);
|
||||||
|
if (!list.contains(name))
|
||||||
|
{
|
||||||
|
list.add(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
finally
|
||||||
finally
|
{
|
||||||
{
|
reader.close();
|
||||||
reader.close();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
|
@ -99,6 +110,10 @@ public class UUIDMap
|
||||||
|
|
||||||
public void forceWriteUUIDMap()
|
public void forceWriteUUIDMap()
|
||||||
{
|
{
|
||||||
|
if (ess.getSettings().isDebug())
|
||||||
|
{
|
||||||
|
ess.getLogger().log(Level.INFO, "Forcing usermap write to disk");
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Future<?> future = _writeUUIDMap();;
|
Future<?> future = _writeUUIDMap();;
|
||||||
|
@ -119,7 +134,7 @@ public class UUIDMap
|
||||||
|
|
||||||
public Future<?> _writeUUIDMap()
|
public Future<?> _writeUUIDMap()
|
||||||
{
|
{
|
||||||
final ConcurrentSkipListMap<String, UUID> names = ess.getUserMap().getNames().clone();
|
final ConcurrentSkipListMap<String, UUID> names = ess.getUserMap().getNames();
|
||||||
if (names.size() < 1)
|
if (names.size() < 1)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
keys.clear();
|
keys.clear();
|
||||||
names.clear();
|
|
||||||
users.invalidateAll();
|
users.invalidateAll();
|
||||||
for (String string : userdir.list())
|
for (String string : userdir.list())
|
||||||
{
|
{
|
||||||
|
@ -200,7 +199,7 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
|
|
||||||
public Set<UUID> getAllUniqueUsers()
|
public Set<UUID> getAllUniqueUsers()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableSet(keys);
|
return Collections.unmodifiableSet(keys.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUniqueUsers()
|
public int getUniqueUsers()
|
||||||
|
@ -208,12 +207,12 @@ public class UserMap extends CacheLoader<UUID, User> implements IConf
|
||||||
return keys.size();
|
return keys.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentSkipListMap<String, UUID> getNames()
|
protected ConcurrentSkipListMap<String, UUID> getNames()
|
||||||
{
|
{
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
|
protected ConcurrentSkipListMap<UUID, ArrayList<String>> getHistory()
|
||||||
{
|
{
|
||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue