/**
 * Copyright Notice
 * 
 * This is a work of the U.S. Government and is not subject to copyright
 * protection in the United States. Foreign copyrights may apply.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package gov.va.isaac.util;

import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 
 * {@link Utility}
 *
 * @author ocarlsen
 * @author <a href="mailto:daniel.armbrust.list@gmail.com">Dan Armbrust</a>
 */
public class Utility {

    private static final ThreadPoolExecutor EXECUTOR = buildExecutor();
    private static final ScheduledExecutorService scheduledExecutor_ = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());

    private static ThreadPoolExecutor buildExecutor() {

        // Thread pool settings.
        int corePoolSize = 10;
        int maximumPoolSize = 30;
        int keepAliveTime = 60;
        TimeUnit timeUnit = TimeUnit.SECONDS;
        LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();
        BackgroundThreadFactory threadFactory = new BackgroundThreadFactory();

        return new ThreadPoolExecutor(
                corePoolSize,
                maximumPoolSize,
                keepAliveTime,
                timeUnit,
                workQueue,
                threadFactory);
    }

    public static void execute(Runnable command) {
        EXECUTOR.execute(command);
    }
    
    public static <T> Future<T> submit(Callable<T> task) {
        return EXECUTOR.submit(task);
    }
    
    public static Future<?> submit(Runnable task) {
        return EXECUTOR.submit(task);
    }
    
    public static <T> Future<?> submit(Runnable task, T result) {
        return EXECUTOR.submit(task, result);
    }
    
    public static ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
        return scheduledExecutor_.schedule(command, delay, unit);
    }
    
    public static <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
        return scheduledExecutor_.schedule(callable, delay, unit);
    }

    public static UUID getUUID(String string) {
        if (string == null)
        {
            return null;
        }
        if (string.length() != 36) {
            return null;
        }
        try {
            return UUID.fromString(string);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }
    
    public static boolean isUUID(String string) {
        return (getUUID(string) != null);
    }

    public static boolean isLong(String string) {
        if (string == null)
        {
            return false;
        }
        try {
            Long.parseLong(string);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    }
    
    public static boolean isInt(String string) {
        return (getInt(string) != null);
    }
    
    public static Integer getInt(String string) {
        try {
            return Integer.parseInt(string);
        } catch (NumberFormatException e) {
            return null;
        }
    }
    
    public static void shutdownThreadPools()
    {
        EXECUTOR.shutdownNow();
        scheduledExecutor_.shutdownNow();
    }
}

@@ -749,16 +749,109 @@
 .util;%0A%0A
+import gov.vha.isaac.ochre.api.LookupService;%0Aimport gov.vha.isaac.ochre.util.WorkExecutors;%0A
 import j
@@ -982,57 +982,8 @@
 re;%0A
-import java.util.concurrent.LinkedBlockingQueue;%0A
 impo
@@ -1081,56 +1081,8 @@
 re;%0A
-import java.util.concurrent.ThreadPoolExecutor;%0A
 impo
@@ -1274,80 +1274,8 @@
  %7B%0A%0A
-    private static final ThreadPoolExecutor EXECUTOR = buildExecutor();%0A
     
@@ -1415,30 +1415,29 @@
 ;%0A%0A    p
-rivate
+ublic
  static 
 ThreadPo
@@ -1432,681 +1432,108 @@
 tic 
-ThreadPoolExecutor buildExecutor() %7B%0A%0A        // Thread pool settings.%0A        int corePoolSize = 10;%0A        int maximumPoolSize = 30;%0A        int keepAliveTime = 60;%0A        TimeUnit timeUnit = TimeUnit.SECONDS;%0A        LinkedBlockingQueue%3CRunnable%3E workQueue = new LinkedBlockingQueue%3CRunnable%3E();%0A        BackgroundThreadFactory threadFactory = new BackgroundThreadFactory();%0A%0A        return new ThreadPoolExecutor(%0A                corePoolSize,%0A                maximumPoolSize,%0A                keepAliveTime,%0A                timeUnit,%0A                workQueue,%0A                threadFactory);%0A    %7D%0A%0A    public static void execute(Runnable command) %7B%0A        EXECUTOR
+void execute(Runnable command) %7B%0A        LookupService.getService(WorkExecutors.class).getExecutor()
 .exe
@@ -1628,32 +1628,83 @@
      return 
-EXECUTOR
+LookupService.getService(WorkExecutors.class).getExecutor()
 .submit(task
@@ -1780,32 +1780,83 @@
      return 
-EXECUTOR
+LookupService.getService(WorkExecutors.class).getExecutor()
 .submit(task
@@ -1950,24 +1950,75 @@
  return 
-EXECUTOR
+LookupService.getService(WorkExecutors.class).getExecutor()
 .submit(
@@ -3476,40 +3476,8 @@
   %7B%0A
-        EXECUTOR.shutdownNow();%0A
     

use shared lower level thread pool