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
using(var orders = store.Subscriptions.Open<Order>(ordersSubscription, new SubscriptionConnectionOptions())) | |
{ | |
orders.Subscribe(order => | |
{ | |
GenerateInvoice(order); | |
}); | |
orders.Subscribe(order => | |
{ |
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
bool hasMoreWork = false; | |
do | |
{ | |
var sp = Stopwatch.StartNew(); | |
lock(lockObj) | |
{ | |
while(sp.ElapsedMilliseconds < 150) // don't hold the lock too long, let other people go in | |
{ | |
// do work and set hasMoreWork | |
} |
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
def OnJournalEntry(entry): | |
journal.AppendHash(entry) | |
journal.BufferedWrite(entry) | |
return if not entry.TransactionCommit | |
journal.WriteHash() | |
journal.ClearHash() |
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
def MergeTransactionThreadProc(): | |
buffer = Buffer() | |
while true: | |
buffer.Clear() | |
result = DequeueOperation() | |
if result.Success is false: | |
WaitForAdditionalOperations() |
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
def MergeTransactionThreadProc(): | |
while true: | |
buffer = Buffer() | |
result = DequeueOperation() | |
if result.Success is false: | |
WaitForAdditionalOperations() | |
continue | |
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 GraphDatabase | |
{ | |
long AddNode(NameValueCollection node); | |
long AddEdge(string type, long from, long to, NameValueCollection edge = null); | |
NameValueCollection GetNode(long id); | |
IEnumerable<Tuple<long, NameValueCollection>> GetEdgesFor(string type, long id); | |
} |
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 GraphDatabase | |
{ | |
private TableSchema _emptySchema = new TableSchema | |
{ | |
AllowNoIndexesOrPrimaryKey = true | |
}; | |
public GraphDatabase(StorageEnvironmentOptions options) | |
{ | |
_env = new StorageEnvironment(options); |
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 unsafe long AddNode(NameValueCollection node); | |
{ | |
using(var tx = _env.WriteTransaction() | |
{ | |
var nodesTable = new Table(_emptySchema, "Nodes", tx); | |
string serializedNode = SerializeNode(node); | |
byte[] data = Encoding.UTF8.GetBytes(serializedNode); | |
fixed(byte* pData = data) | |
{ | |
long id = nodesTable.Insert(new TableValueBuilder |
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 unsafe long AddEdge(string type, long from, long to, NameValueCollection edge = null) | |
{ | |
using(var tx = _env.WriteTransaction()) | |
{ | |
long edgeId = -1; | |
if(edge != null) | |
{ | |
var edgesDataTable = new Table(_emptySchema, "EdgesData", tx); | |
string serializededge = SerializeNode(edge); |
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 NameValueCollection GetNode(long id) | |
{ | |
using(var tx = _env.ReadTransaction()) | |
{ | |
var nodesTable = new Table(_emptySchema, "Nodes", tx); | |
var reader = new TableValueReader(table.DirectRead(id, out size), size); | |
var data = reader.Read(0, out size); | |
var nodeStr = Encoding.UTF8.GetString(data, size); | |
return ParseNode(nodeStr); |