Skip to content

Instantly share code, notes, and snippets.

View odeheurles's full-sized avatar

Olivier Deheurles odeheurles

View GitHub Profile
@odeheurles
odeheurles / RFQStates
Created June 21, 2014 07:47
Possible states for a RFQ
public enum RfqState
{
Input,
Requesting,
Cancelling,
Cancelled,
Quoted,
Executing,
Error,
Done
@odeheurles
odeheurles / RfqEvent
Created June 21, 2014 07:49
Possible RFQ Events
public enum RfqEvent
{
UserRequests,
UserCancels,
UserExecutes,
ServerNewQuote,
ServerQuoteError,
ServerQuoteStreamComplete,
ServerSendsExecutionReport,
@odeheurles
odeheurles / StronglyTypedEvent
Created June 21, 2014 07:50
Defining a strongly typed event
_rfqEventServerSendsQuote = _stateMachine.SetTriggerParameters<IQuote>(RfqEvent.ServerNewQuote);
@odeheurles
odeheurles / RFQTransitions
Created June 21, 2014 07:51
Defining RFQ Transitions
_stateMachine.Configure(RfqState.Input)
.Permit(RfqEvent.UserRequests, RfqState.Requesting);
_stateMachine.Configure(RfqState.Requesting)
.Permit(RfqEvent.ServerNewQuote, RfqState.Quoted)
.Permit(RfqEvent.UserCancels, RfqState.Cancelling)
.Permit(RfqEvent.InternalError, RfqState.Error);
_stateMachine.Configure(RfqState.Quoted)
.PermitReentry(RfqEvent.ServerNewQuote)
@odeheurles
odeheurles / FireEvent
Created June 25, 2014 10:45
Fire an event to the state machine
// for an event without parameters
_stateMachine.Fire(RfqEvent.ServerQuoteStreamComplete)
// for a strongly typed event
_stateMachine.Fire(_rfqEventServerSendsExecutionReport, executionReport)
@odeheurles
odeheurles / DefiningActions
Created June 25, 2014 10:47
Defining actions
_stateMachine.Configure(RfqState.Requesting)
.OnEntry(LogTransition)
.OnEntryFrom(_rfqEventUserRequests, OnEntryRequesting)
.Permit(RfqEvent.ServerNewQuote, RfqState.Quoted)
.Permit(RfqEvent.UserCancels, RfqState.Cancelling)
.Permit(RfqEvent.InternalError, RfqState.Error);
private void OnEntryRequesting(IQuoteRequest quoteRequest)
{
// here goes the code to send a quote request to the server
@odeheurles
odeheurles / ErrorHandling
Created June 25, 2014 10:48
Error handling
_stateMachine.OnUnhandledTrigger(OnUnhandledTrigger);
private void OnUnhandledTrigger(RfqState state, RfqEvent trigger)
{
var message = string.Format("State machine received an invalid trigger '{0}' in state '{1}'", trigger, state);
Console.WriteLine(message);
_rfqUpdateSubject.OnError(new ApplicationException(message));
}
public interface IRfq : IDisposable
{
void RequestQuote(IQuoteRequest quoteRequest);
void Cancel(long rfqId);
void Execute(IExecutionRequest quote);
IObservable<RfqUpdate> Updates { get; }
}
@odeheurles
odeheurles / Assembly optimized
Created December 14, 2013 10:49
Example of inlining with Simple Binary Encoding
80: car.SerialNumber = 1234;
mov edx,dword ptr [esi+8]
mov ecx,dword ptr [esi+18h]
mov eax,dword ptr [edx+8]
mov dword ptr [eax+ecx],4D2h
81: car.ModelYear = 2013;
mov edx,dword ptr [esi+8]
mov ecx,dword ptr [esi+18h]
add ecx,4
mov eax,dword ptr [edx+8]
private static int Encode(Car car, DirectBuffer directBuffer, int bufferOffset)
{
...
car.SerialNumber = 1234;
car.ModelYear = 2013;
car.Available = BooleanType.TRUE;
car.Code = Model.A;
...
}