Ejemplo n.º 1
0
void fill_list(ForwardList &list, int number){ //заполняем список
    if (list.getHead() == 0) {
        list.push_back(list.getHead());
    }
    for(int i = 0; ( i < list.max_size() - 1) && i < number; ++i)
        list.push_back(list.end(), list.order_number() + 1);
}
Ejemplo n.º 2
0
void StatServer::clearForward(AgentFlushRequest * agentFlushRequest)
{
    std::tr1::unordered_map<std::string, Bucketizer> buckets;
    {
        grab aholdof(forwardMutex_);
        buckets.swap(forwardBuckets_);
    }
    ForwardList conns;
    for (ForwardList::iterator i = forward_.begin(); i < forward_.end(); ++i) {
        if ((*i)->opened()) {
            conns.push_back(*i);
        }
    }
    size_t count = conns.size();
    if ((count > 0) && buckets.size())
    {
        size_t forwardIndex = 0;
        //  if not opened, then we lose this bucket
        std::stringstream ss[count];
        for (std::tr1::unordered_map<std::string, Bucketizer>::iterator
            ptr(buckets.begin()), end (buckets.end());
            ptr != end;
            ++ptr)
        {
            Bucketizer &bizer((*ptr).second);
            if ((*ptr).first[0] == '*')
            {
                for (unsigned int i = 0 ; i < bizer.BUCKET_COUNT; i++) {
                    istat::Bucket b = bizer.get(i);
                    if (b.count() > 0) {
                        ss[forwardIndex] << (*ptr).first << " " << b.time() << " " << b.sum() << "\r\n";
                    }
                }
            }
            else
            {
                for (unsigned int i = 0 ; i < bizer.BUCKET_COUNT; i++) {
                    istat::Bucket b = bizer.get(i);
                    if (b.count() > 0) {
                        ss[forwardIndex] << (*ptr).first << " " << b.time() << " " << b.sum() << " " <<
                            b.sumSq() << " " << b.min() << " " << b.max() << " " << b.count() << "\r\n";
                    }
                }
            }
            ++forwardIndex;
            forwardIndex %= count;
        }
        for (size_t i = 0; i < count; ++i) {
            std::string str(ss[i].str());
            if (!str.empty()) {
                size_t pending = conns[i]->writeOut(str);
                if (agentFlushRequest != NULL) {
                    agentFlushRequest->add(i, pending);
                }
            }
        }
    }
}