Coverage Report - org.mule.config.MutableThreadingProfile
 
Classes in this File Line Coverage Branch Coverage Complexity
MutableThreadingProfile
0%
0/50
N/A
1
 
 1  
 /*
 2  
  * $Id: MutableThreadingProfile.java 20321 2010-11-24 15:21:24Z dfeist $
 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.WorkManager;
 16  
 import org.mule.config.pool.ThreadPoolFactory;
 17  
 
 18  
 import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
 19  
 import edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionHandler;
 20  
 import edu.emory.mathcs.backport.java.util.concurrent.ThreadFactory;
 21  
 
 22  
 /**
 23  
  * Partial mutability for a threading profile. A typical use case for this class is to
 24  
  * copy an existing immutable threading profile via a copying constructor, modify values and
 25  
  * reconfigure a thread pool (if the latter supports it).<p/>
 26  
  * <p/>The following parameters are copied locally and can be modified directly:
 27  
  * <ul>
 28  
  *  <li>{@link #maxThreadsActive}
 29  
  *  <li>{@link #maxThreadsIdle}
 30  
  *  <li>{@link #maxBufferSize}
 31  
  *  <li>{@link #threadTTL}
 32  
  *  <li>{@link #threadWaitTimeout}
 33  
  *  <li>{@link #poolExhaustedAction}
 34  
  *  <li>{@link #doThreading}
 35  
  * </ul>
 36  
  * <p/>The following parameters re-use the same object reference as the original threading
 37  
  * profile and <strong>are not deep clones</strong> of those:
 38  
  * <ul>
 39  
  *  <li>{@link #poolFactory}
 40  
  *  <li>{@link #workManagerFactory}
 41  
  *  <li>{@link #rejectedExecutionHandler}
 42  
  *  <li>{@link #threadFactory}
 43  
  * </ul>
 44  
  */
 45  
 public class MutableThreadingProfile implements ThreadingProfile
 46  
 {
 47  
 
 48  
     private int maxThreadsActive;
 49  
     private int maxThreadsIdle;
 50  
     private int maxBufferSize;
 51  
     private long threadTTL;
 52  
     private long threadWaitTimeout;
 53  
     private int poolExhaustedAction;
 54  
     private boolean doThreading;
 55  
 
 56  
     private ThreadPoolFactory poolFactory;
 57  
     private WorkManagerFactory workManagerFactory;
 58  
     private RejectedExecutionHandler rejectedExecutionHandler;
 59  
     private ThreadFactory threadFactory;
 60  
     private MuleContext muleContext;
 61  
 
 62  
     public MutableThreadingProfile(ThreadingProfile tp)
 63  0
     {
 64  0
         this.maxThreadsActive = tp.getMaxThreadsActive();
 65  0
         this.maxThreadsIdle = tp.getMaxThreadsIdle();
 66  0
         this.maxBufferSize = tp.getMaxBufferSize();
 67  0
         this.threadTTL = tp.getThreadTTL();
 68  0
         this.threadWaitTimeout = tp.getThreadWaitTimeout();
 69  0
         this.poolExhaustedAction = tp.getPoolExhaustedAction();
 70  0
         this.doThreading = tp.isDoThreading();
 71  0
         this.rejectedExecutionHandler = tp.getRejectedExecutionHandler();
 72  0
         this.threadFactory = tp.getThreadFactory();
 73  0
         this.workManagerFactory = tp.getWorkManagerFactory();
 74  0
         this.poolFactory = tp.getPoolFactory();
 75  0
     }
 76  
 
 77  
     public ExecutorService createPool()
 78  
     {
 79  0
         return createPool(null);
 80  
     }
 81  
 
 82  
     public int getMaxThreadsActive()
 83  
     {
 84  0
         return maxThreadsActive;
 85  
     }
 86  
 
 87  
     public int getMaxThreadsIdle()
 88  
     {
 89  0
         return maxThreadsIdle;
 90  
     }
 91  
 
 92  
     public long getThreadTTL()
 93  
     {
 94  0
         return threadTTL;
 95  
     }
 96  
 
 97  
     public long getThreadWaitTimeout()
 98  
     {
 99  0
         return threadWaitTimeout;
 100  
     }
 101  
 
 102  
     public int getPoolExhaustedAction()
 103  
     {
 104  0
         return poolExhaustedAction;
 105  
     }
 106  
 
 107  
     public RejectedExecutionHandler getRejectedExecutionHandler()
 108  
     {
 109  0
         return rejectedExecutionHandler;
 110  
     }
 111  
 
 112  
     public ThreadFactory getThreadFactory()
 113  
     {
 114  0
         return threadFactory;
 115  
     }
 116  
 
 117  
     public void setMaxThreadsActive(int maxThreadsActive)
 118  
     {
 119  0
         this.maxThreadsActive = maxThreadsActive;
 120  0
     }
 121  
 
 122  
     public void setMaxThreadsIdle(int maxThreadsIdle)
 123  
     {
 124  0
         this.maxThreadsIdle = maxThreadsIdle;
 125  0
     }
 126  
 
 127  
     public void setThreadTTL(long threadTTL)
 128  
     {
 129  0
         this.threadTTL = threadTTL;
 130  0
     }
 131  
 
 132  
     public void setThreadWaitTimeout(long threadWaitTimeout)
 133  
     {
 134  0
         this.threadWaitTimeout = threadWaitTimeout;
 135  0
     }
 136  
 
 137  
     public void setPoolExhaustedAction(int poolExhaustedAction)
 138  
     {
 139  0
         this.poolExhaustedAction = poolExhaustedAction;
 140  0
     }
 141  
 
 142  
     public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler)
 143  
     {
 144  0
         this.rejectedExecutionHandler = rejectedExecutionHandler;
 145  0
     }
 146  
 
 147  
     public void setThreadFactory(ThreadFactory threadFactory)
 148  
     {
 149  0
         this.threadFactory = threadFactory;
 150  0
     }
 151  
 
 152  
     public int getMaxBufferSize()
 153  
     {
 154  0
         return maxBufferSize;
 155  
     }
 156  
 
 157  
     public void setMaxBufferSize(int maxBufferSize)
 158  
     {
 159  0
         this.maxBufferSize = maxBufferSize;
 160  0
     }
 161  
 
 162  
     public WorkManagerFactory getWorkManagerFactory()
 163  
     {
 164  0
         return workManagerFactory;
 165  
     }
 166  
 
 167  
     public void setWorkManagerFactory(WorkManagerFactory workManagerFactory)
 168  
     {
 169  0
         this.workManagerFactory = workManagerFactory;
 170  0
     }
 171  
 
 172  
     public WorkManager createWorkManager(String name, int shutdownTimeout)
 173  
     {
 174  0
         return workManagerFactory.createWorkManager(new ImmutableThreadingProfile(this), name, shutdownTimeout);
 175  
     }
 176  
 
 177  
     public ExecutorService createPool(String name)
 178  
     {
 179  0
         return poolFactory.createPool(name, new ImmutableThreadingProfile(this));
 180  
     }
 181  
 
 182  
     public boolean isDoThreading()
 183  
     {
 184  0
         return doThreading;
 185  
     }
 186  
 
 187  
     public void setDoThreading(boolean doThreading)
 188  
     {
 189  0
         this.doThreading = doThreading;
 190  0
     }
 191  
 
 192  
     public ThreadPoolFactory getPoolFactory()
 193  
     {
 194  0
         return poolFactory;
 195  
     }
 196  
 
 197  
     public void setMuleContext(MuleContext muleContext)
 198  
     {
 199  0
         this.muleContext = muleContext;
 200  0
     }
 201  
 
 202  
     public MuleContext getMuleContext()
 203  
     {
 204  0
         return muleContext;
 205  
     }
 206  
 }