forked from External/mage
other: fixed rare errors on images download opening, fixed wrong code in chats and preferences store;
This commit is contained in:
parent
3d6a2817ae
commit
e386210b91
4 changed files with 31 additions and 9 deletions
|
|
@ -32,6 +32,9 @@ import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import java.util.prefs.BackingStoreException;
|
import java.util.prefs.BackingStoreException;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -327,6 +330,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
// auto-update settings on first run
|
// auto-update settings on first run
|
||||||
public static final String KEY_SETTINGS_VERSION = "settingsVersion";
|
public static final String KEY_SETTINGS_VERSION = "settingsVersion";
|
||||||
|
|
||||||
|
private static final ReadWriteLock cacheLock = new ReentrantReadWriteLock();
|
||||||
private static final Map<String, String> CACHE = new HashMap<>();
|
private static final Map<String, String> CACHE = new HashMap<>();
|
||||||
|
|
||||||
public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab";
|
public static final String OPEN_CONNECTION_TAB = "Open-Connection-Tab";
|
||||||
|
|
@ -3804,15 +3808,27 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCachedValue(String key, String def) {
|
public static String getCachedValue(String key, String def) {
|
||||||
if (CACHE.containsKey(key)) {
|
final Lock r = cacheLock.readLock();
|
||||||
return CACHE.get(key);
|
r.lock();
|
||||||
} else {
|
try {
|
||||||
|
if (CACHE.containsKey(key)) {
|
||||||
|
return CACHE.get(key);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
final Lock w = cacheLock.writeLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
String value = MageFrame.getPreferences().get(key, def);
|
String value = MageFrame.getPreferences().get(key, def);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return def;
|
value = def;
|
||||||
}
|
}
|
||||||
CACHE.put(key, value);
|
CACHE.put(key, value);
|
||||||
return value;
|
return value;
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ public class ChatSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!clientsToRemove.isEmpty()) {
|
if (!clientsToRemove.isEmpty()) {
|
||||||
final Lock w = lock.readLock();
|
final Lock w = lock.writeLock();
|
||||||
w.lock();
|
w.lock();
|
||||||
try {
|
try {
|
||||||
users.keySet().removeAll(clientsToRemove);
|
users.keySet().removeAll(clientsToRemove);
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
|
|
@ -53,13 +54,14 @@ public enum ServerMessagesUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getMessages() {
|
public List<String> getMessages() {
|
||||||
lock.readLock().lock();
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
try {
|
try {
|
||||||
List<String> res = new ArrayList<>(this.newsMessages);
|
List<String> res = new ArrayList<>(this.newsMessages);
|
||||||
res.add(this.statsMessage);
|
res.add(this.statsMessage);
|
||||||
return res;
|
return res;
|
||||||
} finally {
|
} finally {
|
||||||
lock.readLock().unlock();
|
r.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,13 +70,14 @@ public enum ServerMessagesUtil {
|
||||||
List<String> updatedMessages = new ArrayList<>(readFromFile());
|
List<String> updatedMessages = new ArrayList<>(readFromFile());
|
||||||
String updatedStats = getServerStatsMessage();
|
String updatedStats = getServerStatsMessage();
|
||||||
|
|
||||||
lock.writeLock().lock();
|
final Lock w = lock.writeLock();
|
||||||
|
w.lock();
|
||||||
try {
|
try {
|
||||||
this.newsMessages.clear();
|
this.newsMessages.clear();
|
||||||
this.newsMessages.addAll(updatedMessages);
|
this.newsMessages.addAll(updatedMessages);
|
||||||
this.statsMessage = updatedStats;
|
this.statsMessage = updatedStats;
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
w.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -185,13 +185,16 @@ if (exists ($new_order{$cmd}))
|
||||||
print ("\n\n\n");
|
print ("\n\n\n");
|
||||||
my $set;
|
my $set;
|
||||||
#print Dumper(\%cards_by_sets);
|
#print Dumper(\%cards_by_sets);
|
||||||
|
my $total = 0;
|
||||||
foreach $set (sort keys (%cards_by_sets))
|
foreach $set (sort keys (%cards_by_sets))
|
||||||
{
|
{
|
||||||
my $cards = $cards_by_sets{$set};
|
my $cards = $cards_by_sets{$set};
|
||||||
print ("* ", $set, " - added ", scalar @{$cards}, " new cards;", "\n");
|
print ("* ", $set, " - added ", scalar @{$cards}, " new cards;", "\n");
|
||||||
foreach my $card (@{$cards})
|
foreach my $card (@{$cards})
|
||||||
{
|
{
|
||||||
|
$total++;
|
||||||
print (" * ", $card, "\n");
|
print (" * ", $card, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
print ("* Total cards: ", $total);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue