Skip to content

Conversation

@scottf
Copy link
Contributor

@scottf scottf commented Feb 17, 2025

Additional testing. Minor tweaks.

se.getMetadata()
));
serialized.set(null);
return this;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this method should not be public. Only the service code is supposed to build this.
  2. Clear the lazy serialization. when an endpoint is added

se.getMetadata()
));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top of the file


// build responses first. info needs to be available when adding service endpoints.
pingResponse = new PingResponse(id, b.name, b.version, b.metadata);
infoResponse = new InfoResponse(id, b.name, b.version, b.metadata, b.description);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build responses first. info needs to be available when adding service endpoints.

discoveryContexts = new ArrayList<>();
addDiscoveryContexts(SRV_PING, pingResponse, b.pingDispatcher, dTemp);
addDynamicDiscoveryContexts(SRV_INFO, infoResponse, b.infoDispatcher, dTemp);
addDiscoveryContexts(SRV_INFO, infoResponse, b.infoDispatcher, dTemp);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do this because of the lazy serialization

Dispatcher dTemp = null == dInternals || dInternals.isEmpty() ? null : dInternals.get(0);
EndpointContext ctx = null;
// do this first so it's available on start
infoResponse.addServiceEndpoint(se);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do this first so it's available on start

}

if (null != infoResponse) {
infoResponse.addServiceEndpoint(se);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

infoResponse will never be null since it's initialized first in the constructor.

ServiceMessageHandler handler = smsg -> smsg.respond(conn, sr.serialize());
addDiscoveryContexts(discoveryName, dUser, dInternal, handler);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed since lazy serialization

if (serialized.get() == null) {
serialized.set(toJson().getBytes(StandardCharsets.UTF_8));
}
return serialized.get();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is part of the JsonSerializable interface, which has a default, always execute implementation. This is why I originally applied the serializer in the add discovery, so it didn't need to be executed every time. But since we can add endpoints, the serialization needs to be updated when endpoints are added.

Endpoint ep = new Endpoint("endfoo", endMeta);
ServiceEndpoint se = new ServiceEndpoint(ep, m -> {}, null);
InfoResponse ir1 = new InfoResponse("id", "name", "0.0.0", metadata, "desc", Collections.singletonList(se));
InfoResponse ir1 = new InfoResponse("id", "name", "0.0.0", metadata, "desc").addServiceEndpoint(se);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflects move the endpoints out of the constructor.

@aricart aricart self-requested a review February 17, 2025 18:27
Copy link
Member

@aricart aricart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@scottf scottf merged commit a3ccd2a into main Feb 17, 2025
4 checks passed
@scottf scottf deleted the service-add-endpoints-after-more branch February 17, 2025 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants