Rename dropwizard Duration
See original GitHub issueIt would be nice if the DropWizard Duration
class had a different name like ConfigurationDuration
or YamlReadableDuration
or something like that. I find that a lot of the APIs I use need a regular java.time.Duration
and I ended up having to fully qualify one or the other. Most of us only use the DropWizard Duration as a simpler string to write in a config file.
Another solution would be to add a method toJavaDuration()
so I can just take one of those and turn it into the java.time.Duration
I need.
Minor for sure, just thought I’d document it while I was running into it.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Dropwizard Core
A Task is a run-time action your application provides access to on the administrative port via HTTP. All Dropwizard applications start with: the...
Read more >How does FlexyPool support the Dropwizard Metrics package ...
Being integrated into Dropwizard, the package name was bound to be renamed. So instead of com.codahale.metrics the 4.0.0 release will use ...
Read more >Make metric names configurable · Issue #76 · vert-x3/vertx ...
Hi, I've got an intention to override default metrics names Vertx provides. For example, I'm not happy with this metric for HTTP server ......
Read more >Rename fields from events | Metricbeat Reference [7.17] | Elastic
The rename processor cannot be used to overwrite fields. ... is a subfield of c ), assigning scalar values results in an Elasticsearch...
Read more >Difference between Application and Service in Dropwizard
Added HibernateBundle#configure(Configuration) for customization of Hibernate configuration. Added support for Joda Time DateTime arguments and results when ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, sounds good. Just so that I’m clear on this, do you only need the one PR for 2.1.x branch, and then you’ll just cherry-pick it to the other branches?
We’ve actually had a very small utility for years to do this exact thing, i.e. convert from
io.dropwizard.util.Duration
to ajava.time.Duration
. In Dropwizard’sDuration
, with Java 9 and later it can be as simple as:But since Dropwizard 2.1.x is still using Java 8, the
toChronoUnit()
method doesn’t exist inTimeUnit
. It was added in JDK 9.So, in the 2.1.x branch one solution would be to copy the implementation of JDK 9’s
TimeUnit#toChronoUnit
to theDuration
class as aprivate static
method and use it like this:While I am not usually a fan of copying a method like this, the alternatives would probably need to do some conversions using the
java.time.Duration.ofXxx
methods likeofMillis
andofNanos
, which would be more complicated in order to make sure there is no loss of precision. One big advantage is that using theDuration#of
method takes care of the complexity of dealing with the various units. Have a look at the implementation ofjava.time.Duration#of
and specifically all the details inside theplus(long amountToAdd, TemporalUnit unit)
method that it calls.Assuming the above makes sense, I’d suggest doing separate pull requests for the 2.1.x branch and the 3.x and/or 4.x branches. The 3.x and 4.x branches can make use of the
TimeUnit#toChronoUnit
method and have the simple one line implementation, while the 2.1.x branch would use the JDK 8 code above.If you think the above makes sense, I can create the PRs for the 2.1.x branch and then for the 3.x branch and optionally the 4.x branch. Or, if the JDK 8 solution doesn’t make sense or you have a better idea that I didn’t think of, I’d be happy to implement that as well.