Exemplo n.º 1
0
int main()
{
    Theron::Receiver receiver;
    Theron::Address printerAddress;

    // Create a framework and register a fallback handler with it.
    Theron::Framework framework;
    FallbackHandler fallbackHandler;
    framework.SetFallbackHandler(&fallbackHandler, &FallbackHandler::Handle);

    {
        // Create a printer actor within a local scope and remember its address.
        Printer printer(framework);
        printerAddress = printer.GetAddress();

        // Send the printer a message of a type which it doesn't handle.
        // This message reaches the printer but is handled by its default handler.
        framework.Send(103, receiver.GetAddress(), printerAddress);

        // Send the printer a string message to show that it actually works.
        framework.Send(std::string("hit"), receiver.GetAddress(), printerAddress);

        // Wait for the reply to the handled string message, for synchronization.
        receiver.Wait();
    }

    // Send a string message to the printer's address, which is now stale.
    // This message never reaches an actor so is handled by the fallback handler.
    framework.Send(std::string("miss"), receiver.GetAddress(), printerAddress);
}
Exemplo n.º 2
0
int main()
{
    Theron::Framework framework;
    Theron::ActorRef actor(framework.CreateActor<Example::SimpleActor>());
    Theron::Receiver receiver;

    // Send the actor one message of each kind.
    if (!framework.Send(Example::FloatMessage(5.0f), receiver.GetAddress(), actor.GetAddress()))
    {
        printf("Failed to send message!\n");
    }

    if (!framework.Send(Example::IntegerMessage(6), receiver.GetAddress(), actor.GetAddress()))
    {
        printf("Failed to send message!\n");
    }

    // Wait for both reply messages before terminating.
    receiver.Wait();
    receiver.Wait();

    printf("Received two reply messages\n");
    return 0;
}
Exemplo n.º 3
0
int main()
{
    Theron::Framework framework;
    Theron::ActorRef actor(framework.CreateActor<Catcher>());

    // Create a message and fill it with some values.
    IntegerVector message;
    message.push_back(4);
    message.push_back(7);
    message.push_back(2);

    // Send the message to the catcher, passing the address of a local receiver
    // as the 'from' address. Note that the message is copied during message
    // passing, including all of its contents. See the EnvelopeMessages sample
    // for a workaround that avoids this overhead.
    Theron::Receiver receiver;
    framework.Send(message, receiver.GetAddress(), actor.GetAddress());

    // Wait for confirmation that the message was received before terminating.
    receiver.Wait();

    return 0;
}