Esempio n. 1
0
    bool CPacketizer::initialize(PropertiesPtr properties)
    {
        Properties::iterator ret;
        ret=properties->find(std::string("hdrLength"));
        if (ret == properties->end())
        {
            LOG_ERROR("hdrLength not present in config file");
            return false;
        }
        else
        {
            int* hdr=boost::any_cast<int>(&(ret->second));
            if (hdr == NULL)
            {
                LOG_ERROR("hdrLength not an integer value");
            return false;
            }

            hdrLength_=*hdr;
        }

#if 0
        ret=(*serverDetails)->find(std::string("bodyLength"));
        if (ret == (*serverDetails)->end())
        {
            LOG_ERROR("bodyLength not present in config file");
            return false;
        }
        else
        {
            int* bodyLen=boost::any_cast<int>(&(ret->second));
            if (bodyLen == NULL)
            {
                LOG_ERROR("bodyLength not an integer value");
                return false;
            }

            bodyLength_=*bodyLen;
        }
#endif

        std::ostringstream tmp;
        tmp << "Cpacketize initialized with header length " << hdrLength_;
        LOG_DEBUG(tmp.str());
        return true;
    }
Esempio n. 2
0
void Rmi::initialize(PropertiesPtr& rmiSection)
{
    Properties::iterator ret;

    // initialize multi server
    ret=rmiSection->find(std::string("multiServer"));
    if (ret != rmiSection->end())
    {
        PropertiesPtr* serverDetails=boost::any_cast<PropertiesPtr>(&(ret->second));
        if (serverDetails== NULL)
        {
            LOG_ERROR("multiServer details not found ");
        }
        else
            serverStub_.reset(new Fog::Network::MultiServer(*serverDetails));
    }
    else
    {
        LOG_ERROR("multi server not present in config file");
    }

    // initialize client 
    ret=rmiSection->find(std::string("client"));
    if (ret != rmiSection->end())
    {
        PropertiesPtr* clientDetails=boost::any_cast<PropertiesPtr>(&(ret->second));
        if (clientDetails== NULL)
        {
            LOG_ERROR("client details not found ");
        }
        else
            clientStub_.reset(new Fog::Network::TCPClient(*clientDetails));
    }
    else
    {
        LOG_ERROR("client not present in config file");
    }

    // store the packetizer section 

    ret=rmiSection->find(std::string("cpacketizer"));
    if (ret != rmiSection->end())
    {
        PropertiesPtr* pktPtr=boost::any_cast<PropertiesPtr>(&(ret->second));
        if (pktPtr == NULL)
        {
            LOG_ERROR("unable to extract packetizer section from rmi");
        }
        else
        {
            packetizerSection_=*pktPtr;
            cliPkter_.reset(new Fog::Network::CPacketizer(packetizerSection_));
        }
    }
    else
    {
        LOG_ERROR("packetizer detail not found ");
    }

    // set up the connection for the server and for client on initial connection

    if (serverStub_)
    {
        (serverStub_->OnAccept).connect(boost::bind(&Fog::Network::Rmi::acceptConnection, this, _1));
        serverStub_->startAccept();
    }
    if (clientStub_)
    {
        (clientStub_->OnConnect).connect(boost::bind(&Fog::Network::Rmi::onConnect, this, _1));
        clientStub_->startConnect();
    }
}