Skip to content

Commit

Permalink
Pull in the utransport_fix from up-java
Browse files Browse the repository at this point in the history
The following pulls in eclipse-uprotocol/up-java#84
  • Loading branch information
Steven Hartley committed Feb 7, 2024
1 parent d0a06d9 commit b35024b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
40 changes: 5 additions & 35 deletions library/src/main/java/org/eclipse/uprotocol/UPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ public void onConnectionInterrupted() {
};

private final UListener mListener = new UListener() {
@Override
public void onReceive(UUri topic, UPayload payload, UAttributes attributes) {
handleMessage(buildMessage(topic, payload, attributes));
}

@Override
public void onReceive(UMessage message) {
Expand Down Expand Up @@ -480,32 +476,6 @@ UListener getListener() {
return mListener;
}

private static @NonNull UMessage buildMessage(UUri source, UPayload payload, UAttributes attributes) {
final UMessage.Builder builder = UMessage.newBuilder();
if (source != null) {
builder.setSource(source);
}
if (payload != null) {
builder.setPayload(payload);
}
if (attributes != null) {
builder.setAttributes(attributes);
}
return builder.build();
}

/**
* Transmit a payload associated with a source using defined attributes.
*
* @param source A {@link UUri} associated with a payload.
* @param payload A {@link UPayload} to be sent.
* @param attributes {@link UAttributes} containing transport attributes.
* @return A {@link UStatus} which contains a result code and other details.
*/
@Override
public @NonNull UStatus send(@NonNull UUri source, @NonNull UPayload payload, @NonNull UAttributes attributes) {
return mUBusManager.send(buildMessage(source, payload, attributes));
}

/**
* Transmit a message.
Expand Down Expand Up @@ -708,9 +678,9 @@ private boolean unregisterListenerLocked(@NonNull UUri topic, @NonNull UListener
checkNotNull(requestPayload, "Payload is null");
checkNotNull(options, "Options cannot be null");
final int timeout = checkArgumentPositive(options.timeout(), "Timeout is not positive");
final UAttributesBuilder builder = UAttributesBuilder.request(UPriority.UPRIORITY_CS4, methodUri, timeout);
final UAttributesBuilder builder = UAttributesBuilder.request(mResponseUri, UPriority.UPRIORITY_CS4, methodUri, timeout);
options.token().ifPresent(builder::withToken);
final UMessage requestMessage = buildMessage(mResponseUri, requestPayload, builder.build());
final UMessage requestMessage = UMessage.newBuilder().setPayload(requestPayload).setAttributes(builder.build()).build();
return mRequests.compute(requestMessage.getAttributes().getId(), (requestId, currentRequest) -> {
checkArgument(currentRequest == null, UCode.ABORTED, "Duplicated request found");
final UStatus status = send(requestMessage);
Expand Down Expand Up @@ -765,7 +735,7 @@ private void handleGenericMessage(@NonNull UMessage message) {
}
}
mCallbackExecutor.execute(() -> {
final UUri topic = message.getSource();
final UUri topic = message.getAttributes().getSource();
final Set<UListener> listeners;
synchronized (mRegistrationLock) {
listeners = new ArraySet<>(mListeners.get(topic));
Expand Down Expand Up @@ -797,13 +767,13 @@ private void handleRequestMessage(@NonNull UMessage requestMessage) {
responseFuture.whenComplete((responsePayload, exception) -> {
final UAttributes requestAttributes = requestMessage.getAttributes();
final UAttributesBuilder builder = UAttributesBuilder
.response(requestAttributes.getPriority(), requestMessage.getSource(), requestAttributes.getId());
.response(requestAttributes.getSink(), requestAttributes.getPriority(), requestMessage.getAttributes().getSource(), requestAttributes.getId());
if (exception != null) {
builder.withCommStatus(toStatus(exception).getCodeValue());
} else if (responsePayload == null) {
return;
}
send(buildMessage(requestAttributes.getSink(), responsePayload, builder.build()));
send(UMessage.newBuilder().setPayload(responsePayload).setAttributes(builder.build()).build());
});
return responseFuture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private static void appendPairsSeparator(@NonNull StringBuilder builder) {
}
final UAttributes attributes = message.getAttributes();
final boolean hasSink = attributes.hasSink();
return joinGrouped(Key.ID, stringify(attributes.getId()), Key.SOURCE, stringify(message.getSource()),
return joinGrouped(Key.ID, stringify(attributes.getId()), Key.SOURCE, stringify(attributes.getSource()),
hasSink ? Key.SINK : null, hasSink ? stringify(attributes.getSink()) : null,
Key.TYPE, attributes.getType());
}
Expand Down

0 comments on commit b35024b

Please sign in to comment.