/* This file is part of VoltDB.
 * Copyright (C) 2008-2012 VoltDB Inc.
 *
 * VoltDB is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VoltDB is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.voltdb.iv2;

import java.lang.Object;

import java.util.Comparator;
import java.util.PriorityQueue;

/** SiteTaskerScheduler orders SiteTaskers for execution. */
public class SiteTaskerScheduler
{
    /** TaskComparator orders SiteTaskers by priority */
    static class TaskComparator implements Comparator<SiteTasker>
    {
        public int compare(SiteTasker o1, SiteTasker o2)
        {
            int priorityDiff = o1.priority() - o2.priority();
            if (priorityDiff == 0) {
                return (int)(o1.seq() - o2.seq());
            }
            else {
                return priorityDiff;
            }
        }

        public boolean equals(Object rhs)
        {
            return (rhs instanceof TaskComparator);
        }
    }

    final PriorityQueue<SiteTasker> m_tasks;
    final TaskComparator m_comparator = new TaskComparator();
    final int m_initialCap = 100;
    long m_sequence = 0;

    SiteTaskerScheduler()
    {
        m_tasks = new PriorityQueue<SiteTasker>(m_initialCap, m_comparator);
    }

    synchronized public boolean offer(SiteTasker task)
    {
        task.setSeq(++m_sequence);
        return m_tasks.offer(task);
    }

    synchronized public SiteTasker poll()
    {
        return m_tasks.poll();
    }
}

@@ -797,24 +797,90 @@
 va.util.
-Priority
+concurrent.atomic.AtomicLong;%0Aimport java.util.concurrent.PriorityBlocking
 Queue;%0A%0A
@@ -1547,32 +1547,40 @@
   final Priority
+Blocking
 Queue%3CSiteTasker
@@ -1690,17 +1690,29 @@
 00;%0A    
-l
+final AtomicL
 ong m_se
@@ -1720,17 +1720,33 @@
 uence = 
-0
+new AtomicLong(0)
 ;%0A%0A    S
@@ -1802,16 +1802,24 @@
 Priority
+Blocking
 Queue%3CSi
@@ -1864,37 +1864,24 @@
 %0A    %7D%0A%0A    
-synchronized 
 public boole
@@ -1936,10 +1936,8 @@
 Seq(
-++
 m_se
@@ -1942,16 +1942,34 @@
 sequence
+.incrementAndGet()
 );%0A     
@@ -2014,21 +2014,8 @@
     
-synchronized 
 publ
@@ -2053,30 +2053,128 @@
     
-return m_tasks.poll();
+try %7B%0A            return m_tasks.take();%0A        %7D catch (InterruptedException e) %7B%0A            return poll();%0A        %7D
 %0A   

Make sites block.