diff options
Diffstat (limited to 'subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java index 56fd12c9..dfbd4878 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/push/PushWebDocument.java | |||
@@ -5,11 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.language.web.xtext.server.push; | 6 | package tools.refinery.language.web.xtext.server.push; |
7 | 7 | ||
8 | import java.util.ArrayList; | 8 | import com.google.common.collect.ImmutableList; |
9 | import java.util.HashMap; | ||
10 | import java.util.List; | ||
11 | import java.util.Map; | ||
12 | |||
13 | import org.eclipse.xtext.util.CancelIndicator; | 9 | import org.eclipse.xtext.util.CancelIndicator; |
14 | import org.eclipse.xtext.web.server.IServiceResult; | 10 | import org.eclipse.xtext.web.server.IServiceResult; |
15 | import org.eclipse.xtext.web.server.model.AbstractCachedService; | 11 | import org.eclipse.xtext.web.server.model.AbstractCachedService; |
@@ -17,11 +13,13 @@ import org.eclipse.xtext.web.server.model.DocumentSynchronizer; | |||
17 | import org.eclipse.xtext.web.server.model.XtextWebDocument; | 13 | import org.eclipse.xtext.web.server.model.XtextWebDocument; |
18 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
19 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
20 | |||
21 | import com.google.common.collect.ImmutableList; | ||
22 | |||
23 | import tools.refinery.language.web.xtext.server.ResponseHandlerException; | 16 | import tools.refinery.language.web.xtext.server.ResponseHandlerException; |
24 | 17 | ||
18 | import java.util.ArrayList; | ||
19 | import java.util.HashMap; | ||
20 | import java.util.List; | ||
21 | import java.util.Map; | ||
22 | |||
25 | public class PushWebDocument extends XtextWebDocument { | 23 | public class PushWebDocument extends XtextWebDocument { |
26 | private static final Logger LOG = LoggerFactory.getLogger(PushWebDocument.class); | 24 | private static final Logger LOG = LoggerFactory.getLogger(PushWebDocument.class); |
27 | 25 | ||
@@ -36,37 +34,31 @@ public class PushWebDocument extends XtextWebDocument { | |||
36 | } | 34 | } |
37 | } | 35 | } |
38 | 36 | ||
39 | public boolean addPrecomputationListener(PrecomputationListener listener) { | 37 | public void addPrecomputationListener(PrecomputationListener listener) { |
40 | synchronized (precomputationListeners) { | 38 | synchronized (precomputationListeners) { |
41 | if (precomputationListeners.contains(listener)) { | 39 | if (precomputationListeners.contains(listener)) { |
42 | return false; | 40 | return; |
43 | } | 41 | } |
44 | precomputationListeners.add(listener); | 42 | precomputationListeners.add(listener); |
45 | listener.onSubscribeToPrecomputationEvents(getResourceId(), this); | 43 | listener.onSubscribeToPrecomputationEvents(getResourceId(), this); |
46 | return true; | ||
47 | } | 44 | } |
48 | } | 45 | } |
49 | 46 | ||
50 | public boolean removePrecomputationListener(PrecomputationListener listener) { | 47 | public void removePrecomputationListener(PrecomputationListener listener) { |
51 | synchronized (precomputationListeners) { | 48 | synchronized (precomputationListeners) { |
52 | return precomputationListeners.remove(listener); | 49 | precomputationListeners.remove(listener); |
53 | } | 50 | } |
54 | } | 51 | } |
55 | 52 | ||
56 | public <T extends IServiceResult> void precomputeServiceResult(AbstractCachedService<T> service, String serviceName, | 53 | public <T extends IServiceResult> void precomputeServiceResult(AbstractCachedService<T> service, String serviceName, |
57 | CancelIndicator cancelIndicator, boolean logCacheMiss) { | 54 | CancelIndicator cancelIndicator, boolean logCacheMiss) { |
58 | var result = getCachedServiceResult(service, cancelIndicator, logCacheMiss); | ||
59 | if (result == null) { | ||
60 | LOG.error("{} service returned null result", serviceName); | ||
61 | return; | ||
62 | } | ||
63 | var serviceClass = service.getClass(); | 55 | var serviceClass = service.getClass(); |
64 | var previousResult = precomputedServices.get(serviceClass); | 56 | var previousResult = precomputedServices.get(serviceClass); |
65 | if (previousResult != null && previousResult.equals(result)) { | 57 | var result = getCachedServiceResult(service, cancelIndicator, logCacheMiss); |
66 | return; | ||
67 | } | ||
68 | precomputedServices.put(serviceClass, result); | 58 | precomputedServices.put(serviceClass, result); |
69 | notifyPrecomputationListeners(serviceName, result); | 59 | if (result != null && !result.equals(previousResult)) { |
60 | notifyPrecomputationListeners(serviceName, result); | ||
61 | } | ||
70 | } | 62 | } |
71 | 63 | ||
72 | private <T extends IServiceResult> void notifyPrecomputationListeners(String serviceName, T result) { | 64 | private <T extends IServiceResult> void notifyPrecomputationListeners(String serviceName, T result) { |