Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in the utransport_fix from up-java #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading