class JobRegistrySmartInitializingSingleton
		implements SmartInitializingSingleton, BeanFactoryAware, InitializingBean, DisposableBean {

	private static final Log logger = LogFactory.getLog(JobRegistrySmartInitializingSingleton.class);

	// It doesn't make sense for this to have a default value...
	private JobRegistry jobRegistry = null;

	private final Collection<String> jobNames = new HashSet<>();

	private String groupName = null;

	private ListableBeanFactory beanFactory;

	/**
	 * Default constructor.
	 */
	public JobRegistrySmartInitializingSingleton() {
	}

	/**
	 * Convenience constructor for setting the {@link JobRegistry}.
	 * @param jobRegistry the {@link JobRegistry} to register the {@link Job}s with
	 */
	public JobRegistrySmartInitializingSingleton(JobRegistry jobRegistry) {
		this.jobRegistry = jobRegistry;
	}

	/**
	 * The group name for jobs registered by this component. Optional (defaults to null,
	 * which means that jobs are registered with their bean names). Useful where there is
	 * a hierarchy of application contexts all contributing to the same
	 * {@link JobRegistry}: child contexts can then define an instance with a unique group
	 * name to avoid clashes between job names.
	 * @param groupName the groupName to set
	 */
	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	/**
	 * Injection setter for {@link JobRegistry}.
	 * @param jobRegistry the {@link JobRegistry} to register the {@link Job}s with
	 */
	public void setJobRegistry(JobRegistry jobRegistry) {
		this.jobRegistry = jobRegistry;
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		if (beanFactory instanceof ListableBeanFactory listableBeanFactory) {
			this.beanFactory = listableBeanFactory;
		}
	}

	/**
	 * Make sure the registry is set before use.
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.state(jobRegistry != null, "JobRegistry must not be null");
	}

	/**
	 * Unregister all the {@link Job} instances that were registered by this smart
	 * initializing singleton.
	 */
	@Override
	public void destroy() throws Exception {<FILL_FUNCTION_BODY>}

	@Override
	public void afterSingletonsInstantiated() {
		if (beanFactory == null) {
			return;
		}
		Map<String, Job> jobs = beanFactory.getBeansOfType(Job.class, false, false);
		for (var entry : jobs.entrySet()) {
			postProcessAfterInitialization(entry.getValue(), entry.getKey());
		}
	}

	private void postProcessAfterInitialization(Job job, String beanName) {
		try {
			String groupName = this.groupName;
			if (beanFactory instanceof DefaultListableBeanFactory defaultListableBeanFactory
					&& beanFactory.containsBean(beanName)) {
				groupName = getGroupName(defaultListableBeanFactory.getBeanDefinition(beanName), job);
			}
			job = groupName == null ? job : new GroupAwareJob(groupName, job);
			ReferenceJobFactory jobFactory = new ReferenceJobFactory(job);
			String name = jobFactory.getJobName();
			if (logger.isDebugEnabled()) {
				logger.debug("Registering job: " + name);
			}
			jobRegistry.register(jobFactory);
			jobNames.add(name);
		}
		catch (DuplicateJobException e) {
			throw new FatalBeanException("Cannot register job configuration", e);
		}
	}

	/**
	 * Determine a group name for the job to be registered. The default implementation
	 * returns the {@link #setGroupName(String) groupName} configured. Provides an
	 * extension point for specialised subclasses.
	 * @param beanDefinition the bean definition for the job
	 * @param job the job
	 * @return a group name for the job (or null if not needed)
	 */
	protected String getGroupName(BeanDefinition beanDefinition, Job job) {
		return groupName;
	}

}

		for (String name : jobNames) {
			if (logger.isDebugEnabled()) {
				logger.debug("Unregistering job: " + name);
			}
			jobRegistry.unregister(name);
		}
		jobNames.clear();
	
<no_super_class>