class PolicyUpdater {

    static void policyUpdater(PolicyUpdaterConfiguration configuration, ZTSClientFactory ztsFactory)
            throws Exception {

        try (ZTSClient zts = ztsFactory.create()) {

            List<String> domainList = configuration.getDomainList();
            LOG.info("policyUpdater: Number of domains to process:"
                    + (domainList == null ? 0 : domainList.size()));
            if (domainList == null) {
                LOG.error("policyUpdater: no domain list to process from configuration");
                throw new Exception("no configured domains to process");
            }
            
            for (String domain : domainList) {

                LOG.info("Fetching signed policies for domain:" + domain);
                
                String matchingTag = getEtagForExistingPolicy(zts, configuration, domain);
                
                Map<String, List<String>> responseHeaders = null;
                DomainSignedPolicyData domainSignedPolicyData = null;
                try {
                    domainSignedPolicyData = zts.getDomainSignedPolicyData(domain, matchingTag,
                            responseHeaders);
                } catch (Exception exc) {
                    domainSignedPolicyData = null;
                    LOG.error("PolicyUpdater: Unable to retrieve policies from zts for domain="
                            + domain, exc);
                }
                if (domainSignedPolicyData == null) {
                    if (matchingTag != null && !matchingTag.isEmpty()) {
                        LOG.info("PolicyUpdater: Policies not updated since last fetch time");
                    }
                } else if (validateSignedPolicies(zts, configuration, domainSignedPolicyData, domain)) {
                    writePolicies(configuration, domain, domainSignedPolicyData);
                }
            }
            
            // now push the domain metrics files
            
            postDomainMetrics(zts);
        }
    }

}