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

Make FreePortFinder support Jackson's polymorphic deserialization #547

Closed
sleberknight opened this issue Oct 16, 2024 · 0 comments · Fixed by #548
Closed

Make FreePortFinder support Jackson's polymorphic deserialization #547

sleberknight opened this issue Oct 16, 2024 · 0 comments · Fixed by #548
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Oct 16, 2024

FreePortFinder should allow for deserialization into a specific type using Jackson's polymorphic deserialization feature.

This will allow new implementations to be easily configured in YAML. For example:

dynamicPorts:
  freePortFinder:
    type: lowHigh
  minDynamicPort: 27000
  maxDynamicPort: 29000
  tls:
    keyStorePath: /data/etc/pki/my-ks.jks
    keyStorePassword: my-ks-pwd
    trustStorePath: /data/etc/pki/my-ts.jks
    trustStorePassword: my-ts-pwd

In the above the freePortFinder is configured using the type property to specify the implementation, which needs to map to a class annotated with the same type in a @JsonTypeName annotation. For example:

@JsonTypeName("lowHigh")
public static class LowHighFreePortFinder implements FreePortFinder {
    // implementation details omitted...
}

For the three out-of-the-box implementations, use the following as the type name:

Implementation Class Type Name
AdjacentFreePortFinder adjacent
IncrementingFreePortFinder incrementing
RandomFreePortFinder random

All this "just works" because of Dropwizard support for Polymorphic configuration

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Oct 16, 2024
@sleberknight sleberknight added this to the 4.0.0 milestone Oct 16, 2024
@sleberknight sleberknight self-assigned this Oct 16, 2024
sleberknight added a commit that referenced this issue Oct 17, 2024
* Configure a FreePortFinder when creating the PortAssigner
  inside DynamicPortsBundle.
* Remove LocalPortChecker from DynamicPortsConfiguration.
* Add FreePortFinder to DynamicPortsConfiguration.
* Remove LocalPortChecker from PortAssigner.
* Make FreePortFinder support Jackson's polymorphic deserialization
  by adding JsonTypeInfo to FreePortFinder, adding JsonTypeName
  annotation to the three FreePortFinder impls, and adding an
  io.dropwizard.jackson.Discoverable in META-INF/services, plus
  org.kiwiproject.dropwizard.util.startup.FreePortFinder also
  in META-INF/services.
* Lots of test refactoring and new tests.
* Misc: fix Javadoc in StartupLockConfiguration

Closes #545
Closes #546
Closes #547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant