@Override public void service(Mail mail) throws MessagingException { metric.increment(); }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { super.messageReceived(ctx, e); smtpMetrics.getCommandsMetric().increment(); }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { super.channelConnected(ctx, e); smtpMetrics.getConnectionMetric().increment(); }
@VisibleForTesting void attemptDelivery(Mail mail) throws MailQueue.MailQueueException { ExecutionResult executionResult = mailDelivrer.deliver(mail); switch (executionResult.getExecutionState()) { case SUCCESS: outgoingMailsMetric.increment(); break; case TEMPORARY_FAILURE: handleTemporaryFailure(mail, executionResult); break; case PERMANENT_FAILURE: bouncer.bounce(mail, executionResult.getException().orElse(null)); break; } }
@Override public void storeMail(MailAddress recipient, Mail mail) throws MessagingException { String username = computeUsername(recipient); String locatedFolder = locateFolder(username, mail); ComposedMessageId composedMessageId = mailboxAppender.append(mail.getMessage(), username, locatedFolder); metric.increment(); LOGGER.info("Local delivered mail {} successfully from {} to {} in folder {} with composedMessageId {}", mail.getName(), mail.getMaybeSender().asString(), recipient.asPrettyString(), locatedFolder, composedMessageId); }
@Test public void deliverySuccessShouldIncrementMetric() throws Exception { FakeMail fakeMail = FakeMail.defaultFakeMail(); when(mailDelivrer.deliver(fakeMail)).thenReturn(ExecutionResult.success()); testee.attemptDelivery(fakeMail); verify(outgoingMailsMetric).increment(); verifyNoMoreInteractions(outgoingMailsMetric); }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { try (Closeable closeable = IMAPMDCContext.from(ctx, attributes)) { InetSocketAddress address = (InetSocketAddress) ctx.getChannel().getRemoteAddress(); LOGGER.info("Connection established from {}", address.getAddress().getHostAddress()); imapConnectionsMetric.increment(); ImapResponseComposer response = new ImapResponseComposerImpl(new ChannelImapResponseWriter(ctx.getChannel())); ctx.setAttachment(response); // write hello to client response.untagged().message("OK").message(hello).end(); super.channelConnected(ctx, e); } }
dequeuedMailsMetric.increment(); return createMailQueueItem(session, consumer, message); } else {
@Override public void enQueue(Mail mail, long delay, TimeUnit unit) throws MailQueueException { TimeMetric timeMetric = metricFactory.timer(ENQUEUED_TIMER_METRIC_NAME_PREFIX + queueName); long nextDeliveryTimestamp = computeNextDeliveryTimestamp(delay, unit); try { int msgPrio = NORMAL_PRIORITY; Object prio = mail.getAttribute(MAIL_PRIORITY); if (prio instanceof Integer) { msgPrio = (Integer) prio; } Map<String, Object> props = getJMSProperties(mail, nextDeliveryTimestamp); produceMail(props, msgPrio, mail); enqueuedMailsMetric.increment(); } catch (Exception e) { throw new MailQueueException("Unable to enqueue mail " + mail, e); } finally { timeMetric.stopAndPublish(); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { try (Closeable closeable = IMAPMDCContext.from(ctx, attributes)) { imapCommandsMetric.increment(); ImapSession session = (ImapSession) attributes.get(ctx.getChannel()); ImapResponseComposer response = (ImapResponseComposer) ctx.getAttachment();
@Test public void serviceShouldIncrementMetricCounter() throws Exception { mailet.init(FakeMailetConfig.builder() .mailetName(MAILET_NAME) .setProperty(MetricsMailet.METRIC_NAME, "metricName") .build()); mailet.service(FakeMail.builder().build()); verify(metric).increment(); verifyNoMoreInteractions(metric); }