Skip to content

Commit d5896a8

Browse files
Remove GetRef RPC method (#5856)
* Remove `GetRef` RPC method For now removing `GetRef` again, as the object caches are no longer being evicted and thus the situation where an unknown ref is received should not occur. * Remove reference to "batch" from `RewriteRpc#parse()` * Remove `localObjectGenerators` field from `RewriteRpc`
1 parent cc1c5ea commit d5896a8

File tree

14 files changed

+24
-1053
lines changed

14 files changed

+24
-1053
lines changed

rewrite-core/src/main/java/org/openrewrite/rpc/RewriteRpc.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ protected RewriteRpc(JsonRpc jsonRpc, Environment marketplace, Duration timeout)
125125
Map<String, Recipe> preparedRecipes = new HashMap<>();
126126
Map<Recipe, Cursor> recipeCursors = new IdentityHashMap<>();
127127

128-
jsonRpc.rpc("GetRef", new GetRef.Handler(remoteRefs, localRefs, batchSize, traceSendPackets));
129128
jsonRpc.rpc("Visit", new Visit.Handler(localObjects, preparedRecipes, recipeCursors,
130129
this::getObject, this::getCursor));
131130
jsonRpc.rpc("Generate", new Generate.Handler(localObjects, preparedRecipes, recipeCursors,
@@ -280,11 +279,7 @@ public boolean tryAdvance(Consumer<? super SourceFile> action) {
280279
if (ids == null) {
281280
// FIXME handle `TimeoutException` gracefully
282281
ids = send("Parse", new Parse(mappedInputs, relativeTo != null ? relativeTo.toString() : null), ParseResponse.class);
283-
284-
// If batch is empty, we're done
285-
if (ids.isEmpty()) {
286-
return false;
287-
}
282+
assert ids.size() == inputList.size();
288283
}
289284

290285
// Process current item in batch
@@ -364,7 +359,7 @@ public <T> T getObject(String id) {
364359
String lastKnownId = localObject != null ? id : null;
365360

366361
RpcReceiveQueue q = new RpcReceiveQueue(remoteRefs, traceFile, () -> send("GetObject",
367-
new GetObject(id, lastKnownId), GetObjectResponse.class), this::getRef);
362+
new GetObject(id, lastKnownId), GetObjectResponse.class));
368363
Object remoteObject = q.receive(localObject, null);
369364
if (q.take().getState() != END_OF_OBJECT) {
370365
throw new IllegalStateException("Expected END_OF_OBJECT");
@@ -377,27 +372,6 @@ public <T> T getObject(String id) {
377372
return (T) remoteObject;
378373
}
379374

380-
private Object getRef(Integer refId) {
381-
RpcReceiveQueue q = new RpcReceiveQueue(remoteRefs, traceFile, () -> send("GetRef",
382-
new GetRef(refId), GetRefResponse.class), nestedRefId -> {
383-
throw new IllegalStateException("Nested ref calls not supported in GetRef: " + nestedRefId);
384-
});
385-
386-
Object ref = q.receive(null, null);
387-
if (q.take().getState() != END_OF_OBJECT) {
388-
throw new IllegalStateException("Expected END_OF_OBJECT");
389-
}
390-
391-
if (ref == null) {
392-
throw new IllegalStateException("Reference " + refId + " not found on remote");
393-
}
394-
395-
remoteRefs.put(refId, ref);
396-
localRefs.put(ref, refId);
397-
398-
return ref;
399-
}
400-
401375
protected <P> P send(String method, @Nullable RpcRequest body, Class<P> responseType) {
402376
try {
403377
// TODO handle error

rewrite-core/src/main/java/org/openrewrite/rpc/RpcReceiveQueue.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ public class RpcReceiveQueue {
4646
private final Map<Integer, Object> refs;
4747
private final @Nullable PrintStream logFile;
4848
private final Supplier<List<RpcObjectData>> pull;
49-
private final Function<Integer, Object> getRef;
5049

5150
public RpcReceiveQueue(Map<Integer, Object> refs, @Nullable PrintStream logFile,
52-
Supplier<List<RpcObjectData>> pull, Function<Integer, Object> getRef) {
51+
Supplier<List<RpcObjectData>> pull) {
5352
this.refs = refs;
5453
this.batch = new ArrayDeque<>();
5554
this.logFile = logFile;
5655
this.pull = pull;
57-
this.getRef = getRef;
5856
}
5957

6058
public RpcObjectData take() {
@@ -135,11 +133,7 @@ public <T> T receive(@Nullable T before) {
135133
//noinspection unchecked
136134
return (T) refs.get(ref);
137135
} else {
138-
// Ref was evicted from cache, fetch it
139-
Object refObject = getRef.apply(ref);
140-
refs.put(ref, refObject);
141-
//noinspection unchecked
142-
return (T) refObject;
136+
throw new IllegalStateException("Received a reference to an object that was not previously sent: " + ref);
143137
}
144138
} else {
145139
// This is either a new object or a forward declaration with ref

rewrite-core/src/main/java/org/openrewrite/rpc/request/GetRef.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

rewrite-core/src/main/java/org/openrewrite/rpc/request/GetRefResponse.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

rewrite-core/src/test/java/org/openrewrite/rpc/GetRefRequestTest.java

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)