Skip to content
Snippets Groups Projects

Resolve "Feature: Send endpoint for attributes"

Merged René Schöne requested to merge 38-feature-send-endpoint-for-attributes into dev
5 files
+ 175
69
Compare changes
  • Side-by-side
  • Inline
Files
5
  • 27cf1820
    - observer-entry now has list of connect-tokens and attributeCall is invoked once when attribute is flushed
    - INC_FLUSH_START and INC_FLUSH_END can now be nested
    - finished AttributeTest
@@ -87,22 +87,33 @@ aspect RagConnectObserver {
class RagConnectObserver implements ASTState.Trace.Receiver {
class RagConnectObserverEntry {
final RagConnectToken connectToken;
final ASTNode node;
final String attributeString;
final boolean compareParams;
final Object params;
final Runnable attributeCall;
final java.util.List<RagConnectToken> connectList = new java.util.ArrayList<>();
RagConnectObserverEntry(RagConnectToken connectToken, ASTNode node, String attributeString,
RagConnectObserverEntry(ASTNode node, String attributeString,
boolean compareParams, Object params, Runnable attributeCall) {
this.connectToken = connectToken;
this.node = node;
this.attributeString = attributeString;
this.compareParams = compareParams;
this.params = params;
this.attributeCall = attributeCall;
}
boolean baseMembersEqualTo(RagConnectObserverEntry other) {
return baseMembersEqualTo(other.node, other.attributeString, other.compareParams, other.params);
}
boolean baseMembersEqualTo(ASTNode otherNode, String otherAttributeString,
boolean otherCompareParams, Object otherParams) {
return this.node.equals(otherNode) &&
this.attributeString.equals(otherAttributeString) &&
this.compareParams == otherCompareParams &&
(!this.compareParams || java.util.Objects.equals(this.params, otherParams));
}
}
{{#configExperimentalJastAdd329}}
@@ -124,7 +135,7 @@ aspect RagConnectObserver {
{{#configExperimentalJastAdd329}}
java.util.Set<RagConnectObserverEntry> entryQueue = new java.util.HashSet<>();
RagConnectObserverStartEntry startEntry = null;
java.util.Deque<RagConnectObserverStartEntry> startEntries = new java.util.LinkedList<>();
{{/configExperimentalJastAdd329}}
RagConnectObserver(ASTNode node) {
@@ -145,42 +156,72 @@ aspect RagConnectObserver {
{{#configLoggingEnabledForIncremental}}
System.out.println("** observer add: " + node + " on " + attributeString + (compareParams ? " (parameterized)" : ""));
{{/configLoggingEnabledForIncremental}}
observedNodes.add(new RagConnectObserverEntry(connectToken, node, attributeString,
compareParams, params, attributeCall));
// either add to an existing entry (with same node, attribute) or create new entry
boolean needNewEntry = true;
for (RagConnectObserverEntry entry : observedNodes) {
if (entry.baseMembersEqualTo(node, attributeString, compareParams, params)) {
entry.connectList.add(connectToken);
needNewEntry = false;
break;
}
}
if (needNewEntry) {
RagConnectObserverEntry newEntry = new RagConnectObserverEntry(node, attributeString,
compareParams, params, attributeCall);
newEntry.connectList.add(connectToken);
observedNodes.add(newEntry);
}
}
void remove(RagConnectToken connectToken) {
observedNodes.removeIf(entry -> entry.connectToken.equals(connectToken));
RagConnectObserverEntry entryToDelete = null;
for (RagConnectObserverEntry entry : observedNodes) {
entry.connectList.remove(connectToken);
if (entry.connectList.isEmpty()) {
entryToDelete = entry;
}
}
if (entryToDelete != null) {
observedNodes.remove(entryToDelete);
}
}
@Override
public void accept(ASTState.Trace.Event event, ASTNode node, String attribute, Object params, Object value) {
oldReceiver.accept(event, node, attribute, params, value);
{{#configExperimentalJastAdd329}}
// react to INC_FLUSH_START and remember entry
if (event == ASTState.Trace.Event.INC_FLUSH_START && startEntry == null) {
if (event == ASTState.Trace.Event.INC_FLUSH_START && startEntries.isEmpty()) {
{{#configLoggingEnabledForIncremental}}
System.out.println("** observer start: " + node + " on " + attribute);
{{/configLoggingEnabledForIncremental}}
startEntry = new RagConnectObserverStartEntry(node, attribute, value);
startEntries.addFirst(new RagConnectObserverStartEntry(node, attribute, value));
return;
}
// react to INC_FLUSH_END and process queued entries, if it matches start entry
if (event == ASTState.Trace.Event.INC_FLUSH_END &&
node == startEntry.node &&
if (event == ASTState.Trace.Event.INC_FLUSH_END) {
if (startEntries.isEmpty()) {
{{#configLoggingEnabledForIncremental}}
System.out.println("** observer end without start! for " + node + " on " + attribute);
{{/configLoggingEnabledForIncremental}}
return;
}
RagConnectObserverStartEntry startEntry = startEntries.removeFirst();
if (node == startEntry.node &&
attribute == startEntry.attributeString &&
value == startEntry.flushIncToken) {
// create a copy of the queue to avoid entering this again causing an endless recursion
RagConnectObserverEntry[] entriesToProcess = entryQueue.toArray(new RagConnectObserverEntry[entryQueue.size()]);
entryQueue.clear();
startEntry = null;
{{#configLoggingEnabledForIncremental}}
System.out.println("** observer process (entries: " + entriesToProcess.length + "): " + node + " on " + attribute);
{{/configLoggingEnabledForIncremental}}
for (RagConnectObserverEntry entry : entriesToProcess) {
entry.attributeCall.run();
// create a copy of the queue to avoid entering this again causing an endless recursion
RagConnectObserverEntry[] entriesToProcess = entryQueue.toArray(new RagConnectObserverEntry[entryQueue.size()]);
entryQueue.clear();
{{#configLoggingEnabledForIncremental}}
System.out.println("** observer process (entries: " + entriesToProcess.length + "): " + node + " on " + attribute);
{{/configLoggingEnabledForIncremental}}
for (RagConnectObserverEntry entry : entriesToProcess) {
entry.attributeCall.run();
}
return;
}
return;
}
{{/configExperimentalJastAdd329}}
Loading