Created
July 17, 2014 23:26
-
-
Save Aaronontheweb/4ecf3a11de54516163e9 to your computer and use it in GitHub Desktop.
Inline actor - defined solely using lamba functions and delegates
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
/// <summary> | |
/// A simple actor implementation that can be defined solely using lamba functions and delegates | |
/// </summary> | |
public class Actor : UntypedActor | |
{ | |
public Actor() | |
{ | |
Receive = message => base.Unhandled(message); | |
OnPreStart = () => base.PreStart(); | |
OnPostStop = () => base.PostStop(); | |
OnUnhandled = o => base.Unhandled(o); | |
OnPreRestart = (exception, o) => base.PreRestart(exception, o); | |
OnPostRestart = exception => base.PostRestart(exception); | |
} | |
public UntypedReceive Receive { get; set; } | |
public Action OnPostStop { get; set; } | |
public Action OnPreStart { get; set; } | |
public Action<object> OnUnhandled { get; set; } | |
public Action<Exception, object> OnPreRestart { get; set; } | |
public Action<Exception> OnPostRestart { get; set; } | |
protected override void PreStart() | |
{ | |
OnPreStart(); | |
} | |
protected override void PostStop() | |
{ | |
OnPostStop(); | |
} | |
protected override void Unhandled(object message) | |
{ | |
OnUnhandled(message); | |
} | |
protected override void PreRestart(Exception reason, object message) | |
{ | |
OnPreRestart(reason, message); | |
} | |
protected override void PostRestart(Exception reason) | |
{ | |
OnPostRestart(reason); | |
} | |
protected override void OnReceive(object message) | |
{ | |
Receive(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment