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

package org.bouncycastle.jcajce.provider.drbg;

import org.bouncycastle.util.Properties;
import java.util.logging.Level;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;

class EntropyGatherer implements Runnable
{
    private static final Logger LOG;
    private final long pause;
    private final AtomicBoolean seedAvailable;
    private final AtomicReference<byte[]> entropy;
    private final IncrementalEntropySource baseRandom;
    
    EntropyGatherer(final IncrementalEntropySource baseRandom, final AtomicBoolean seedAvailable, final AtomicReference<byte[]> entropy) {
        this.baseRandom = baseRandom;
        this.seedAvailable = seedAvailable;
        this.entropy = entropy;
        this.pause = getPause();
    }
    
    @Override
    public void run() {
        try {
            this.entropy.set(this.baseRandom.getEntropy(this.pause));
            this.seedAvailable.set(true);
        }
        catch (final InterruptedException ex) {
            if (EntropyGatherer.LOG.isLoggable(Level.FINE)) {
                EntropyGatherer.LOG.fine("entropy request interrupted - exiting");
            }
            Thread.currentThread().interrupt();
        }
    }
    
    private static long getPause() {
        final String propertyValue = Properties.getPropertyValue("org.bouncycastle.drbg.gather_pause_secs");
        if (propertyValue != null) {
            try {
                return Long.parseLong(propertyValue) * 1000L;
            }
            catch (final Exception ex) {
                return 5000L;
            }
        }
        return 5000L;
    }
    
    static {
        LOG = Logger.getLogger(EntropyGatherer.class.getName());
    }
}
