public ImmutableThreadingProfile(ThreadingProfile tp) { this(tp.getMaxThreadsActive(), tp.getMaxThreadsIdle(), tp.getMaxBufferSize(), tp.getThreadTTL(), tp.getThreadWaitTimeout(), tp.getPoolExhaustedAction(), tp.isDoThreading(), tp.getRejectedExecutionHandler(), tp.getThreadFactory()); }
protected ThreadingProfile createThreadingProfile(MuleContext muleContext) { ThreadingProfile threadingProfile = new ChainedThreadingProfile(muleContext.getDefaultThreadingProfile()); if (maxThreads != null) { threadingProfile.setMaxThreadsActive(maxThreads); } if (minThreads != null) { threadingProfile.setMaxThreadsIdle(minThreads); } if (maxBufferSize != null) { threadingProfile.setMaxBufferSize(maxBufferSize); } if (threadTTL != null) { threadingProfile.setThreadTTL(threadTTL); } if (threadWaitTimeout != null) { threadingProfile.setThreadWaitTimeout(threadWaitTimeout); } if (poolExhaustedAction != null) { threadingProfile.setPoolExhaustedAction(poolExhaustedAction); } threadingProfile.setMuleContext(muleContext); return threadingProfile; }
public AsyncInterceptingMessageProcessor(ThreadingProfile threadingProfile, String name, int shutdownTimeout) { this.doThreading = threadingProfile.isDoThreading(); this.threadTimeout = threadingProfile.getThreadWaitTimeout(); workManager = threadingProfile.createWorkManager(name, shutdownTimeout); workManagerSource = new WorkManagerSource() { @Override public WorkManager getWorkManager() throws MuleException { return workManager; } }; }
protected ThreadPoolExecutor internalCreatePool(String name, ThreadingProfile tp, BlockingQueue buffer) { return new ThreadPoolExecutor(Math.min(tp.getMaxThreadsIdle(), tp.getMaxThreadsActive()), tp.getMaxThreadsActive(), tp.getThreadTTL(), TimeUnit.MILLISECONDS, buffer); }
public int getMaxThreadsActive() { return null != maxThreadsActive ? maxThreadsActive : delegate.getMaxThreadsActive(); }
@Override public ThreadPoolExecutor createPool(String name, ThreadingProfile tp) { BlockingQueue buffer; if (tp.getMaxBufferSize() > 0 && tp.getMaxThreadsActive() > 1) { buffer = new LinkedBlockingDeque(tp.getMaxBufferSize()); } else { buffer = new SynchronousQueue(); } ThreadPoolExecutor pool = internalCreatePool(name, tp, buffer); configureThreadPoolExecutor(name, tp, pool); return pool; }
@Override protected void doInitialise() throws InitialisationException { if (tcpProtocol != null) { try { muleContext.getInjector().inject(getTcpProtocol()); } catch (MuleException e) { throw new InitialisationException(e, this); } } socketFactory.setConnectionTimeout(getConnectionTimeout()); socketsPool.setFactory(getSocketFactory()); socketsPool.setTestOnBorrow(true); socketsPool.setTestOnReturn(true); socketsPool.setMaxActive(getDispatcherThreadingProfile().getMaxThreadsActive()); socketsPool.setMaxIdle(getDispatcherThreadingProfile().getMaxThreadsIdle()); socketsPool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK); socketsPool.setMaxWait(socketMaxWait); // Use connector's classloader so that other temporary classloaders // aren't used when things are started lazily or from elsewhere. final String monitorName = String.format("%s%s.socket", ThreadNameHelper.getPrefix(muleContext), getName()); keepAliveMonitor = new ExpiryMonitor(monitorName, 1000, this.getClass().getClassLoader(), muleContext, false); }
protected void configureDispatcherPool() { // Normally having a the same maximum number of dispatcher objects as threads // is ok. int maxDispatchersActive = getDispatcherThreadingProfile().getMaxThreadsActive(); // BUT if the WHEN_EXHAUSTED_RUN threading profile exhausted action is // configured then a single // additional dispatcher is required that can be used by the caller thread // when it executes job's itself. // Also See: MULE-4752 if (ThreadingProfile.WHEN_EXHAUSTED_RUN == getDispatcherThreadingProfile().getPoolExhaustedAction()) { maxDispatchersActive++; } setMaxDispatchersActive(maxDispatchersActive); }
connector.setMaxDispatchersActive(threads); connector.setMaxRequestersActive(threads); connector.getReceiverThreadingProfile().setMaxThreadsActive(threads); connector.getReceiverThreadingProfile().setMaxThreadsIdle(threads);
WorkManager newWorkManager = this.getReceiverThreadingProfile().createWorkManager( threadPrefix, muleContext.getConfiguration().getShutdownTimeout()); if (dispatcherThreadingProfile.getMuleContext() == null) dispatcherThreadingProfile.setMuleContext(muleContext); WorkManager newWorkManager = dispatcherThreadingProfile.createWorkManager( threadPrefix, muleContext.getConfiguration().getShutdownTimeout()); WorkManager newWorkManager = this.getRequesterThreadingProfile().createWorkManager( threadPrefix, muleContext.getConfiguration().getShutdownTimeout());
protected ScheduledThreadPoolExecutor internalCreateScheduledPool(ThreadingProfile tp) { ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(tp.getMaxThreadsIdle()); scheduledThreadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(true); scheduledThreadPoolExecutor.setKeepAliveTime(tp.getThreadTTL(), TimeUnit.MILLISECONDS); return scheduledThreadPoolExecutor; } }
@Override public void initialise() throws InitialisationException { if (asynchronous) { if (asyncPool == null) { asyncPool = muleContext.getDefaultThreadingProfile().createPool("spring-events"); } } else { if (asyncPool != null) { asyncPool.shutdown(); asyncPool = null; } } }
public WorkManager createWorkManager(FlowConstruct flowConstruct) { MuleContext muleContext = flowConstruct.getMuleContext(); ThreadingProfile threadingProfile = createThreadingProfile(muleContext); if (poolExhaustedAction == null) { threadingProfile.setPoolExhaustedAction(WHEN_EXHAUSTED_WAIT); } MuleWorkManager workManager = (MuleWorkManager) threadingProfile.createWorkManager (getThreadPoolName(flowConstruct.getName(), muleContext), muleContext.getConfiguration() .getShutdownTimeout()); return workManager; }
if (threadingProfile.isDoThreading()) workManager = threadingProfile.createWorkManager( ThreadNameHelper.getPrefix(muleContext) + "ScatterGatherWorkManager", muleContext.getConfiguration().getShutdownTimeout());
workerThreadingProfile.setMaxThreadsActive(DEFAULT_MAX_THREADS);
public int getMaxThreadsIdle() { return null != maxThreadsIdle ? maxThreadsIdle : delegate.getMaxThreadsIdle(); }
private WorkManager createWorkManager() { final WorkManager workManager = workerThreadingProfile.createWorkManager(format("%s%s.%s", ThreadNameHelper.getPrefix(muleContext), name, "worker"), muleContext.getConfiguration().getShutdownTimeout()); if (workManager instanceof MuleContextAware) { ((MuleContextAware) workManager).setMuleContext(muleContext); } return workManager; }
/** * The preferred number of messages to process in the current batch. We need to * drain the queue quickly, but not by slamming the workManager too hard. It is * impossible to determine this more precisely without proper load * statistics/feedback or some kind of "event cost estimate". Therefore we just * try to use half of the receiver's workManager, since it is shared with * receivers for other endpoints. TODO make this user-settable * * @param available the number if messages currently available to be processed */ protected int getBatchSize(int available) { if (available <= 0) { return 0; } int maxThreads = connector.getReceiverThreadingProfile().getMaxThreadsActive(); return Math.max(1, Math.min(available, ((maxThreads / 2) - 1))); }
public synchronized void start() throws MuleException { gracefulShutdownTimeout = getMuleContext().getConfiguration().getShutdownTimeout(); if (workExecutorService == null) { workExecutorService = threadingProfile.createPool(name); } }
public MutableThreadingProfile(ThreadingProfile tp) { this.maxThreadsActive = tp.getMaxThreadsActive(); this.maxThreadsIdle = tp.getMaxThreadsIdle(); this.maxBufferSize = tp.getMaxBufferSize(); this.threadTTL = tp.getThreadTTL(); this.threadWaitTimeout = tp.getThreadWaitTimeout(); this.poolExhaustedAction = tp.getPoolExhaustedAction(); this.doThreading = tp.isDoThreading(); this.rejectedExecutionHandler = tp.getRejectedExecutionHandler(); this.threadFactory = tp.getThreadFactory(); this.workManagerFactory = tp.getWorkManagerFactory(); this.poolFactory = tp.getPoolFactory(); }