Coverage Report - org.mule.config.ImmutableThreadingProfile
 
Classes in this File Line Coverage Branch Coverage Complexity
ImmutableThreadingProfile
0%
0/46
0%
0/2
1.387
ImmutableThreadingProfile$DefaultWorkManagerFactory
0%
0/8
0%
0/2
1.387
 
 1  
 /*
 2  
  * $Id: ImmutableThreadingProfile.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.config.ThreadingProfile;
 15  
 import org.mule.api.context.MuleContextAware;
 16  
 import org.mule.api.context.WorkManager;
 17  
 import org.mule.config.pool.ThreadPoolFactory;
 18  
 import org.mule.work.MuleWorkManager;
 19  
 
 20  
 import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
 21  
 import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionHandler;
 22  
 import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory;
 23  
 
 24  
 
 25  
 public class ImmutableThreadingProfile implements ThreadingProfile
 26  
 {
 27  
 
 28  
     private int maxThreadsActive;
 29  
     private int maxThreadsIdle;
 30  
     private int maxBufferSize;
 31  
     private long threadTTL;
 32  
     private long threadWaitTimeout;
 33  
     private int poolExhaustedAction;
 34  
     private boolean doThreading;
 35  
 
 36  0
     private ThreadPoolFactory poolFactory = ThreadPoolFactory.newInstance();
 37  0
     private WorkManagerFactory workManagerFactory = new DefaultWorkManagerFactory();
 38  
     private RejectedExecutionHandler rejectedExecutionHandler;
 39  
     private ThreadFactory threadFactory;
 40  
     private MuleContext muleContext;
 41  
 
 42  
     public ImmutableThreadingProfile(int maxThreadsActive,
 43  
                             int maxThreadsIdle,
 44  
                             int maxBufferSize,
 45  
                             long threadTTL,
 46  
                             long threadWaitTimeout,
 47  
                             int poolExhaustedAction,
 48  
                             boolean doThreading,
 49  
                             RejectedExecutionHandler rejectedExecutionHandler,
 50  
                             ThreadFactory threadFactory)
 51  0
     {
 52  0
         this.maxThreadsActive = maxThreadsActive;
 53  0
         this.maxThreadsIdle = maxThreadsIdle;
 54  0
         this.maxBufferSize = maxBufferSize;
 55  0
         this.threadTTL = threadTTL;
 56  0
         this.threadWaitTimeout = threadWaitTimeout;
 57  0
         this.poolExhaustedAction = poolExhaustedAction;
 58  0
         this.doThreading = doThreading;
 59  0
         this.rejectedExecutionHandler = rejectedExecutionHandler;
 60  0
         this.threadFactory = threadFactory;
 61  0
     }
 62  
 
 63  
     public ImmutableThreadingProfile(ThreadingProfile tp)
 64  
     {
 65  0
         this(tp.getMaxThreadsActive(),
 66  
                 tp.getMaxThreadsIdle(),
 67  
                 tp.getMaxBufferSize(),
 68  
                 tp.getThreadTTL(),
 69  
                 tp.getThreadWaitTimeout(),
 70  
                 tp.getPoolExhaustedAction(),
 71  
                 tp.isDoThreading(),
 72  
                 tp.getRejectedExecutionHandler(),
 73  
                 tp.getThreadFactory());
 74  0
     }
 75  
 
 76  
     public int getMaxThreadsActive()
 77  
     {
 78  0
         return maxThreadsActive;
 79  
     }
 80  
 
 81  
     public int getMaxThreadsIdle()
 82  
     {
 83  0
         return maxThreadsIdle;
 84  
     }
 85  
 
 86  
     public long getThreadTTL()
 87  
     {
 88  0
         return threadTTL;
 89  
     }
 90  
 
 91  
     public long getThreadWaitTimeout()
 92  
     {
 93  0
         return threadWaitTimeout;
 94  
     }
 95  
 
 96  
     public int getPoolExhaustedAction()
 97  
     {
 98  0
         return poolExhaustedAction;
 99  
     }
 100  
 
 101  
     public RejectedExecutionHandler getRejectedExecutionHandler()
 102  
     {
 103  0
         return rejectedExecutionHandler;
 104  
     }
 105  
 
 106  
     public ThreadFactory getThreadFactory()
 107  
     {
 108  0
         return threadFactory;
 109  
     }
 110  
 
 111  
     public void setMaxThreadsActive(int maxThreadsActive)
 112  
     {
 113  0
         throw new UnsupportedOperationException(getClass().getName());
 114  
     }
 115  
 
 116  
     public void setMaxThreadsIdle(int maxThreadsIdle)
 117  
     {
 118  0
         throw new UnsupportedOperationException(getClass().getName());
 119  
     }
 120  
 
 121  
     public void setThreadTTL(long threadTTL)
 122  
     {
 123  0
         throw new UnsupportedOperationException(getClass().getName());
 124  
     }
 125  
 
 126  
     public void setThreadWaitTimeout(long threadWaitTimeout)
 127  
     {
 128  0
         throw new UnsupportedOperationException(getClass().getName());
 129  
     }
 130  
 
 131  
     public void setPoolExhaustedAction(int poolExhaustPolicy)
 132  
     {
 133  0
         throw new UnsupportedOperationException(getClass().getName());
 134  
     }
 135  
 
 136  
     public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
 137  
     {
 138  0
         throw new UnsupportedOperationException(getClass().getName());
 139  
     }
 140  
 
 141  
     public void setThreadFactory(ThreadFactory threadFactory)
 142  
     {
 143  0
         throw new UnsupportedOperationException(getClass().getName());
 144  
     }
 145  
 
 146  
     public int getMaxBufferSize()
 147  
     {
 148  0
         return maxBufferSize;
 149  
     }
 150  
 
 151  
     public void setMaxBufferSize(int maxBufferSize)
 152  
     {
 153  0
         throw new UnsupportedOperationException(getClass().getName());
 154  
     }
 155  
 
 156  
     public WorkManagerFactory getWorkManagerFactory()
 157  
     {
 158  0
         return workManagerFactory;
 159  
     }
 160  
 
 161  
     public void setWorkManagerFactory(WorkManagerFactory workManagerFactory)
 162  
     {
 163  0
         throw new UnsupportedOperationException(getClass().getName());
 164  
     }
 165  
 
 166  
     public WorkManager createWorkManager(String name, int shutdownTimeout)
 167  
     {
 168  0
         return workManagerFactory.createWorkManager(new ImmutableThreadingProfile(this), name, shutdownTimeout);
 169  
     }
 170  
 
 171  
     public ExecutorService createPool()
 172  
     {
 173  0
         return createPool(null);
 174  
     }
 175  
 
 176  
     public ExecutorService createPool(String name)
 177  
     {
 178  0
         return poolFactory.createPool(name, new ImmutableThreadingProfile(this));
 179  
     }
 180  
 
 181  
     public boolean isDoThreading()
 182  
     {
 183  0
         return doThreading;
 184  
     }
 185  
 
 186  
     public void setDoThreading(boolean doThreading)
 187  
     {
 188  0
         throw new UnsupportedOperationException(getClass().getName());
 189  
     }
 190  
 
 191  
     public ThreadPoolFactory getPoolFactory()
 192  
     {
 193  0
         return poolFactory;
 194  
     }
 195  
 
 196  
     public void setMuleContext(MuleContext context)
 197  
     {
 198  0
         this.muleContext = context;
 199  
 
 200  
         // propagate mule context
 201  0
         if (this.workManagerFactory instanceof MuleContextAware)
 202  
         {
 203  0
             ((MuleContextAware) workManagerFactory).setMuleContext(muleContext);
 204  
         }
 205  
 
 206  0
         poolFactory.setMuleContext(muleContext);
 207  0
     }
 208  
 
 209  
     public MuleContext getMuleContext()
 210  
     {
 211  0
         return muleContext;
 212  
     }
 213  
 
 214  
     public String toString()
 215  
     {
 216  0
         return "ThreadingProfile{" + "maxThreadsActive=" + maxThreadsActive + ", maxThreadsIdle="
 217  
                         + maxThreadsIdle + ", maxBufferSize=" + maxBufferSize + ", threadTTL=" + threadTTL
 218  
                         + ", poolExhaustedAction=" + poolExhaustedAction + ", threadWaitTimeout="
 219  
                         + threadWaitTimeout + ", doThreading=" + doThreading + ", workManagerFactory="
 220  
                         + workManagerFactory + ", rejectedExecutionHandler=" + rejectedExecutionHandler
 221  
                         + ", threadFactory=" + threadFactory + "}";
 222  
     }
 223  
 
 224  0
     public static class DefaultWorkManagerFactory implements WorkManagerFactory, MuleContextAware
 225  
     {
 226  
 
 227  
         protected MuleContext muleContext;
 228  
 
 229  
         public WorkManager createWorkManager(ThreadingProfile profile, String name, int shutdownTimeout)
 230  
         {
 231  0
             final WorkManager workManager = new MuleWorkManager(profile, name, shutdownTimeout);
 232  0
             if (muleContext != null)
 233  
             {
 234  0
                 MuleContextAware contextAware = (MuleContextAware) workManager;
 235  0
                 contextAware.setMuleContext(muleContext);
 236  
             }
 237  
 
 238  0
             return workManager;
 239  
         }
 240  
 
 241  
         public void setMuleContext(MuleContext context)
 242  
         {
 243  0
             this.muleContext = context;
 244  0
         }
 245  
     }
 246  
 
 247  
 }