class SoapSTSInstancePublisherImpl implements SoapSTSInstancePublisher {

    @Override
    public void run() {
        //run method will be in a global try/catch(Exception) block because an uncaught exception will terminate subsequent runs
        try {
            Set<SoapSTSInstanceConfig> serverProvidedConfigurations;
            try {
                /*
                When the ScheduledExecutorService#shutdownNow is called, running threads will be interrupted. Respond ASAP.
                */
                if (Thread.currentThread().isInterrupted()) {
                    return;
                }
                serverProvidedConfigurations = publishServiceConsumer.getPublishedInstances();
            } catch (ResourceException e) {
                /*
                Don't log to error - many log messages will be generated as this Runnable runs periodically, and this
                exception is thrown if the OpenAM mothership is down.
                */
                logger.warn("Soap sts instances published on the home OpenAM server cannot be exposed as a " +
                        "web-service because their configuration state could not be obtained from the home server. " +
                        "Exception: " + e, e);
                return;
            }
            /*
            When the ScheduledExecutorService#shutdownNow is called, running threads will be interrupted. Respond ASAP.
            */
            if (Thread.currentThread().isInterrupted()) {
                return;
            }
            /*
            Three cases must be handled:
            1. a new instance has been published
            2. an instances has been removed
            3. an instance has been updated
            The guava Maps#difference method will make this easy - first marshal the returned instances to map view
            equivalent to that maintained in publishedAndExposedInstances.
            */
            Map<String, ConfigAndServerHolder> serverProvidedConfigurationMap =
                    marshalPublishedConfigToCommonFormat(serverProvidedConfigurations);
            MapDifference<String, ConfigAndServerHolder> diff = Maps.difference(publishedAndExposedInstances, serverProvidedConfigurationMap);

            exposeNewInstances(diff.entriesOnlyOnRight().values());
            removeDeletedInstances(diff.entriesOnlyOnLeft().values());
            updateInstances(diff.entriesDiffering().values());
            
            // Update the health check with the number of exposed STS instances.
            healthCheck.setNumPublishedInstances(publishedAndExposedInstances.size());
        } catch (Exception e) {
            logger.error("Unexpected exception caught in SoapSTSInstancePublisherImpl#run: " + e, e);
        }
    }

    @Inject public  SoapSTSInstancePublisherImpl(SoapSTSInstanceLifecycleManager soapSTSInstanceLifecycleManager,
                                        PublishServiceConsumer publishServiceConsumer,
                                        Logger logger,
                                        HealthCheck healthCheck);

}