private UntypedReceive Active(IActorRef consumer)
{
return message =>
{
message.Match()
.With<UnregisterConsumer>(_ =>
{
if (Sender.Equals(consumer))
{
_log.Info("Unregistration ok: [{0}]", Sender.Path);
Sender.Tell(UnregistrationOk.Instance);
Context.Become(Idle);
}
else
{
_log.Info("Unexpected unregistration: [{0}], expected: [{1}]", Sender.Path, consumer.Path);
Sender.Tell(UnexpectedUnregistration.Instance);
Context.Stop(Self);
}
})
.With<RegisterConsumer>(_ =>
{
_log.Info("Unexpected registration: [{0}], active consumer: [{1}]", Sender.Path, consumer.Path);
Sender.Tell(UnexpectedRegistration.Instance);
Context.Stop(Self);
})
.With<Reset>(_ =>
{
Context.Become(Idle);
Sender.Tell(ResetOk.Instance);
})
.Default(m => Sender.Tell(m));
};
}