Created
November 4, 2014 13:11
-
-
Save rofr/c2e8f78100080ea584e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Journaler : IEventHandler<BufferEntry> | |
{ | |
private BufferEntry[] _buffer = new BufferEntry[1024]; | |
private int _current; | |
private IJournalWriter _journal; | |
public Journaler(IJournalWriter journal) | |
{ | |
_journal = journal; | |
} | |
public void OnNext(BufferEntry data, long sequence, bool endOfBatch) | |
{ | |
_buffer[_current++] = data; | |
if (endOfBatch) Process(); | |
} | |
private void Process() | |
{ | |
var commands = _buffer.Take(_current).Select(e => e.Transaction as Command); | |
_journal.AppendAsync(commands).Wait(); | |
_current = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment