// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.jwk.source;

import com.nimbusds.jose.KeySourceException;
import com.nimbusds.jose.util.health.HealthReport;
import com.nimbusds.jose.util.health.HealthStatus;
import com.nimbusds.jose.jwk.JWKSet;
import java.util.Objects;
import com.nimbusds.jose.util.health.HealthReportListener;
import com.nimbusds.jose.shaded.jcip.ThreadSafe;
import com.nimbusds.jose.proc.SecurityContext;

@ThreadSafe
public class JWKSetSourceWithHealthStatusReporting<C extends SecurityContext> extends JWKSetSourceWrapper<C>
{
    private final HealthReportListener<JWKSetSourceWithHealthStatusReporting<C>, C> healthReportListener;
    
    public JWKSetSourceWithHealthStatusReporting(final JWKSetSource<C> source, final HealthReportListener<JWKSetSourceWithHealthStatusReporting<C>, C> healthReportListener) {
        super(source);
        Objects.requireNonNull(healthReportListener);
        this.healthReportListener = healthReportListener;
    }
    
    @Override
    public JWKSet getJWKSet(final JWKSetCacheRefreshEvaluator refreshEvaluator, final long currentTime, final C context) throws KeySourceException {
        JWKSet jwkSet;
        try {
            jwkSet = this.getSource().getJWKSet(refreshEvaluator, currentTime, context);
            this.healthReportListener.notify(new HealthReport<JWKSetSourceWithHealthStatusReporting<C>, C>(this, HealthStatus.HEALTHY, currentTime, context));
        }
        catch (final Exception e) {
            this.healthReportListener.notify(new HealthReport<JWKSetSourceWithHealthStatusReporting<C>, C>(this, HealthStatus.NOT_HEALTHY, e, currentTime, context));
            throw e;
        }
        return jwkSet;
    }
}
