All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.kencochrane.raven.event.interfaces.MessageInterface Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
package net.kencochrane.raven.event.interfaces;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * The Message interface for Sentry allows to send the original pattern to Sentry, allowing the events to be grouped
 * by original message (rather than the formatted version).
 * 

* Sentry's ability to regroup event with the same messages is based on the content of the message, meaning that an * {@link net.kencochrane.raven.event.Event} with the message "User1 failed to provide an email address" * won't be grouped with an Event with the message "User2 failed to provide an email address". *

* To allow this kind of grouping, sentry supports the message interface which will provide both the pattern of the * message and the parameters. In this example the pattern could be:
* {} failed to provide an email address
* And the parameters would be User1 in the first Event and User2 in the second Event.
* This way, Sentry will be able to put the two events in the same category. *

* Note: Sentry won't attempt to format the message, this is why the formatted message should be set through * {@link net.kencochrane.raven.event.EventBuilder#setMessage(String)} in any case. */ public class MessageInterface implements SentryInterface { /** * Name of the message interface in Sentry. */ public static final String MESSAGE_INTERFACE = "sentry.interfaces.Message"; private final String message; private final List parameters; /** * Creates a non parametrised message. *

* While it's technically possible to create a non parametrised message with {@code MessageInterface}, it's * recommended to use {@link net.kencochrane.raven.event.EventBuilder#setMessage(String)} instead. * * @param message message to add to the event. * @deprecated Use {@link net.kencochrane.raven.event.EventBuilder#setMessage(String)} instead. */ @Deprecated public MessageInterface(String message) { this(message, Collections.emptyList()); } /** * Creates a parametrised message for an {@link net.kencochrane.raven.event.Event}. * * @param message original message. * @param params parameters of the message. */ public MessageInterface(String message, String... params) { this(message, Arrays.asList(params)); } /** * Creates a parametrised message for an {@link net.kencochrane.raven.event.Event}. * * @param message original message. * @param parameters parameters of the message. */ public MessageInterface(String message, List parameters) { this.message = message; this.parameters = Collections.unmodifiableList(new ArrayList<>(parameters)); } @Override public String getInterfaceName() { return MESSAGE_INTERFACE; } public String getMessage() { return message; } public List getParameters() { return parameters; } @Override public String toString() { return "MessageInterface{" + "message='" + message + '\'' + ", parameters=" + parameters + '}'; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MessageInterface that = (MessageInterface) o; return message.equals(that.message) && parameters.equals(that.parameters); } @Override public int hashCode() { return message.hashCode(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy