Blame | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.mail;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;/*** Bridges the static mail helpers in Utils to the Spring-managed {@link MailQueue}.** This is a deliberate compromise, not a pattern to copy. Utils.sendMail* are* static and called from 27 places, several of them static contexts that have no* bean to inject into. Converting all of them at once would be a large,* mechanical, and risky change to code paths that send real money-related* reports. Holding the queue in one place instead lets those helpers stop* sending inline today, and lets the call sites move at their own pace.** New code must inject {@link MailQueue} directly. Nothing except Utils should* read this.*/@Componentpublic final class MailQueueHolder {private static final Logger LOGGER = LogManager.getLogger(MailQueueHolder.class);private static volatile MailQueue mailQueue;@Autowiredpublic void setMailQueue(MailQueue queue) {mailQueue = queue;}/*** Returns null before the context has finished starting. Callers must handle* that rather than assume — a mail sent during startup is better dropped with* a log line than allowed to NPE inside a scheduled job.*/public static MailQueue get() {if (mailQueue == null) {LOGGER.warn("MailQueue requested before the Spring context supplied one; mail dropped");}return mailQueue;}}