On Fri, 24 Nov 2023 14:57:08 GMT, Jaikiran Pai <j...@openjdk.org> wrote:

>> src/jdk.internal.jvmstat/share/classes/sun/jvmstat/monitor/MonitoredHost.java
>>  line 170:
>> 
>>> 168:                 break;
>>> 169:             }
>>> 170:         }
>> 
>> Alternatively, you can do it more succulently with a stream:
>> 
>> 
>> MonitoredHost mh = ServiceLoader.load(MonitoredHostService.class,
>>                                                   
>> MonitoredHostService.class.getClassLoader())
>>                     .stream()
>>                     .map(ServiceLoader.Provider::get)
>>                     .filter(mhs -> 
>> mhs.getScheme().equals(hostId.getScheme()))
>>                     .map(mhs -> mhs.getMonitoredHost(hostId))
>>                     .findAny()
>>                     .orElse(null);
>
>> .map(mhs -> mhs.getMonitoredHost(hostId))
> 
> That was a reasoanable suggestion and I gave it a try, but 
> `mhs.getMonitoredHost(hostId)` throws a checked exception `MonitorException` 
> so using this `Stream` based approach then would need additional exception 
> catching, wrapping and throwing, then catching this wrapped exception, 
> checking the cause and rethrowing. That then defeats the purpose of using the 
> `Stream` approach.
> 
> I see that you have approved the PR, so I think you are OK with the current 
> non-stream approach. I'll now trigger the tier tests and if all comes back 
> fine, I'll go ahead and integrate this in a day or two.
> 
> Kevin, does this latest form of the PR look OK to you too?

All good!

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16805#discussion_r1404446346

Reply via email to