CATCH_NEXTROW()
 {
     ActivityTimer t(totalCycles, timeActivities);
     if (abortSoon || eof)
         return NULL;
     RtlDynamicRowBuilder out(queryRowAllocator());
     size32_t sz = helper->clearAggregate(out);
     OwnedConstThorRow row = input->nextRow();
     if (row)
     {
         sz = helper->processFirst(out, row);
         // NB: if ungrouped existsAggregate, no need to look at rest of input
         if (!ungroupedExistsAggregate)
         {
             while (!abortSoon)
             {
                 row.setown(input->nextRow());
                 if (!row)
                     break;
                 sz = helper->processNext(out, row);
             }
         }
         if (!input->isGrouped())
             eof = true;
     }
     else
     {
         eof = true;
         if (input->isGrouped())
             return NULL;
     }
     dataLinkIncrement();
     return out.finalizeRowClear(sz);
 }
 CATCH_NEXTROW()
 {
     ActivityTimer t(totalCycles, timeActivities);
     while(!abortSoon)
     {
         OwnedConstThorRow row = input->nextRow();
         if(!row)    {
             numToSkip = whichSample ? whichSample - 1 : 0;
             if(anyThisGroup) {
                 anyThisGroup = false;           
                 break;
             }
             row.setown(input->nextRow());
             if(!row) 
                 break;
         }
         if(numToSkip == 0) {
             anyThisGroup = true;
             numToSkip = numSamples - 1;
             dataLinkIncrement();
             return row.getClear();
         }
         numToSkip--;
     }
     return NULL;
 }
    void process()
    {
        helper->clearAggregate(aggy);
        input = inputs.item(0);
        startInput(input);
        processed = THORDATALINK_STARTED;

        try
        {
            while (!abortSoon)
            {
                OwnedConstThorRow row(input->ungroupedNextRow());
                if (!row)
                    break;
                helper->process(aggy, row);     
                processed++;
            }
            ActPrintLog("DISTRIBUTION: processed %"RCPF"d records", processed & THORDATALINK_COUNT_MASK);
        }
        catch(CATCHALL)
        {
            ActPrintLog("DISTRIBUTION: exception");
            throw;
        }
        CMessageBuffer msg;
        helper->serialize(aggy, msg);
        container.queryJob().queryJobComm().send(msg, 0, mpTag);
    }
static bool canStall(CActivityBase *act)
{
    if (!act)
        return false;
    unsigned i=0;
    IThorDataLink *inp;
    while ((inp=((CSlaveActivity *)act)->queryInput(i++))!=NULL) {
        ThorDataLinkMetaInfo info;
        inp->getMetaInfo(info);
        if (info.canStall)
            return true;
        if (!info.isSource&&!info.buffersInput&&!info.canBufferInput)
            if (canStall((CSlaveActivity *)inp->queryFromActivity()))
                return true;
    }
    return false;
}
 void start()
 {
     ActivityTimer s(totalCycles, timeActivities);
     eof = false;
     input=inputs.item(0);
     startInput(input);
     ungroupedExistsAggregate = (container.getKind() == TAKexistsaggregate) && !input->isGrouped();
     dataLinkStart();
 }
 void doStart()
 {
     hadElement = false;
     inputStopped = false;
     input = inputs.item(0);
     startInput(input);
     if (input->isGrouped())
         ActPrintLog("Grouped mismatch");
 }
    void process()
    {
        processed = 0;

        input = inputs.item(0);
        startInput(input);

        processed = THORDATALINK_STARTED;

        OwnedConstThorRow row = input->ungroupedNextRow();
        CMessageBuffer mb;
        size32_t lenpos = mb.length(); // its 0 really
        mb.append((size32_t)0);
        if (row) {
            CMemoryRowSerializer msz(mb);
            ::queryRowSerializer(input)->serialize(msz,(const byte *)row.get());
            size32_t sz = mb.length()-lenpos-sizeof(size32_t);
            mb.writeDirect(lenpos,sizeof(size32_t),&sz);
            processed++;
        }
        container.queryJob().queryJobComm().send(mb, 0, masterMpTag);
    }
 virtual void getMetaInfo(ThorDataLinkMetaInfo &info)
 {
     // JCSMORE - TBD
     base->getMetaInfo(info);
 }