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);
}
Exemple #2
0
    bool response()
        {
  
            wchar_t langString[] = { 0x0440, 0x0443, 0x0441, 0x0441, 0x043a, 0x0438, 0x0439, 0x0000 };
            out << "Set-Cookie: lang=" << langString << '\n';
       
            out << "Content-Type: text/html; charset=utf-8\r\n\r\n";
       
            if(environment.posts.size())
            {
                std::map<std::string,std::string> params;
                for(Fastcgipp::Http::Environment<char>::Posts::iterator it=environment.posts.begin(); it!=environment.posts.end(); ++it)
                {

                    if(it->second.type==Fastcgipp::Http::Post<char>::form)
                    {
                        params.insert(std::make_pair(it->first,it->second.value));
                    }
                }
                std::map<std::string,std::string>::iterator fit=params.find("query");
                if(params.size()>0&&fit!=params.end())
                {
                    search::QueryInfo *qi=new search::QueryInfo();
                    qi->query=fit->second;
                    qi->vdb=std::string("news");
                    queryActor.Push(QueryMessage(qi,"null"), receiver.GetAddress());
                    receiver.Wait();
                    search::DocList &docs=qc.GetDocs();
                    std::cout<<"size:"<<docs.docList.size()<<std::endl;
                    xmlpp::Document doc;
                    xmlpp::Element* root=doc.create_root_node(Glib::ustring("DocumentList"));
                    
                    for(std::list<search::IndexInfo>::iterator it=docs.docList.begin();it!=docs.docList.end();++it)
                    {
                        xmlpp::Element* ele=root->add_child(Glib::ustring("Document"));
                        xmlpp::Element* uid=ele->add_child(Glib::ustring("Uid"));
                        xmlpp::Element* title=ele->add_child(Glib::ustring("Title"));
                        xmlpp::Element* content=ele->add_child(Glib::ustring("Content"));
                        uid->add_child_text(Glib::ustring(it->uid.c_str()));
                        content->add_child_text(Glib::ustring(it->content.c_str()));
                        title->add_child_text(Glib::ustring(it->attMap["title"].c_str()));
                    }
                    Glib::ustring docString=doc.write_to_string(Glib::ustring("utf-8"));
                    out << docString.c_str();
                }else
                {
                    out << "param error\n";
                }
            }
            else
                out << "No post data\n";
            return true;

        }
Exemple #3
0
int main(int argc, char *argv[])
{
    const char *filename = 0;
    if (argc > 1)
    {
        filename = argv[1];
    }

    if (filename == 0)
    {
        printf("No filename supplied. Use command line argument to supply one.\n");
        return 1;
    }

    printf("Reading file from path '%s'.\n", filename);

    Theron::Framework framework;
    Theron::ActorRef fileReader(framework.CreateActor<FileReader>());

    MessageCollector messageCollector;
    Theron::Receiver receiver;
    receiver.RegisterHandler(&messageCollector, &MessageCollector::Handler);

    // Allocate a buffer for the file data.
    const unsigned int MAX_FILE_SIZE = 65536;
    unsigned char fileBuffer[MAX_FILE_SIZE];

    // Send the actor a message to request the file read operation.
    ReadFileMessage readFileMessage;
    readFileMessage.mFilename = filename;
    readFileMessage.mBuffer = fileBuffer;
    readFileMessage.mBufferSize = MAX_FILE_SIZE;

    fileReader.Push(readFileMessage, receiver.GetAddress());

    // Wait for a reply message indicating the file has been read.
    // This is a blocking call and so prevents this thread from doing
    // any more work in parallel. In practice it would be better to
    // call receiver.Count() periodically while doing other work (but
    // not so often that we busy-wait!). The Count() method is
    // non-blocking and just returns the number of messages received
    // but not yet waited for.
    receiver.Wait();

    // Check the returned file size.
    printf("Read %d bytes\n", messageCollector.mFileMessage.mFileSize);

    return 0;
}
Exemple #4
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;
}
Exemple #5
0
    HelloWorld():framework(),
                 qc(),
                 receiver(),
                 queryActor(framework.CreateActor<QueryActor>())
        {
            receiver.RegisterHandler(&qc, &QueryCollector::Handler);
            std::map<std::string,std::string> queryMap;

            queryMap.insert(std::make_pair(std::string("dbpath"),std::string("/srv/search/")));
            queryMap.insert(std::make_pair(std::string("dbnames"),std::string("news1.db")));
            queryMap.insert(std::make_pair(std::string("dicpath"),std::string("/srv/search/")));
            queryActor.Push(MapMessage(MapMessage::ATTR,queryMap),receiver.GetAddress());
            
            
        }
Exemple #6
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;
}