-
Notifications
You must be signed in to change notification settings - Fork 612
NMS-8099: MailTransportMonitor steps all over itself #8212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,7 +96,7 @@ public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { | |||||
| } | ||||||
|
|
||||||
| parseJavaMailProperties(mailParms); | ||||||
| status = doMailTest(mailParms); | ||||||
| status = doMailTest(mailParms, svc.getNodeId()); | ||||||
| } catch (final IllegalStateException ise) { | ||||||
| //ignore this because we don't have to have both a send and read | ||||||
|
|
||||||
|
|
@@ -134,10 +134,10 @@ private void parseJavaMailProperties(final MailTransportParameters mailParms) { | |||||
| * | ||||||
| * @param mailParms | ||||||
| */ | ||||||
| private PollStatus doMailTest(final MailTransportParameters mailParms) { | ||||||
| private PollStatus doMailTest(final MailTransportParameters mailParms, final int nodeId) { | ||||||
| final long beginPoll = System.currentTimeMillis(); | ||||||
| PollStatus status = PollStatus.unknown("Beginning poll."); | ||||||
| mailParms.setTestSubjectSuffix(Long.toString(beginPoll)); | ||||||
| mailParms.setTestSubjectSuffix(Integer.toString(nodeId) + ": " + Long.toString(beginPoll)); | ||||||
|
|
||||||
| /* | ||||||
| * If both a send and receive test are configured, then were testing the | ||||||
|
|
@@ -151,19 +151,19 @@ private PollStatus doMailTest(final MailTransportParameters mailParms) { | |||||
| * matching. | ||||||
| */ | ||||||
| mailParms.setEnd2EndTestInProgress(true); | ||||||
| status = sendTestMessage(mailParms); | ||||||
| status = sendTestMessage(mailParms, nodeId); | ||||||
|
|
||||||
| if (status.isAvailable()) { | ||||||
| LOG.debug("doMailTest: send test successful."); | ||||||
| status = readTestMessage(mailParms); | ||||||
| status = readTestMessage(mailParms, nodeId); | ||||||
| } else { | ||||||
| LOG.info("doMailTest: send test unsuccessful... skipping read portion of test."); | ||||||
| } | ||||||
|
|
||||||
| } else if (mailParms.getReadTest() != null) { | ||||||
| status = readTestMessage(mailParms); | ||||||
| status = readTestMessage(mailParms, nodeId); | ||||||
| } else if (mailParms.getSendTest() != null) { | ||||||
| status = sendTestMessage(mailParms); | ||||||
| status = sendTestMessage(mailParms, nodeId); | ||||||
| } else { | ||||||
| throw new IllegalArgumentException("MailTransportMonitor requires either send-host or read-host parameters"); | ||||||
| } | ||||||
|
|
@@ -175,7 +175,7 @@ private PollStatus doMailTest(final MailTransportParameters mailParms) { | |||||
| return status; | ||||||
| } | ||||||
|
|
||||||
| private PollStatus readTestMessage(final MailTransportParameters mailParms) { | ||||||
| private PollStatus readTestMessage(final MailTransportParameters mailParms, final int nodeId) { | ||||||
| LOG.debug("readTestMessage: Beginning read mail test."); | ||||||
| PollStatus status = PollStatus.unavailable("Test not completed."); | ||||||
|
|
||||||
|
|
@@ -221,7 +221,7 @@ private PollStatus readTestMessage(final MailTransportParameters mailParms) { | |||||
| } | ||||||
| } | ||||||
| if (mailFolder.isOpen() && (mailParms.getReadTest().getSubjectMatch() != null || mailParms.isEnd2EndTestInProgress())) { | ||||||
| status = processMailSubject(mailParms, mailFolder); | ||||||
| status = processMailSubject(mailParms, mailFolder, nodeId); | ||||||
| if (status.getStatusCode() == PollStatus.SERVICE_AVAILABLE) { | ||||||
| break; | ||||||
| } | ||||||
|
|
@@ -268,14 +268,14 @@ private void closeStore(final Store mailStore, final Folder mailFolder) { | |||||
| * @return a PollStatus indicative of the success of matching a subject or just retieving | ||||||
| * mail folder contents... dependent on configuration. | ||||||
| */ | ||||||
| private PollStatus processMailSubject(final MailTransportParameters mailParms, final Folder mailFolder) { | ||||||
| private PollStatus processMailSubject(final MailTransportParameters mailParms, final Folder mailFolder, final int nodeId) { | ||||||
| PollStatus status = PollStatus.unknown(); | ||||||
| try { | ||||||
| final String subject = computeMatchingSubject(mailParms); | ||||||
| if (mailFolder.isOpen() && subject != null) { | ||||||
| final Message[] mailMessages = mailFolder.getMessages(); | ||||||
| final SearchTerm searchTerm = new SubjectTerm(subject); | ||||||
| final SearchTerm deleteTerm = new HeaderTerm(MTM_HEADER_KEY, m_headerValue); | ||||||
| final SearchTerm deleteTerm = new HeaderTerm(MTM_HEADER_KEY, m_headerValue + "-" + nodeId); | ||||||
|
||||||
|
|
||||||
| LOG.debug("searchMailSubject: searching {} message(s) for subject '{}'", mailMessages.length, subject); | ||||||
|
|
||||||
|
|
@@ -298,18 +298,20 @@ private PollStatus processMailSubject(final MailTransportParameters mailParms, f | |||||
|
|
||||||
| final boolean deleteAllMail = mailParms.getReadTest().getDeleteAllMail(); | ||||||
| final boolean foundMTMHeader = mailMessage.match(deleteTerm); | ||||||
| LOG.debug("searchMailSubject: deleteAllMail = {}, MTM header found = {}", Boolean.toString(deleteAllMail), Boolean.toString(foundMTMHeader)); | ||||||
| LOG.debug("searchMailSubject: deleteAllMail = {}, MTM header found = {}, delete = {}", deleteAllMail, foundMTMHeader, delete); | ||||||
|
||||||
| LOG.debug("searchMailSubject: deleteAllMail = {}, MTM header found = {}, delete = {}", deleteAllMail, foundMTMHeader, delete); | |
| LOG.debug("searchMailSubject: deleteAllMail = {}, MTM header found = {}, delete = {}", Boolean.toString(deleteAllMail), Boolean.toString(foundMTMHeader), Boolean.toString(delete)); |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting the delete flag to false after each deletion is incorrect logic. The delete flag should remain true once set by deleteAllMail or foundMTMHeader conditions. This reset would cause only the first matching message to be deleted when deleteAllMail is true, leaving subsequent messages undeleted.
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space before the '-' concatenation operator. Should be: m_headerValue + "-" + nodeId for consistency with line 278.
| sendMailer.addExtraHeader(MTM_HEADER_KEY, m_headerValue+ "-" + nodeId); | |
| sendMailer.addExtraHeader(MTM_HEADER_KEY, m_headerValue + "-" + nodeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string concatenation should use String.format() or StringBuilder for better readability and maintainability, especially since this is building a composite identifier. Consider: String.format("%d: %d", nodeId, beginPoll)