From 8e4bc4280b1e6ecad32bac40e99718cd9ab87e33 Mon Sep 17 00:00:00 2001 From: Mats Date: Tue, 5 Mar 2024 22:46:05 +0100 Subject: [PATCH] Gracefully handle deadends --- .../meteor/core/trackers/OutgoingInvocationTracker.java | 9 ++++++--- .../pixelib/meteor/core/transport/TransportHandler.java | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/meteor-core/src/main/java/dev/pixelib/meteor/core/trackers/OutgoingInvocationTracker.java b/meteor-core/src/main/java/dev/pixelib/meteor/core/trackers/OutgoingInvocationTracker.java index 9f95c11..1a25c07 100644 --- a/meteor-core/src/main/java/dev/pixelib/meteor/core/trackers/OutgoingInvocationTracker.java +++ b/meteor-core/src/main/java/dev/pixelib/meteor/core/trackers/OutgoingInvocationTracker.java @@ -50,18 +50,21 @@ public T invokeRemoteMethod(InvocationDescriptor invocationDescriptor) throw } } - public void completeInvocation(InvocationResponse invocationResponse) { + public boolean completeInvocation(InvocationResponse invocationResponse) { // do we have a pending invocation for this invocation id? PendingInvocation pendingInvocation = pendingInvocations.get(invocationResponse.getInvocationId()); if (pendingInvocation == null) { - throw new IllegalStateException("No pending invocation found for invocation id " + invocationResponse.getInvocationId() + ". Data: " + invocationResponse.getResult()); - //return; + // we cannot handle this invocation, so it must be handled in another listener + return false; } pendingInvocation.complete(invocationResponse.getResult()); // remove the pending invocation from the map pendingInvocations.remove(invocationResponse.getInvocationId()); + + // invocation was successfully completed + return true; } } diff --git a/meteor-core/src/main/java/dev/pixelib/meteor/core/transport/TransportHandler.java b/meteor-core/src/main/java/dev/pixelib/meteor/core/transport/TransportHandler.java index 9b1ecf7..b1dea18 100644 --- a/meteor-core/src/main/java/dev/pixelib/meteor/core/transport/TransportHandler.java +++ b/meteor-core/src/main/java/dev/pixelib/meteor/core/transport/TransportHandler.java @@ -49,8 +49,7 @@ public TransportHandler( private boolean handleInvocationResponse(byte[] bytes) throws ClassNotFoundException { InvocationResponse invocationResponse = InvocationResponse.fromBytes(serializer, bytes); - outgoingInvocationTracker.completeInvocation(invocationResponse); - return true; + return outgoingInvocationTracker.completeInvocation(invocationResponse); } private boolean handleInvocationRequest(byte[] bytes) throws ClassNotFoundException {