These are chat archives for petabridge/akka-bootcamp

31st
Aug 2015
Alan Rutter
@AlanGRutter
Aug 31 2015 02:42
In the docs for Consistent Hash Router, the example given uses Customer Id as the hash key. A consistent hash pool will auto create actors based off this key. How would you deal with the scenario that a Customer Id may not exist any more - where you want the pool child actor to die? Additionally is there a way to find out how many active children the pool has so that the parent can terminate if required.
Andrei Marculescu
@andreimarculescu
Aug 31 2015 14:05
This message was deleted
Andrei Marculescu
@andreimarculescu
Aug 31 2015 14:11

feedback from Lesson 1.2. The method GetAndValidateInput from ConsoleReaderActor seems bit awkward to me, so I rewrote it in a way that seems more logical and that avoids a useless level of indirection.

private void GetAndValidateInput()
{
var message = Console.ReadLine();
if (string.IsNullOrEmpty(message))
{
// signal that the user needs to supply an input, as previously
// received input was blank
Self.Tell(new Messages.NullInputError("No input received."));
}
else if (String.Equals(message, ExitCommand, StringComparison.OrdinalIgnoreCase))
{
// shut down the entire actor system (allows the process to exit)
Context.System.Shutdown();
}
else
{
var valid = IsValid(message);
if (valid)
{
_consoleWriterActor.Tell(new Messages.InputSuccess("Thank you! Message was valid."));

        // continue reading messages from console
        Self.Tell(new Messages.ContinueProcessing());
    }
    else
    {
        Self.Tell(new Messages.ValidationError("Invalid: input had odd number of characters."));
    }
}

}

The two code lines which send errors to Self seem wrong because the reader actor doesn't handle these message types, but it sends them to itself rather than to the writer actor.

I rewrote the method like this:

   private void GetAndValidateInput()
    {
        var message = Console.ReadLine();
        if (string.IsNullOrEmpty(message))
        {
            // signal that the user needs to supply an input, as previously
            // received input was blank
            _consoleWriterActor.Tell(new Messages.NullInputError("No input received."));
        }
        else if (String.Equals(message, ExitCommand, StringComparison.OrdinalIgnoreCase))
        {
            // shut down the entire actor system (allows the process to exit)
            Context.System.Shutdown();
        }
        else
        {
            var valid = IsValid(message);
            if (valid)
            {
                _consoleWriterActor.Tell(new Messages.InputSuccess("Thank you! Message was valid."));
            }
            else
            {
                _consoleWriterActor.Tell(new Messages.ValidationError("Invalid: input had odd number of characters."));
            }
        }

        // continue reading messages from console
        Self.Tell(new Messages.ContinueProcessing());
    }

This also simplifies the code in ConsoleReaderActor.OnReceived and responsibilities are clearly distributed between the two actors. Here is the new method ConsoleReaderActor.OnReceived:
protected override void OnReceive(object message)
{
if (message.Equals(StartCommand))
{
DoPrintInstructions();
}

        GetAndValidateInput();
    }