Class MessageContainer

    • Field Detail

      • MESSAGE_TIME_COMPARATOR

        protected static final Comparator<Message> MESSAGE_TIME_COMPARATOR
        Used to sort messages by their time.
      • log

        @Nullable
        protected transient volatile @Nullable org.slf4j.Logger log
        A logger where add(Message) automatically logs to.
      • lockObject

        protected final transient Object lockObject
        Synchronizing on this when accessing messages.
    • Constructor Detail

      • MessageContainer

        public MessageContainer()
        Default constructor which means we do not log added messages - usually it's better to use MessageContainer(Logger) and log things immediately.
      • MessageContainer

        public MessageContainer​(@Nullable
                                @Nullable org.slf4j.Logger log)
        Constructor that allows to set a logger to which add(Message) automatically writes the messages.
        Parameters:
        log - an optional log to which added messages are logged.
    • Method Detail

      • getMessages

        @NotNull
        public @NotNull List<Message> getMessages()
        A (unmodifiable) snapshot of the list of messages.
      • add

        @NotNull
        public @NotNull MessageContainer add​(@Nullable
                                             @Nullable Message message,
                                             @Nullable
                                             @Nullable Throwable throwable)
        Adds a message to the container, and logs it into the logger if one was specified for this container. The intended usecase is with a logger, so we log a warning if it's called with a throwable but we have no logger, so that Stacktraces don't disappear accidentially.
        Returns:
        this MessageContainer, for builder-style operation chaining.
      • add

        @NotNull
        public @NotNull MessageContainer add​(@Nullable
                                             @Nullable Message message)
        Adds a message to the container, and logs it into the logger if one was specified for this container. Like in SLF4J, if the last argument is a Throwable we use it for logging with add(Message, Throwable).
        Returns:
        this MessageContainer, for builder-style operation chaining.
      • logInto

        public void logInto​(@Nullable
                            @Nullable org.slf4j.Logger logger)
        Logs the messages into the given container. This is automatically done on add(Message) if a logger is set, but this might be necessary after deserializing the container.
      • clear

        @NotNull
        public @NotNull MessageContainer clear()
        Removes all messages.
        Returns:
        this MessageContainer, for builder-style operation chaining.
      • isEmpty

        public boolean isEmpty()
        Whether there are any messages.