Class RollingFileMessageWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, MessageWriter

    public class RollingFileMessageWriter
    extends java.lang.Object
    implements MessageWriter
    A simple rolling file message writer in the same manner that logging often does, e.g. the 'RollingFileAppender' from lockback.

    the message writer MUST be assigned a rolling policy, and MAY be assigned a cleanup policy. Note that the cleanup policy will only be triggered when the rolling policy triggers a file update.

    Also note that the RollingFileMessageWriter is NOT thread safe. So if you need to write to the message writer from multiple threads, you will either have to synchronize the calls yourself, or use the QueuedMessageWriter.

    • Constructor Detail

      • RollingFileMessageWriter

        public RollingFileMessageWriter​(@Nonnull
                                        java.io.File directory,
                                        @Nonnull
                                        Serializer serializer,
                                        @Nonnull
                                        java.lang.String currentName,
                                        @Nonnull
                                        RollingFileMessageWriter.RollingPolicy rollingPolicy)
        Create a rolling file message writer without a cleanup policy.
        Parameters:
        directory - The directory to place the message files into.
        serializer - The message serializer to use.
        currentName - The name of the current file symbolic link.
        rollingPolicy - The rolling policy.
      • RollingFileMessageWriter

        public RollingFileMessageWriter​(@Nonnull
                                        java.io.File directory,
                                        @Nonnull
                                        Serializer serializer,
                                        @Nonnull
                                        java.lang.String currentName,
                                        @Nonnull
                                        RollingFileMessageWriter.RollingPolicy rollingPolicy,
                                        @Nullable
                                        RollingFileMessageWriter.CleanupPolicy cleanupPolicy)
        Create a rolling file message writer.
        Parameters:
        directory - The directory to place the message files into.
        serializer - The message serializer to use.
        currentName - The name of the current file symbolic link.
        rollingPolicy - The rolling policy.
        cleanupPolicy - Optional cleanup policy.
    • Method Detail

      • write

        public <Message extends PMessage<Message,Field>,Field extends PField> int write​(Message message)
                                                                                 throws java.io.IOException
        Description copied from interface: MessageWriter
        Write a providence message to the writer.
        Specified by:
        write in interface MessageWriter
        Type Parameters:
        Message - The message type.
        Field - The field type.
        Parameters:
        message - The message to write.
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException - If write failed.
      • write

        public <Message extends PMessage<Message,Field>,Field extends PField> int write​(PServiceCall<Message,Field> call)
                                                                                 throws java.io.IOException
        Description copied from interface: MessageWriter
        Write a providence service call to the writer.
        Specified by:
        write in interface MessageWriter
        Type Parameters:
        Message - The message type embedded in the call.
        Field - The field type embedded in the call.
        Parameters:
        call - The service call to write.
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException - If write failed.
      • separator

        public int separator()
                      throws java.io.IOException
        Description copied from interface: MessageWriter
        Write an entry separator to the writer.
        Specified by:
        separator in interface MessageWriter
        Returns:
        The number of bytes written.
        Throws:
        java.io.IOException - If write failed.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException