Package net.morimekta.providence.mio
Class RollingFileMessageWriter
- java.lang.Object
-
- net.morimekta.providence.mio.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 interface
RollingFileMessageWriter.CleanupPolicy
Interface for cleanup policy implementations.static interface
RollingFileMessageWriter.CurrentFileUpdater
Interface for calling back to the rolling file message writen when a file roll is supposed to happen.static interface
RollingFileMessageWriter.RollingPolicy
Interface for rolling policy implementations.
-
Constructor Summary
Constructors Constructor Description RollingFileMessageWriter(java.io.File directory, Serializer serializer, java.lang.String currentName, RollingFileMessageWriter.RollingPolicy rollingPolicy)
Create a rolling file message writer without a cleanup policy.RollingFileMessageWriter(java.io.File directory, 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 void
close()
int
separator()
Write an entry separator to the writer.<Message extends PMessage<Message,Field>,Field extends PField>
intwrite(Message message)
Write a providence message to the writer.<Message extends PMessage<Message,Field>,Field extends PField>
intwrite(PServiceCall<Message,Field> call)
Write a providence service call to the writer.
-
-
-
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 interfaceMessageWriter
- 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 interfaceMessageWriter
- 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 interfaceMessageWriter
- 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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
-