@@ -0,0 +1,2835 @@
+/*%0A * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.%0A *%0A * This program and the accompanying materials are made available under the%0A * terms of the Eclipse Public License v1.0 which accompanies this distribution,%0A * and is available at http://www.eclipse.org/legal/epl-v10.html%0A */%0Apackage org.opendaylight.yangtools.util;%0A%0Aimport java.util.concurrent.BlockingQueue;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.RejectedExecutionException;%0Aimport java.util.concurrent.RejectedExecutionHandler;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport com.google.common.util.concurrent.ForwardingBlockingQueue;%0A%0A/**%0A * Utility methods for dealing with %7B@link ExecutorService%7Ds.%0A */%0Apublic final class ExecutorServiceUtil %7B%0A    private static final class WaitInQueueExecutionHandler implements RejectedExecutionHandler %7B%0A        @Override%0A        public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) %7B%0A            try %7B%0A                executor.getQueue().put(r);%0A            %7D catch (InterruptedException e) %7B%0A                LOG.debug(%22Intterupted while waiting for queue%22, e);%0A                throw new RejectedExecutionException(%22Interrupted while waiting for queue%22, e);%0A            %7D%0A        %7D%0A    %7D%0A%0A    private static final Logger LOG = LoggerFactory.getLogger(ExecutorServiceUtil.class);%0A    private static final RejectedExecutionHandler WAIT_IN_QUEUE_HANDLER = new WaitInQueueExecutionHandler();%0A%0A    private ExecutorServiceUtil() %7B%0A        throw new UnsupportedOperationException(%22Utility class%22);%0A    %7D%0A%0A    /**%0A     * Create a %7B@link BlockingQueue%7D which does not allow for non-blocking addition to the queue.%0A     * This is useful with %7B@link #waitInQueueExecutionHandler()%7D to turn force a%0A     * %7B@link ThreadPoolExecutor%7D to create as many threads as it is configured to before starting%0A     * to fill the queue.%0A     *%0A     * @param delegate Backing blocking queue.%0A     * @return A new blocking queue backed by the delegate%0A     */%0A    public %3CE%3E BlockingQueue%3CE%3E offerFailingBlockingQueue(final BlockingQueue%3CE%3E delegate) %7B%0A        return new ForwardingBlockingQueue%3CE%3E() %7B%0A            @Override%0A            public boolean offer(final E o) %7B%0A                return false;%0A            %7D%0A%0A            @Override%0A            protected BlockingQueue%3CE%3E delegate() %7B%0A                return delegate;%0A            %7D%0A        %7D;%0A    %7D%0A%0A    /**%0A     * Return a %7B@link RejectedExecutionHandler%7D which blocks on the %7B@link ThreadPoolExecutor%7D's%0A     * backing queue if a new thread cannot be spawned.%0A     *%0A     * @return A shared RejectedExecutionHandler instance.%0A     */%0A    public RejectedExecutionHandler waitInQueueExecutionHandler() %7B%0A        return WAIT_IN_QUEUE_HANDLER;%0A    %7D%0A%7D%0A

add ExecutorServiceUtil