void CommandService::_process_timeout(const int64_t now) { /* clear timeout command */ if(m_queue_tb->size()>0) { Int64Array* ls =0; HashIterator* it =static_cast< HashIterator* >(m_queue_tb->iterator()); while(it->next()) { const int64_t who =static_cast< Int64* >(it->getKey())->getValue(); Array* queue =static_cast< Array* >(it->getValue()); while(Command* cmd =dynamic_cast< Command* >(queue->front())) { if(cmd->isTimeout(now)) { if(cmd->isProcessing()) { WARN("service %s(%lld) who %lld command %lld cancel", name(), (long long)m_id, (long long)cmd->getWho(), (long long)cmd->getCommand()); } queue->pop_front(); } else { break; } } if(Command* cmd =dynamic_cast< Command* >(queue->front())) { if(cmd->isProcessing()) { continue; } ASSERT(cmd->isInit()); if(!ls) { ls =SafeNew<Int64Array>(); } ls->push_back(who); } } const int64_t n= ls ? ls->size() : 0; for(int64_t i=0; i<n; ++i) { _process_request(ls->get(i)); } } /* clear timeout rpc */ if(m_rpc_tb->size()>0) { Array* ls =0; HashIterator* it =static_cast< HashIterator* >(m_rpc_tb->iterator()); while(it->next()) { RpcInfo* ri =static_cast< RpcInfo* >(it->getValue()); if(now >= ri->getExpireTime()) { if(!ls) { ls =SafeNew<Array>(); } ls->push_back(ri); it->remove(); } } const int64_t n =ls ? ls->size() : 0; for(int64_t i=0; i<n; ++i) { RpcInfo* ri =static_cast< RpcInfo* >(ls->get(i)); WARN("service %s(%lld) rpc %lld cancel", name(), (long long)m_id, (long long)ri->getId()); ri->timeout(); } } }