Java 类org.apache.camel.ThreadPoolRejectedPolicy 实例源码

项目:eds    文件:EdsCamelConfig.java   
/**  
    * thread pool of consumer
    */
    @Bean(name="defaultThreadPoolProfile")
    ThreadPoolProfile threadPoolProfile(){
        ThreadPoolProfile defaultThreadPoolProfile = new ThreadPoolProfile();
        defaultThreadPoolProfile.setDefaultProfile(true);
        defaultThreadPoolProfile.setId("defaultThreadPoolProfile");
        defaultThreadPoolProfile.setPoolSize(threadPoolSize);
        defaultThreadPoolProfile.setMaxPoolSize(threadMaxPoolSize);
        defaultThreadPoolProfile.setMaxQueueSize(threadMaxQueueSize); // 队列最大程度1000万
        defaultThreadPoolProfile.setTimeUnit(TimeUnit.SECONDS);
        defaultThreadPoolProfile.setKeepAliveTime(60 * 5L);
        defaultThreadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
//      camelContext().getExecutorServiceManager().registerThreadPoolProfile(defaultThreadPoolProfile);
//      setDefaultThreadPoolProfile(defaultThreadPoolProfile);
        return defaultThreadPoolProfile;
    }
项目:Camel    文件:AggregateThreadPoolProfileTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create and register thread pool profile
            ThreadPoolProfile profile = new ThreadPoolProfile("myProfile");
            profile.setPoolSize(2);
            profile.setMaxPoolSize(8);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start")
                .aggregate(header("id"), new BodyInAggregatingStrategy())
                    // use our custom thread pool profile
                    .completionSize(3).executorServiceRef("myProfile")
                    .to("log:foo")
                    .to("mock:aggregated");
        }
    };
}
项目:Camel    文件:DualManagedThreadPoolProfileTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("custom");
            profile.setPoolSize(5);
            profile.setMaxPoolSize(15);
            profile.setKeepAliveTime(25L);
            profile.setMaxQueueSize(250);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);

            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start").threads().executorServiceRef("custom").to("mock:result");

            from("direct:foo").threads().executorServiceRef("custom").to("mock:foo");
        }
    };
}
项目:Camel    文件:ManagedThreadPoolProfileTest.java   
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("custom");
            profile.setPoolSize(5);
            profile.setMaxPoolSize(15);
            profile.setKeepAliveTime(25L);
            profile.setMaxQueueSize(250);
            profile.setAllowCoreThreadTimeOut(true);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);

            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start").threads().executorServiceRef("custom").to("mock:result");
        }
    };
}
项目:Camel    文件:DefaultExecutorServiceManagerTest.java   
public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
    ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
    newDefault.setKeepAliveTime(30L);
    newDefault.setMaxPoolSize(50);
    newDefault.setPoolSize(5);
    newDefault.setMaxQueueSize(2000);
    newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);

    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setMaxPoolSize(25);
    foo.setPoolSize(1);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));

    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");

    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(25, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
项目:Camel    文件:DefaultExecutorServiceStrategyTest.java   
public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
    ThreadPoolProfileSupport newDefault = new ThreadPoolProfileSupport("newDefault");
    newDefault.setKeepAliveTime(30L);
    newDefault.setMaxPoolSize(50);
    newDefault.setPoolSize(5);
    newDefault.setMaxQueueSize(2000);
    newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(newDefault);

    assertNull(context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));
    ThreadPoolProfileSupport foo = new ThreadPoolProfileSupport("foo");
    foo.setMaxPoolSize(25);
    foo.setPoolSize(1);
    context.getExecutorServiceStrategy().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));

    ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this, "MyPool", "foo");

    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(25, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
项目:Camel    文件:TimerAsyncTest.java   
public void testAsyncRouting() throws Exception {
    final int threads = 5;

    // should trigger many tasks as we are async
    getMockEndpoint("mock:task").expectedMinimumMessageCount(20);

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("timer://foo?fixedRate=true&delay=0&period=200").id("timer")
                    .threads(threads, threads).maxQueueSize(1).rejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns)
                    .to("log:task")
                    .to("mock:task")
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            // simulate long task
                            TimeUnit.SECONDS.sleep(1);
                        }
                    });
        }
    });
    context.start();

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:SpringCamelContextThreadPoolProfilesTest.java   
public void testBigProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");

    ThreadPoolProfile profile = context.getExecutorServiceManager().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.getExecutorServiceManager().newThreadPool(this, "MyBig", "big");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(50, tp.getCorePoolSize());
    assertEquals(100, tp.getMaximumPoolSize());
    // should inherit default options
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("DiscardOldest", tp.getRejectedExecutionHandler().toString());
}
项目:openex-worker    文件:OpenexContext.java   
private ThreadPoolProfile threadPoolProfileRemote() {
    //Define custom thread pool profile
    ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("openex-remote-thread-profile");
    threadPoolProfile.setPoolSize(10);
    threadPoolProfile.setMaxPoolSize(20);
    threadPoolProfile.setMaxQueueSize(500);
    threadPoolProfile.setAllowCoreThreadTimeOut(false);
    threadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.Discard);
    return threadPoolProfile;
}
项目:openex-worker    文件:OpenexContext.java   
private ThreadPoolProfile threadPoolProfileExecutor() {
    //Define custom thread pool profile
    ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("openex-worker-thread-profile");
    threadPoolProfile.setPoolSize(20);
    threadPoolProfile.setMaxPoolSize(40);
    threadPoolProfile.setMaxQueueSize(1000);
    threadPoolProfile.setAllowCoreThreadTimeOut(false);
    threadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
    return threadPoolProfile;
}
项目:Camel    文件:ThreadsDefinition.java   
protected ThreadPoolRejectedPolicy resolveRejectedPolicy(RouteContext routeContext) {
    if (getExecutorServiceRef() != null && getRejectedPolicy() == null) {
        ThreadPoolProfile threadPoolProfile = routeContext.getCamelContext().getExecutorServiceManager().getThreadPoolProfile(getExecutorServiceRef());
        if (threadPoolProfile != null) {
            return threadPoolProfile.getRejectedPolicy();
        }
    }
    return getRejectedPolicy();
}
项目:Camel    文件:ThreadsProcessor.java   
public ThreadsProcessor(CamelContext camelContext, ExecutorService executorService, boolean shutdownExecutorService, ThreadPoolRejectedPolicy rejectedPolicy) {
    ObjectHelper.notNull(camelContext, "camelContext");
    ObjectHelper.notNull(executorService, "executorService");
    ObjectHelper.notNull(rejectedPolicy, "rejectedPolicy");
    this.camelContext = camelContext;
    this.executorService = executorService;
    this.shutdownExecutorService = shutdownExecutorService;
    this.rejectedPolicy = rejectedPolicy;
}
项目:Camel    文件:DefaultExecutorServiceManager.java   
public DefaultExecutorServiceManager(CamelContext camelContext) {
    this.camelContext = camelContext;

    defaultProfile = new ThreadPoolProfile(defaultThreadPoolProfileId);
    defaultProfile.setDefaultProfile(true);
    defaultProfile.setPoolSize(10);
    defaultProfile.setMaxPoolSize(20);
    defaultProfile.setKeepAliveTime(60L);
    defaultProfile.setTimeUnit(TimeUnit.SECONDS);
    defaultProfile.setMaxQueueSize(1000);
    defaultProfile.setAllowCoreThreadTimeOut(false);
    defaultProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);

    registerThreadPoolProfile(defaultProfile);
}
项目:Camel    文件:ThreadsRejectedExecutionWithDeadLetterTest.java   
public void testThreadsRejectedExecution() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start").errorHandler(deadLetterChannel("mock:failed"))
                    .to("log:before")
                    // will use our custom pool
                    .threads()
                    .maxPoolSize(1).poolSize(1) // 1 thread max
                    .maxQueueSize(1)            // 1 queued task
                    //(Test fails whatever the chosen policy below)
                    .rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    getMockEndpoint("mock:result").expectedMessageCount(2);
    getMockEndpoint("mock:failed").expectedMessageCount(1);

    template.sendBody("seda:start", "Hello World"); // will block
    template.sendBody("seda:start", "Hi World");    // will be queued
    template.sendBody("seda:start", "Bye World");   // will be rejected

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:ThreadsRejectedExecutionWithDeadLetterTest.java   
public void testThreadsRejectedExecutionWithRedelivery() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start").errorHandler(deadLetterChannel("mock:failed").maximumRedeliveries(5))
                    .to("log:before")
                    // will use our custom pool
                    .threads()
                    .maxPoolSize(1).poolSize(1) // 1 thread max
                    .maxQueueSize(1)            // 1 queued task
                    //(Test fails whatever the chosen policy below)
                    .rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    getMockEndpoint("mock:result").expectedMessageCount(3);
    getMockEndpoint("mock:failed").expectedMessageCount(0);

    template.sendBody("seda:start", "Hello World"); // will block
    template.sendBody("seda:start", "Hi World");    // will be queued
    template.sendBody("seda:start", "Bye World");   // will be rejected and queued on redelivery later

    assertMockEndpointsSatisfied();
}
项目:Camel    文件:ThreadsRejectedExecutionTest.java   
public void testThreadsRejectedDiscard() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start")
                    .to("log:before")
                    .threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.Discard)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();

    getMockEndpoint("mock:result").expectedMinimumMessageCount(2);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();

    assertTrue(notify.matchesMockWaitTime());

    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
项目:Camel    文件:ThreadsRejectedExecutionTest.java   
public void testThreadsRejectedDiscardOldest() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start")
                    .to("log:before")
                    .threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();

    getMockEndpoint("mock:result").expectedMinimumMessageCount(2);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();

    assertTrue(notify.matchesMockWaitTime());

    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
项目:Camel    文件:ThreadsRejectedExecutionTest.java   
public void testThreadsRejectedAbort() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start")
                    .to("log:before")
                    .threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();

    getMockEndpoint("mock:result").expectedMinimumMessageCount(2);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();

    assertTrue(notify.matchesMockWaitTime());

    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
项目:Camel    文件:ThreadsRejectedExecutionTest.java   
public void testThreadsRejectedCallerRuns() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start")
                    .to("log:before")
                    .threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns)
                    .delay(200)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();

    getMockEndpoint("mock:result").expectedMessageCount(10);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();

    assertTrue(notify.matchesMockWaitTime());

    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
项目:Camel    文件:ThreadsRejectedExecutionTest.java   
public void testThreadsRejectedAbortNoRedelivery() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            onException(Exception.class).maximumRedeliveries(3).handled(true).to("mock:error");

            from("seda:start")
                    .to("log:before")
                    .threads(1, 1).maxPoolSize(1).maxQueueSize(2).rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    NotifyBuilder notify = new NotifyBuilder(context).whenDone(10).create();

    // there should be error handling for aborted tasks (eg no redeliveries and no error handling)
    getMockEndpoint("mock:error").expectedMessageCount(0);

    getMockEndpoint("mock:result").expectedMinimumMessageCount(2);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:start", "Message " + i);
    }
    assertMockEndpointsSatisfied();

    assertTrue(notify.matchesMockWaitTime());

    int inflight = context.getInflightRepository().size();
    assertEquals(0, inflight);
}
项目:Camel    文件:CamelCustomDefaultThreadPoolProfileTest.java   
@Override
protected CamelContext createCamelContext() throws Exception {
    CamelContext camel = super.createCamelContext();

    ThreadPoolProfile profile = new ThreadPoolProfile("custom");
    profile.setPoolSize(5);
    profile.setMaxPoolSize(15);
    profile.setKeepAliveTime(25L);
    profile.setMaxQueueSize(250);
    profile.setAllowCoreThreadTimeOut(true);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);

    camel.getExecutorServiceManager().setDefaultThreadPoolProfile(profile);
    return camel;
}
项目:Camel    文件:CamelCustomDefaultThreadPoolProfileTest.java   
public void testCamelCustomDefaultThreadPoolProfile() throws Exception {
    DefaultExecutorServiceManager manager = (DefaultExecutorServiceManager)context.getExecutorServiceManager();
    ThreadPoolProfile profile = manager.getDefaultThreadPoolProfile();
    assertEquals(5, profile.getPoolSize().intValue());
    assertEquals(15, profile.getMaxPoolSize().intValue());
    assertEquals(25, profile.getKeepAliveTime().longValue());
    assertEquals(250, profile.getMaxQueueSize().intValue());
    assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue());
    assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
项目:Camel    文件:ThreadPoolBuilderTest.java   
public void testThreadPoolBuilderAll() throws Exception {
    ThreadPoolBuilder builder = new ThreadPoolBuilder(context);
    ExecutorService executor = builder.poolSize(50).maxPoolSize(100).maxQueueSize(2000)
            .keepAliveTime(20000, TimeUnit.MILLISECONDS)
            .rejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest)
            .build(this, "myPool");
    assertNotNull(executor);

    assertEquals(false, executor.isShutdown());
    context.stop();
    assertEquals(true, executor.isShutdown());
}
项目:Camel    文件:SpringCamelContextSimpleCustomDefaultThreadPoolProfileTest.java   
public void testDefaultThreadPoolProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-B");

    ThreadPoolProfile profile = context.getExecutorServiceManager().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());
}
项目:Camel    文件:SpringCamelContextCustomDefaultThreadPoolProfileTest.java   
public void testDefaultThreadPoolProfile() throws Exception {
    SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();

    ThreadPoolProfile profile = context.getExecutorServiceManager().getDefaultThreadPoolProfile();
    assertEquals(5, profile.getPoolSize().intValue());
    assertEquals(15, profile.getMaxPoolSize().intValue());
    assertEquals(25, profile.getKeepAliveTime().longValue());
    assertEquals(250, profile.getMaxQueueSize().intValue());
    assertEquals(true, profile.getAllowCoreThreadTimeOut().booleanValue());
    assertEquals(ThreadPoolRejectedPolicy.Abort, profile.getRejectedPolicy());
}
项目:Camel    文件:SpringCamelContextCustomThreadPoolProfileTest.java   
public void testDefaultThreadPoolProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-D");

    ThreadPoolProfile profile = context.getExecutorServiceManager().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());
}
项目:camelinaction2    文件:CustomThreadPoolProfileTest.java   
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    return new ThreadPoolProfileBuilder("bigPool")
        .maxPoolSize(200)
        .rejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest)
        .build();
}
项目:switchyard    文件:RouteFactoryTest.java   
private ExecutorService createCustomThreadPool(RouteBuilder builder, String name) {
    ThreadPoolProfile profile = new ThreadPoolProfile();
    profile.setId("I48-custom-profile");
    profile.setPoolSize(50);
    profile.setMaxPoolSize(500);
    profile.setKeepAliveTime(1L);
    profile.setMaxQueueSize(1000);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    customPool = builder.getContext().getExecutorServiceManager().newThreadPool(builder, name, profile);
    return customPool;
}
项目:camelinaction    文件:CustomThreadPoolProfileTest.java   
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    ThreadPoolProfile profile = new ThreadPoolProfile("bigPool");
    profile.setMaxPoolSize(200);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest);
    return profile;
}
项目:t4f-data    文件:CustomThreadPoolProfileTest.java   
public ThreadPoolProfile createCustomProfile() {
    // create a custom thread pool profile with the name bigPool
    ThreadPoolProfile profile = new ThreadPoolProfileSupport("bigPool");
    profile.setMaxPoolSize(200);
    profile.setRejectedPolicy(ThreadPoolRejectedPolicy.DiscardOldest);
    return profile;
}
项目:Camel    文件:ThreadsDefinition.java   
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    // the threads name
    String name = getThreadName() != null ? getThreadName() : "Threads";
    // prefer any explicit configured executor service
    boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, true);
    ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, name, this, false);

    // resolve what rejected policy to use
    ThreadPoolRejectedPolicy policy = resolveRejectedPolicy(routeContext);
    if (policy == null) {
        if (callerRunsWhenRejected == null || callerRunsWhenRejected) {
            // should use caller runs by default if not configured
            policy = ThreadPoolRejectedPolicy.CallerRuns;
        } else {
            policy = ThreadPoolRejectedPolicy.Abort;
        }
    }
    log.debug("Using ThreadPoolRejectedPolicy: {}", policy);

    // if no explicit then create from the options
    if (threadPool == null) {
        ExecutorServiceManager manager = routeContext.getCamelContext().getExecutorServiceManager();
        // create the thread pool using a builder
        ThreadPoolProfile profile = new ThreadPoolProfileBuilder(name)
                .poolSize(getPoolSize())
                .maxPoolSize(getMaxPoolSize())
                .keepAliveTime(getKeepAliveTime(), getTimeUnit())
                .maxQueueSize(getMaxQueueSize())
                .rejectedPolicy(policy)
                .allowCoreThreadTimeOut(getAllowCoreThreadTimeOut())
                .build();
        threadPool = manager.newThreadPool(this, name, profile);
        shutdownThreadPool = true;
    } else {
        if (getThreadName() != null && !getThreadName().equals("Threads")) {
            throw new IllegalArgumentException("ThreadName and executorServiceRef options cannot be used together.");
        }
        if (getPoolSize() != null) {
            throw new IllegalArgumentException("PoolSize and executorServiceRef options cannot be used together.");
        }
        if (getMaxPoolSize() != null) {
            throw new IllegalArgumentException("MaxPoolSize and executorServiceRef options cannot be used together.");
        }
        if (getKeepAliveTime() != null) {
            throw new IllegalArgumentException("KeepAliveTime and executorServiceRef options cannot be used together.");
        }
        if (getTimeUnit() != null) {
            throw new IllegalArgumentException("TimeUnit and executorServiceRef options cannot be used together.");
        }
        if (getMaxQueueSize() != null) {
            throw new IllegalArgumentException("MaxQueueSize and executorServiceRef options cannot be used together.");
        }
        if (getRejectedPolicy() != null) {
            throw new IllegalArgumentException("RejectedPolicy and executorServiceRef options cannot be used together.");
        }
        if (getAllowCoreThreadTimeOut() != null) {
            throw new IllegalArgumentException("AllowCoreThreadTimeOut and executorServiceRef options cannot be used together.");
        }
    }

    ThreadsProcessor thread = new ThreadsProcessor(routeContext.getCamelContext(), threadPool, shutdownThreadPool, policy);

    List<Processor> pipe = new ArrayList<Processor>(2);
    pipe.add(thread);
    pipe.add(createChildProcessor(routeContext, true));
    // wrap in nested pipeline so this appears as one processor
    // (recipient list definition does this as well)
    return new Pipeline(routeContext.getCamelContext(), pipe) {
        @Override
        public String toString() {
            return "Threads[" + getOutputs() + "]";
        }
    };
}
项目:Camel    文件:ThreadsDefinition.java   
public ThreadPoolRejectedPolicy getRejectedPolicy() {
    return rejectedPolicy;
}
项目:Camel    文件:ThreadsDefinition.java   
public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
    this.rejectedPolicy = rejectedPolicy;
}
项目:Camel    文件:ThreadPoolProfileDefinition.java   
public ThreadPoolRejectedPolicy getRejectedPolicy() {
    return rejectedPolicy;
}
项目:Camel    文件:ThreadPoolProfileDefinition.java   
/**
 * Sets the handler for tasks which cannot be executed by the thread pool.
 */
public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
    this.rejectedPolicy = rejectedPolicy;
}
项目:Camel    文件:ThreadsProcessor.java   
public ThreadPoolRejectedPolicy getRejectedPolicy() {
    return rejectedPolicy;
}
项目:Camel    文件:AbstractCamelThreadPoolFactoryBean.java   
public ThreadPoolRejectedPolicy getRejectedPolicy() {
    return rejectedPolicy;
}
项目:Camel    文件:AbstractCamelThreadPoolFactoryBean.java   
public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
    this.rejectedPolicy = rejectedPolicy;
}
项目:Camel    文件:ThreadPoolProfile.java   
/**
 * Gets the policy for tasks which cannot be executed by the thread pool.
 *
 * @return the policy for the handler
 */
public ThreadPoolRejectedPolicy getRejectedPolicy() {
    return rejectedPolicy;
}
项目:Camel    文件:ThreadPoolProfile.java   
/**
 * Sets the handler for tasks which cannot be executed by the thread pool.
 *
 * @param rejectedPolicy  the policy for the handler
 */
public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
    this.rejectedPolicy = rejectedPolicy;
}