void p3ZeroReserveRS::statusChange(const std::list< pqipeer > &plist)
{
    std::cerr << "Zero Reserve: Status changed:" << std::endl;
    if( m_initialized < INIT_THRESHOLD ){
        for (std::list< pqipeer >::const_iterator it = plist.begin(); it != plist.end(); it++ ){
            if( RS_PEER_CONNECTED & (*it).actions ){
                RsZeroReserveMsgItem * item = new RsZeroReserveMsgItem( RsZeroReserveMsgItem::REQUEST_ORDERBOOK, "" );
                item->PeerId( (*it).id );
                sendItem( item );
            }
        }
    }
    // give any newly connected peer updated credit info - we might have changed it.
    for (std::list< pqipeer >::const_iterator peerIt = plist.begin(); peerIt != plist.end(); peerIt++ ){
        if( RS_PEER_CONNECTED & (*peerIt).actions ){
            Credit::CreditList cl;
            try{
                Credit::getCreditList( cl, (*peerIt).id );
            }
            catch( std::exception e ){
                g_ZeroReservePlugin->placeMsg( std::string( "Exception caught: " ) + e.what() + " Cannot load credit list" );
                break;
            }

            for( Credit::CreditList::const_iterator creditIt = cl.begin(); creditIt != cl.end(); creditIt++){
                sendCredit( *creditIt );
            }
        }
    }
}
Beispiel #2
0
void Mailbox::__addThing(int32_t index, Thing* thing)
{
	if(Item* item = thing->getItem())
	{
		if(canSend(item))
			sendItem(item);
	}
}
Beispiel #3
0
void Mailbox::__addThing(Creature* actor, int32_t, Thing* thing)
{
	Item* item = thing->getItem();
	if(!item)
		return;

	if(canSend(item))
		sendItem(actor, item);
}
bool p3ZeroReserveRS::sendOrder( const std::string& peer_id, OrderBook::Order * order )
{
    std::cerr << "Zero Reserve: Sending order to " << peer_id << std::endl;
    RsZeroReserveOrderBookItem * item = new RsZeroReserveOrderBookItem( *order );
    if(!item){
            std::cerr << "Cannot allocate RsZeroReserveOrderBookItem !" << std::endl;
            return false ;
    }
    item->PeerId( peer_id );
    sendItem( item );
    return true;
}
bool p3ZeroReserveRS::sendCredit( Credit * credit )
{
    std::cerr << "Zero Reserve: Sending Credit item to " << credit->m_id << std::endl;
    RsZeroReserveCreditItem * item = new RsZeroReserveCreditItem( credit );
    if(!item){
            std::cerr << "Cannot allocate RsZeroReserveCreditItem !" << std::endl;
            return false ;
    }
    sendItem( item );
    item->print( std::cerr, 16 );
    return true;
}
Beispiel #6
0
void Chest::receiveUseRequest(){
    QString output;
    QTextStream os(&output);
    os << "Obtained:\n";
    for (int i = 0; i < m_itemLimit; ++i){
        if (m_contents[i].getType() != "none"){
            sendItem(m_contents[i]);
            os << "* " << m_contents[i].getName() << "\n";
        }
        else {
            break;
        }
    }
    clearContent();
    sendUseReport(output);
}
void p3ZeroReserveRS::sendOrderBook( const std::string & uid )
{
    {
        RsStackMutex askMutex( m_asks->m_order_mutex );
        for( OrderBook::OrderIterator it = m_asks->begin(); it != m_asks->end(); it++ ){
            sendOrder( uid, *it );
        }
    }
    {
        RsStackMutex bidMutex( m_bids->m_order_mutex );
        for( OrderBook::OrderIterator it = m_bids->begin(); it != m_bids->end(); it++ ){
            sendOrder( uid, *it );
        }
    }
    sendItem( new RsZeroReserveMsgItem( RsZeroReserveMsgItem::SENT_ORDERBOOK, "" ) );
}
void ReplicationManager::wait(const std::shared_ptr<Item>& item)
{
    ScopedMutexLock cs(_repMutex);

    assert(_lsnrId);

    if (item->isDone()) {
        item->validate();
        return;
    }

    std::shared_ptr<RepItems>& ri = _repQueue[item->getInstanceId()];
    assert(ri);

    Event::ErrorChecker ec = bind(&ReplicationManager::checkItemState, item);

    while (true) {

        LOG4CXX_TRACE(logger, "ReplicationManager::wait: about to wait for instance=" << item->getInstanceId()
                      << ", size=" << item->getChunkMsg()->getMessageSize()
                      << ", query (" << item->getChunkMsg()->getQueryID()<<")"
                      << ", queue size="<< ri->size());
        assert(!ri->empty());

        bool mine = (ri->front() == item);
        bool res = sendItem(*ri);
        if (mine && res) {
            assert(item->isDone());
            item->validate();
            return;
        }
        if (!res) {
            try {
                InjectedErrorListener<ReplicaWaitInjectedError>::check();
                _repEvent.wait(_repMutex, ec);
            } catch (Exception& e) {
                item->setDone(e.copy());
                throw;
            }
        }
        if (item->isDone()) {
            item->validate();
            return;
        }
    }
}
void ReplicationManager::send(const std::shared_ptr<Item>& item)
{
    assert(item);
    assert(!item->isDone());
    assert(_lsnrId);

    ScopedMutexLock cs(_repMutex);
    std::shared_ptr<RepItems>& ri = _repQueue[item->getInstanceId()];
    if (!ri) {
        ri = std::shared_ptr<RepItems>(new RepItems);
    }
    ri->push_back(item);
    if (ri->size() == 1) {
        assert(ri->front() == item);
        sendItem(*ri);
    }
}