Coverage Report - org.mule.config.pool.ThreadPoolFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ThreadPoolFactory
0%
0/9
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.config.pool;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleRuntimeException;
 11  
 import org.mule.api.config.ThreadingProfile;
 12  
 import org.mule.api.context.MuleContextAware;
 13  
 import org.mule.config.PreferredObjectSelector;
 14  
 import org.mule.config.i18n.MessageFactory;
 15  
 
 16  
 import java.util.Iterator;
 17  
 
 18  
 import javax.imageio.spi.ServiceRegistry;
 19  
 
 20  
 import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
 21  
 
 22  
 /**
 23  
  * Uses a standard JDK's
 24  
  * <a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider">SPI discovery</a>
 25  
  * mechanism to locate implementations.
 26  
  */
 27  0
 public abstract class ThreadPoolFactory implements MuleContextAware
 28  
 {
 29  
 
 30  
     protected MuleContext muleContext;
 31  
 
 32  
     /**
 33  
      * @return a discovered
 34  
      */
 35  
     public static ThreadPoolFactory newInstance()
 36  
     {
 37  
         /*
 38  
            There's a public (at last!) SPI mechanism in Java 6, java.util.ServiceLoader, but
 39  
            it's hidden in earlier versions.
 40  
 
 41  
            The javax.imageio.spi.ServiceRegistry, while not belonging here at first look, is
 42  
            perfectly functional. Underneath, it wraps the sun.misc.Service class, which does the
 43  
            lookup. The latter has been available since Java 1.3 and standardized internally at Sun.
 44  
            Also, Sun, Bea JRockit and IBM JDK all have it readily available for use, so it's safe to
 45  
            rely on.
 46  
         */
 47  0
         final Iterator<ThreadPoolFactory> servicesIterator = ServiceRegistry.lookupProviders(ThreadPoolFactory.class);
 48  
 
 49  0
         PreferredObjectSelector<ThreadPoolFactory> selector = new PreferredObjectSelector<ThreadPoolFactory>();
 50  0
         ThreadPoolFactory threadPoolFactory = selector.select(servicesIterator);
 51  
 
 52  0
         if (threadPoolFactory == null)
 53  
         {
 54  0
             throw new MuleRuntimeException(MessageFactory.createStaticMessage(
 55  
                     "Couldn't find config via SPI mechanism. Corrupted Mule core jar?"
 56  
             ));
 57  
         }
 58  
 
 59  0
         return threadPoolFactory;
 60  
     }
 61  
 
 62  
     public void setMuleContext(MuleContext context)
 63  
     {
 64  0
         this.muleContext = context;
 65  0
     }
 66  
 
 67  
     public abstract ThreadPoolExecutor createPool(String name, ThreadingProfile tp);
 68  
 }