}
// Remove the empty items
for (Iterator itr = m_workSet.iterator(); itr.hasNext();)
{
Work work = (Work)itr.next();
if (work.isEmpty())
{
itr.remove();
work.ignore();
}
}
// Sort the work items topologically
Work[] workArray = new Work[m_workSet.size()];
int nStart = 0;
int nEnd = 0;
// Get the root items
for (Iterator itr = m_workSet.iterator(); itr.hasNext();)
{
Work work = (Work)itr.next();
if (work.getPredCount() == 0)
{
workArray[nEnd++] = work;
}
}
while (nStart < nEnd)
{
// Sort the items that are at the same distance from the root,
// so that similar work items are batched together.
Arrays.sort(workArray, nStart, nEnd);
int nNewEnd;
for (nNewEnd = nEnd; nStart < nEnd; ++nStart)
{
Work work = workArray[nStart];
for (int i = 0, nCount = work.getSuccessorCount(); i < nCount; ++i)
{
Work succ = work.getSuccessor(i);
if (succ.decPredCount() == 0)
{
workArray[nNewEnd++] = succ;
}
}
}
nEnd = nNewEnd;
}
if (nEnd != workArray.length)
{
// TODO: Break the cycles
throw new UnsupportedOperationException("Circular dependencies in units of work are not supported yet");
}
// Execute the work items while batching them for each engine
execute(workArray, 0, nEnd);
// Execute the work items for replicated instances against their fragments
if (m_replicationSet != null)
{
Set fragmentSet = new HashSet();
for (Lookup2D.Iterator itr = m_replicationSet.valueIterator(); itr.hasNext();)
{
itr.next();
fragmentSet.add(itr.getKey2());
}
fragmentSet.remove((m_context.getFragmentName() == null) ? "" : m_context.getFragmentName());
if (!fragmentSet.isEmpty())
{
Work[] replicaArray = new Work[nEnd];
for (Iterator itr = fragmentSet.iterator(); itr.hasNext();)
{
String sFragmentName = (String)itr.next();
nStart = 0;
for (int i = 0; i < nEnd; ++i)
{
Work work = workArray[i];
if (m_replicationSet.contains(work.getInstance(), sFragmentName))
{
replicaArray[nStart++] = work;
work.setFragmentName(sFragmentName);
}
}
if (nStart > 0)
{