Package net.morimekta.providence.logging
Class RollingFileMessageWriter
- java.lang.Object
-
- net.morimekta.providence.logging.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRollingFileMessageWriter.CleanupPolicyInterface for cleanup policy implementations.static interfaceRollingFileMessageWriter.CurrentFileUpdaterInterface for calling back to the rolling file message writen when a file roll is supposed to happen.static interfaceRollingFileMessageWriter.RollingPolicyInterface for rolling policy implementations.
-
Constructor Summary
Constructors Constructor Description RollingFileMessageWriter(java.io.File directory, net.morimekta.providence.serializer.Serializer serializer, java.lang.String currentName, RollingFileMessageWriter.RollingPolicy rollingPolicy)Create a rolling file message writer without a cleanup policy.RollingFileMessageWriter(java.io.File directory, net.morimekta.providence.serializer.Serializer serializer, java.lang.String currentName, RollingFileMessageWriter.RollingPolicy rollingPolicy, RollingFileMessageWriter.CleanupPolicy cleanupPolicy)Create a rolling file message writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()intseparator()Write an entry separator to the writer.<Message extends net.morimekta.providence.PMessage<Message>>
intwrite(net.morimekta.providence.PMessageOrBuilder<Message> message)Write a providence message to the writer.<Message extends net.morimekta.providence.PMessage<Message>>
intwrite(net.morimekta.providence.PServiceCall<Message> call)Write a providence service call to the writer.
-
-
-
Constructor Detail
-
RollingFileMessageWriter
public RollingFileMessageWriter(@Nonnull java.io.File directory, @Nonnull net.morimekta.providence.serializer.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 net.morimekta.providence.serializer.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 net.morimekta.providence.PMessage<Message>> int write(net.morimekta.providence.PMessageOrBuilder<Message> message) throws java.io.IOExceptionDescription copied from interface:MessageWriterWrite a providence message to the writer.- Specified by:
writein interfaceMessageWriter- Type Parameters:
Message- The message type.- Parameters:
message- The message to write.- Returns:
- The number of bytes written.
- Throws:
java.io.IOException- If write failed.
-
write
public <Message extends net.morimekta.providence.PMessage<Message>> int write(net.morimekta.providence.PServiceCall<Message> call) throws java.io.IOExceptionDescription copied from interface:MessageWriterWrite a providence service call to the writer.- Specified by:
writein interfaceMessageWriter- Type Parameters:
Message- The message 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()
Description copied from interface:MessageWriterWrite an entry separator to the writer.- Specified by:
separatorin interfaceMessageWriter- Returns:
- The number of bytes written.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-