[microprofile] How to define the java.time.temporal.ChronoUnit via the configuration file?

25 views
Skip to first unread message

Charlee Chitsuk

unread,
Feb 18, 2019, 3:18:30 AM2/18/19
to Payara Forum
Dear Team,

I've tried to set the fault tolerance annotation time unit via the `META-INF/microprofile-config.properties`, but have no luck to success.

Here is what I tried

#META-INF/microprofile-config.properties

my.service.MyResource/alwaysFail/CircuitBreaker/delayUnit=java.time.temporal.ChronoUnit.MILLIS

The system show me as an exception as the following: -

java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.ChronoUnit
at fish.payara.microprofile.faulttolerance.interceptors.CircuitBreakerInterceptor.circuitBreak(CircuitBreakerInterceptor.java:220)
at fish.payara.microprofile.faulttolerance.interceptors.CircuitBreakerInterceptor.intercept(CircuitBreakerInterceptor.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
at org.jboss.weld.interceptor.proxy.NonTerminalAroundInvokeInvocationContext.proceedInternal(NonTerminalAroundInvokeInvocationContext.java:66)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)
at fish.payara.microprofile.metrics.cdi.interceptor.TimedInterceptor.applyInterceptor(TimedInterceptor.java:67)
at fish.payara.microprofile.metrics.cdi.interceptor.AbstractInterceptor.preInterceptor(AbstractInterceptor.java:91)
at fish.payara.microprofile.metrics.cdi.interceptor.AbstractInterceptor.methodInvocation(AbstractInterceptor.java:78)

Could you please help to advise how to define the java.time.temporal.ChronoUnit via the configuration file?

Regards,

Charlee Ch.

Ondro Mihályi

unread,
Feb 21, 2019, 3:28:26 AM2/21/19
to Payara Forum
Hi,

You should just use MILLIS as the value:

my.service.MyResource/alwaysFail/CircuitBreaker/delayUnit=MILLIS

MicroProfile Config will automatically convert to ChronoUnit using its static method valueOf(String), which accepts only the simple name, not full name.

Charlee Chitsuk

unread,
Feb 21, 2019, 4:26:20 AM2/21/19
to Payara Forum
Hi,

Thank you for your advice. I've tried to set as "MILLIS", but the exception still thrown as the following: -

java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.ChronoUnit
at fish.payara.microprofile.faulttolerance.interceptors.CircuitBreakerInterceptor.circuitBreak(CircuitBreakerInterceptor.java:220)
at fish.payara.microprofile.faulttolerance.interceptors.CircuitBreakerInterceptor.intercept(CircuitBreakerInterceptor.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
at org.jboss.weld.interceptor.proxy.NonTerminalAroundInvokeInvocationContext.proceedInternal(NonTerminalAroundInvokeInvocationContext.java:66)
at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)

I also have a chance to look at CircuitBreakerInterceptor[1] and found that it use "String.class" for looking up the value and then cast it to "ChronoUnit".

ChronoUnit delayUnit = (ChronoUnit) FaultToleranceCdiUtils.getOverrideValue(
config, CircuitBreaker.class, "delayUnit", invocationContext, String.class)
.orElse(circuitBreaker.delayUnit());

I'm not sure if this may be a root cause for the message "java.lang.String cannot be cast to java.time.temporal.ChronoUnit" or I've to set the java.time.temporal.ChronoUnit with other value instead. Could you please help to advise further?

Regards,

Charlee Ch.

Andrew Pielage

unread,
Feb 22, 2019, 6:49:02 AM2/22/19
to Payara Forum
Hello Charlee,

I've created a PR that should hopefully fix this issue - you pinpointed the problem correctly.

Thanks,
Andrew
Reply all
Reply to author
Forward
0 new messages