Created
March 12, 2013 17:25
-
-
Save abdullin/5144972 to your computer and use it in GitHub Desktop.
Trying to figure out projection semantics
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
void Main() | |
{ | |
dynamic processor = null; | |
bool stopRequested; | |
while(!stopRequested) | |
{ | |
var checkpoint = 0; | |
if (chekpoint = 0) | |
{ | |
processor.Clear(); | |
} | |
foreach (var e in processor.ReadEvents(checkpoint, 1000)) | |
{ | |
} | |
} | |
} | |
public interface IEventStore | |
{ | |
} | |
public interface IRawKeyValueStore | |
{ | |
void Put(string bucket, string id, byte[] data); | |
void Update(string bucket, string id, Func<byte[],byte[]> update); | |
void Delete(string bucket, string id); | |
byte[] TryGet(string bucket, string id); | |
} | |
public interface IRawListStore | |
{ | |
void Append(string bucket, IEnumerable<KeyValuePair<string,byte[]>> records); | |
void Compact(string bucket); | |
void Delete(string bucket); | |
} | |
sealed class MyProjection : IProjection | |
{ | |
IEventStore events; | |
IDocumentStore docs; | |
public long ProcessNext(long checkpoint) | |
{ | |
if (checkpoint == 0) | |
{ | |
docs.CreateBucket(ProjectionName); | |
} | |
// no batching now | |
var es = store.ReadAll(checkpoint, 1); | |
if (es.Count > 0) | |
{ | |
this.When(es[0]); | |
return es.Checkpoint; | |
} | |
return checkpoint; | |
} | |
public void When(AccountCreated e) | |
{ | |
docs.Put(ProjectionName, e.AccountId, new AccountView()); | |
} | |
public void When(AccountRenamed e) | |
{ | |
docs.Update(ProjectionName, e.AccountId, a => a.Name = e.Name); | |
} | |
public string ProjectionName { get { return "my-projection"; } } | |
void Clear() | |
{ | |
docs.ClearBucket(ProjectionName); | |
} | |
} | |
public interface IProjection | |
{ | |
void Clear(); | |
long ProcessNext(long checkpoint); | |
string ProjectionName { get; } | |
} | |
// Define other methods and classes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment