Package org.apache.camel.spi

Examples of org.apache.camel.spi.ThreadPoolProfile


        // lookup and use custom profiles from the registry
        Map<String, ThreadPoolProfile> profiles = context.getRegistry().lookupByType(ThreadPoolProfile.class);
        if (profiles != null && !profiles.isEmpty()) {
            for (Entry<String, ThreadPoolProfile> entry : profiles.entrySet()) {
                ThreadPoolProfile profile = entry.getValue();
                // do not add if already added, for instance a tracer that is also an InterceptStrategy class
                if (profile.isDefaultProfile()) {
                    LOG.info("Using custom default ThreadPoolProfile with id: " + entry.getKey() + " and implementation: " + profile);
                    context.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
                    defaultIds.add(entry.getKey());
                } else {
                    context.getExecutorServiceManager().registerThreadPoolProfile(profile);
View Full Code Here


     * @param context    the camel context
     * @return           the profile
     * @throws Exception is thrown if error creating the profile
     */
    private ThreadPoolProfile asThreadPoolProfile(CamelContext context, ThreadPoolProfileDefinition definition) throws Exception {
        ThreadPoolProfile answer = new ThreadPoolProfile();
        answer.setId(definition.getId());
        answer.setDefaultProfile(definition.getDefaultProfile());
        answer.setPoolSize(CamelContextHelper.parseInteger(context, definition.getPoolSize()));
        answer.setMaxPoolSize(CamelContextHelper.parseInteger(context, definition.getMaxPoolSize()));
        answer.setKeepAliveTime(CamelContextHelper.parseLong(context, definition.getKeepAliveTime()));
        answer.setMaxQueueSize(CamelContextHelper.parseInteger(context, definition.getMaxQueueSize()));
        answer.setRejectedPolicy(definition.getRejectedPolicy());
        answer.setTimeUnit(definition.getTimeUnit());
        return answer;
    }
View Full Code Here

            // none was configured so create an executor based on the other parameters
            if (poolSize == null || poolSize <= 0) {
                // use the cached thread pool
                executorService = routeContext.getCamelContext().getExecutorServiceStrategy().newDefaultThreadPool(this, name);
            } else {
                ThreadPoolProfile profile = routeContext.getCamelContext().getExecutorServiceStrategy().getDefaultThreadPoolProfile();
                // use the default thread pool profile as base and then override with values
                // use a custom pool based on the settings
                int max = getMaxPoolSize() != null ? getMaxPoolSize() : profile.getMaxPoolSize();
                long keepAlive = getKeepAliveTime() != null ? getKeepAliveTime() : profile.getKeepAliveTime();
                int maxQueue = getMaxQueueSize() != null ? getMaxQueueSize() : profile.getMaxQueueSize();
                TimeUnit tu = getTimeUnit() != null ? getTimeUnit() : profile.getTimeUnit();
                RejectedExecutionHandler rejected = profile.getRejectedExecutionHandler();
                if (rejectedPolicy != null) {
                    rejected = rejectedPolicy.asRejectedExecutionHandler();
                }

                executorService = routeContext.getCamelContext().getExecutorServiceStrategy()
View Full Code Here

    }

    public void testDefaultThreadPoolProfile() throws Exception {
        CamelContext context = getMandatoryBean(CamelContext.class, "camel");

        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getDefaultThreadPoolProfile();
        assertEquals(25, profile.getMaxPoolSize().intValue());

        // should inherit default values
        assertEquals(10, profile.getPoolSize().intValue());
        assertEquals(60, profile.getKeepAliveTime().longValue());
        assertEquals(1000, profile.getMaxQueueSize().intValue());
        assertEquals(ThreadPoolRejectedPolicy.CallerRuns, profile.getRejectedPolicy());
    }
View Full Code Here

    }

    public void testDefaultThreadPoolProfile() throws Exception {
        CamelContext context = getMandatoryBean(CamelContext.class, "camel");

        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getDefaultThreadPoolProfile();
        assertEquals(5, profile.getPoolSize().intValue());
        assertEquals(15, profile.getMaxPoolSize().intValue());
        assertEquals(25, profile.getKeepAliveTime().longValue());
        assertEquals(250, profile.getMaxQueueSize().intValue());
        assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
    }
View Full Code Here

    }

    public void testLowProfile() throws Exception {
        CamelContext context = getMandatoryBean(CamelContext.class, "camel");

        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getThreadPoolProfile("low");
        assertEquals(1, profile.getPoolSize().intValue());
        assertEquals(5, profile.getMaxPoolSize().intValue());
        assertEquals(null, profile.getKeepAliveTime());
        assertEquals(null, profile.getMaxQueueSize());
        assertEquals(null, profile.getRejectedPolicy());

        // create a thread pool from low
        ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this, "MyLow", "low");
        ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
        assertEquals(1, tp.getCorePoolSize());
View Full Code Here

    }

    public void testBigProfile() throws Exception {
        CamelContext context = getMandatoryBean(CamelContext.class, "camel");

        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getThreadPoolProfile("big");
        assertEquals(50, profile.getPoolSize().intValue());
        assertEquals(100, profile.getMaxPoolSize().intValue());
        assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
        assertEquals(null, profile.getKeepAliveTime());
        assertEquals(null, profile.getMaxQueueSize());

        // create a thread pool from big
        ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this, "MyBig", "big");
        ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
        assertEquals(50, tp.getCorePoolSize());
View Full Code Here

    }

    public void testDefaultThreadPoolProfile() throws Exception {
        CamelContext context = getMandatoryBean(CamelContext.class, "camel");

        ThreadPoolProfile profile = context.getExecutorServiceStrategy().getDefaultThreadPoolProfile();
        assertEquals(5, profile.getPoolSize().intValue());
        assertEquals(15, profile.getMaxPoolSize().intValue());
        assertEquals(25, profile.getKeepAliveTime().longValue());
        assertEquals(250, profile.getMaxQueueSize().intValue());
        assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
    }
View Full Code Here

    public DefaultExecutorServiceStrategy(CamelContext camelContext) {
        this.camelContext = camelContext;

        // create and register the default profile
        this.defaultThreadPoolProfileId = "defaultThreadPoolProfile";
        ThreadPoolProfile defaultProfile = new ThreadPoolProfileSupport(defaultThreadPoolProfileId);
        // the default profile has the following values
        defaultProfile.setDefaultProfile(true);
        defaultProfile.setPoolSize(10);
        defaultProfile.setMaxPoolSize(20);
        defaultProfile.setKeepAliveTime(60L);
        defaultProfile.setTimeUnit(TimeUnit.SECONDS);
        defaultProfile.setMaxQueueSize(1000);
        defaultProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
        registerThreadPoolProfile(defaultProfile);
    }
View Full Code Here

    public ThreadPoolProfile getDefaultThreadPoolProfile() {
        return getThreadPoolProfile(defaultThreadPoolProfileId);
    }

    public void setDefaultThreadPoolProfile(ThreadPoolProfile defaultThreadPoolProfile) {
        ThreadPoolProfile oldProfile = threadPoolProfiles.remove(defaultThreadPoolProfileId);
        if (oldProfile != null) {
            // the old is no longer default
            oldProfile.setDefaultProfile(false);

            // fallback and use old default values for new default profile if absent (convention over configuration)
            if (defaultThreadPoolProfile.getKeepAliveTime() == null) {
                defaultThreadPoolProfile.setKeepAliveTime(oldProfile.getKeepAliveTime());
            }
            if (defaultThreadPoolProfile.getMaxPoolSize() == null) {
                defaultThreadPoolProfile.setMaxPoolSize(oldProfile.getMaxPoolSize());
            }
            if (defaultThreadPoolProfile.getRejectedPolicy() == null) {
                defaultThreadPoolProfile.setRejectedPolicy(oldProfile.getRejectedPolicy());
            }
            if (defaultThreadPoolProfile.getMaxQueueSize() == null) {
                defaultThreadPoolProfile.setMaxQueueSize(oldProfile.getMaxQueueSize());
            }
            if (defaultThreadPoolProfile.getPoolSize() == null) {
                defaultThreadPoolProfile.setPoolSize(oldProfile.getPoolSize());
            }
            if (defaultThreadPoolProfile.getTimeUnit() == null) {
                defaultThreadPoolProfile.setTimeUnit(oldProfile.getTimeUnit());
            }
        }

        // validate that all options has been given as its mandatory for a default thread pool profile
        // as it is used as fallback for other profiles if they do not have that particular value
View Full Code Here

TOP

Related Classes of org.apache.camel.spi.ThreadPoolProfile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.