mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-22 20:13:52 +00:00
using Lambdas for more compact code; some formatting adjustments
Change-Id: I2666f1797ab71e72b81188dc2103fe19265fa2c8
This commit is contained in:
1 parent
5a429b4097
commit
315043bca1
1 file changed
+17
-40
+17
-40
@@ -74,34 +74,23 @@ public class RemoteSailingServerSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
LockUtil.executeWithWriteLock(lock, new Runnable() {
|
LockUtil.executeWithWriteLock(lock, () -> {
|
||||||
@Override
|
remoteSailingServers.clear();
|
||||||
public void run() {
|
cachedEventsForRemoteSailingServers.clear();
|
||||||
remoteSailingServers.clear();
|
|
||||||
cachedEventsForRemoteSailingServers.clear();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(RemoteSailingServerReference remoteSailingServerReference) {
|
public void add(RemoteSailingServerReference remoteSailingServerReference) {
|
||||||
LockUtil.executeWithWriteLock(lock, new Runnable() {
|
LockUtil.executeWithWriteLock(lock, () -> {
|
||||||
|
remoteSailingServers.put(remoteSailingServerReference.getName(), remoteSailingServerReference);
|
||||||
@Override
|
triggerAsynchronousEventCacheUpdate(remoteSailingServerReference);
|
||||||
public void run() {
|
|
||||||
remoteSailingServers.put(remoteSailingServerReference.getName(), remoteSailingServerReference);
|
|
||||||
triggerAsynchronousEventCacheUpdate(remoteSailingServerReference);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRemoteSailingServerReferenceEventCaches() {
|
private void updateRemoteSailingServerReferenceEventCaches() {
|
||||||
LockUtil.executeWithReadLock(lock, new Runnable() {
|
LockUtil.executeWithReadLock(lock, () -> {
|
||||||
|
for (RemoteSailingServerReference ref : remoteSailingServers.values()) {
|
||||||
@Override
|
triggerAsynchronousEventCacheUpdate(ref);
|
||||||
public void run() {
|
|
||||||
for (RemoteSailingServerReference ref : remoteSailingServers.values()) {
|
|
||||||
triggerAsynchronousEventCacheUpdate(ref);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -115,12 +104,7 @@ public class RemoteSailingServerSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void triggerAsynchronousEventCacheUpdate(final RemoteSailingServerReference ref) {
|
private void triggerAsynchronousEventCacheUpdate(final RemoteSailingServerReference ref) {
|
||||||
new Thread("Event Cache Updater for remote server " + ref) {
|
new Thread(() -> updateRemoteServerEventCacheSynchronously(ref), "Event Cache Updater for remote server " + ref).start();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updateRemoteServerEventCacheSynchronously(ref);
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Util.Pair<Iterable<EventBase>, Exception> updateRemoteServerEventCacheSynchronously(
|
private Util.Pair<Iterable<EventBase>, Exception> updateRemoteServerEventCacheSynchronously(
|
||||||
@@ -156,19 +140,13 @@ public class RemoteSailingServerSet {
|
|||||||
e);
|
e);
|
||||||
result = new Util.Pair<Iterable<EventBase>, Exception>(/* events */ null, e);
|
result = new Util.Pair<Iterable<EventBase>, Exception>(/* events */ null, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Pair<Iterable<EventBase>, Exception> finalResult = result;
|
final Pair<Iterable<EventBase>, Exception> finalResult = result;
|
||||||
|
LockUtil.executeWithWriteLock(lock, () -> {
|
||||||
LockUtil.executeWithWriteLock(lock, new Runnable() {
|
// check that the server was not removed while no lock was held
|
||||||
|
if (remoteSailingServers.containsValue(ref)) {
|
||||||
@Override
|
cachedEventsForRemoteSailingServers.put(ref, finalResult);
|
||||||
public void run() {
|
} else {
|
||||||
// check that the server was not removed while no lock was held
|
logger.fine("Omitted update for " + ref + " as it was removed");
|
||||||
if (remoteSailingServers.containsValue(ref)) {
|
|
||||||
cachedEventsForRemoteSailingServers.put(ref, finalResult);
|
|
||||||
}else{
|
|
||||||
logger.fine("Omitted update for " + ref + " as it was removed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@@ -225,8 +203,7 @@ public class RemoteSailingServerSet {
|
|||||||
List<RemoteSailingServerReference> result = new ArrayList<>();
|
List<RemoteSailingServerReference> result = new ArrayList<>();
|
||||||
LockUtil.lockForRead(lock);
|
LockUtil.lockForRead(lock);
|
||||||
try {
|
try {
|
||||||
for (Map.Entry<RemoteSailingServerReference, Pair<Iterable<EventBase>, Exception>> e : cachedEventsForRemoteSailingServers
|
for (Map.Entry<RemoteSailingServerReference, Pair<Iterable<EventBase>, Exception>> e : cachedEventsForRemoteSailingServers.entrySet()) {
|
||||||
.entrySet()) {
|
|
||||||
if (e.getValue().getB() == null) {
|
if (e.getValue().getB() == null) {
|
||||||
// no exception; reference considered live
|
// no exception; reference considered live
|
||||||
result.add(e.getKey());
|
result.add(e.getKey());
|
||||||
|
|||||||
Reference in new issue
Block a user