예제 #1
0
CDFamilyIterator  CDFamily::convergeTo(CCdCore* cd1, CCdCore* cd2, bool byAccession)const
{
	vector<CCdCore*> path1, path2;
	getPathToRoot(cd1, path1);
	getPathToRoot(cd2, path2);
	vector<CCdCore*>::reverse_iterator rit1 = path1.rbegin();
	vector<CCdCore*>::reverse_iterator rit2 = path2.rbegin();
	if( (rit1 == path1.rend()) || (rit2 == path2.rend()))
		return end();
	assert((*rit1) = (*rit2)); //both should point to the root
	CCdCore* lastConvergedPoint = *rit1;
	for (; rit1 != path1.rend() && rit2 != path2.rend(); rit1++, rit2++)
	{
		if ((!byAccession && *rit1 == *rit2) || (byAccession && (*rit1)->GetAccession() == (*rit2)->GetAccession()))
			lastConvergedPoint = *rit1;
		else
			break;
	}
    return (byAccession) ? findCDByAccession(lastConvergedPoint) : findCD(lastConvergedPoint);
}
예제 #2
0
CDFamilyIterator  CDFamily::convergeTo(CCdCore* cd1, CCdCore* cd2, vector<CCdCore*>& path1, vector<CCdCore*>& path2) const
{
	vector<CCdCore*> pathToRoot1, pathToRoot2;
	getPathToRoot(cd1, pathToRoot1);
	getPathToRoot(cd2, pathToRoot2);
	vector<CCdCore*>::reverse_iterator rit1 = pathToRoot1.rbegin();
	vector<CCdCore*>::reverse_iterator rit2 = pathToRoot2.rbegin();
	vector<CCdCore*>::reverse_iterator lastConvergedIt1, lastConvergedIt2;
	if( (rit1 == pathToRoot1.rend()) || (rit2 == pathToRoot2.rend()))
		return end();
	assert((*rit1) = (*rit2)); //both should point to the root
	CCdCore* lastConvergedPoint = *rit1;
	for (; rit1 != pathToRoot1.rend() && rit2 != pathToRoot2.rend(); rit1++, rit2++)
	{
        if (*rit1 == *rit2) {
			lastConvergedPoint = *rit1;
            lastConvergedIt1 = rit1;
            lastConvergedIt2 = rit2;
        } else {
			break;
        }
	}

    //  Construct the paths from cd1/cd2 to the lastConvergedPoint
    path1.clear();
    for (rit1 = lastConvergedIt1; rit1 != pathToRoot1.rend(); ++rit1) {
        path1.push_back(*rit1);
    }
//    path1.insert(path1.end(), lastConvergedIt1, pathToRoot1.rend());  //  breaks Workshop builds
    reverse(path1.begin(), path1.end());

    path2.clear();
    for (rit2 = lastConvergedIt2; rit2 != pathToRoot2.rend(); ++rit2) {
        path2.push_back(*rit2);
    }
//    path2.insert(path2.end(), lastConvergedIt2, pathToRoot2.rend());  //  breaks Workshop builds
    reverse(path2.begin(), path2.end());

	return findCD(lastConvergedPoint);
}
void rice::p2p::scribe::ScribeImpl_TopicManager::setPathToRoot(::java::util::List* pathToRoot)
{
    if(pathToRoot == nullptr) {
        this->pathToRoot = new ::java::util::ArrayList();
    } else {
        this->pathToRoot = new ::java::util::ArrayList(static_cast< ::java::util::Collection* >(pathToRoot));
    }
    npc(java_cast< ::java::util::List* >(this->pathToRoot))->add(static_cast< ::java::lang::Object* >(npc(ScribeImpl_this->endpoint)->getId()));
    if(!npc(children)->isEmpty()) {
        ::java::util::List* sendDrop = new ::java::util::ArrayList();
        ::java::util::List* sendUpdate = new ::java::util::ArrayList();
        {
            synchronized synchronized_0(ScribeImpl_this->topicManagers);
            {
                auto children = getChildren();
                for (auto _i = npc(children)->iterator(); _i->hasNext(); ) {
                    ::rice::p2p::commonapi::NodeHandle* child = java_cast< ::rice::p2p::commonapi::NodeHandle* >(_i->next());
                    {
                        if(npc(java_cast< ::java::util::List* >(this->pathToRoot))->contains(static_cast< ::java::lang::Object* >(npc(child)->getId()))) {
                            npc(sendDrop)->add(static_cast< ::java::lang::Object* >(child));
                        } else {
                            npc(sendUpdate)->add(static_cast< ::java::lang::Object* >(child));
                        }
                    }
                }
                for (auto _i = npc(sendDrop)->iterator(); _i->hasNext(); ) {
                    ::rice::p2p::commonapi::NodeHandle* child = java_cast< ::rice::p2p::commonapi::NodeHandle* >(_i->next());
                    {
                        removeChild(child);
                    }
                }
            }
        }
        for (auto _i = npc(sendDrop)->iterator(); _i->hasNext(); ) {
            ::rice::p2p::commonapi::NodeHandle* child = java_cast< ::rice::p2p::commonapi::NodeHandle* >(_i->next());
            {
                npc(ScribeImpl_this->endpoint)->route(static_cast< ::rice::p2p::commonapi::Id* >(nullptr), static_cast< ::rice::p2p::commonapi::rawserialization::RawMessage* >(new ::rice::p2p::scribe::messaging::DropMessage(ScribeImpl_this->localHandle, topic)), child);
            }
        }
        for (auto _i = npc(sendUpdate)->iterator(); _i->hasNext(); ) {
            ::rice::p2p::commonapi::NodeHandle* child = java_cast< ::rice::p2p::commonapi::NodeHandle* >(_i->next());
            {
                npc(ScribeImpl_this->endpoint)->route(static_cast< ::rice::p2p::commonapi::Id* >(nullptr), static_cast< ::rice::p2p::commonapi::rawserialization::RawMessage* >(new ::rice::p2p::scribe::messaging::SubscribeAckMessage(ScribeImpl_this->localHandle, ::java::util::Collections::singletonList(topic), ::java::util::Collections::singletonList(getPathToRoot()), ::rice::p2p::scribe::maintenance::MaintainableScribe::MAINTENANCE_ID)), child);
            }
        }
    }
}