本文整理汇总了Java中org.apache.camel.util.ServiceHelper.suspendService方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceHelper.suspendService方法的具体用法?Java ServiceHelper.suspendService怎么用?Java ServiceHelper.suspendService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.ServiceHelper
的用法示例。
在下文中一共展示了ServiceHelper.suspendService方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stopConsumer
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
public boolean stopConsumer(Consumer consumer) throws Exception {
boolean suspended = ServiceHelper.suspendService(consumer);
if (suspended) {
log.debug("Suspended consumer {}", consumer);
}
return suspended;
}
示例2: suspendNow
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
/**
* Suspends/stops the consumer immediately.
*
* @param consumer the consumer to suspend
*/
protected static void suspendNow(Consumer consumer) {
LOG.trace("Suspending: {}", consumer);
// allow us to do custom work before delegating to service helper
try {
ServiceHelper.suspendService(consumer);
} catch (Throwable e) {
LOG.warn("Error occurred while suspending route: " + consumer + ". This exception will be ignored.", e);
// fire event
EventHelper.notifyServiceStopFailure(consumer.getEndpoint().getCamelContext(), consumer, e);
}
LOG.trace("Suspend complete for: {}", consumer);
}
示例3: afterPoll
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Override
public void afterPoll() throws Exception {
LOG.trace("After poll {}", getEndpoint());
// suspend or stop our self
if (!ServiceHelper.suspendService(this)) {
ServiceHelper.stopService(this);
}
}
示例4: testScheduledResumeRoutePolicy
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long startTime = System.currentTimeMillis() + 3000L;
policy.setRouteResumeDate(new Date(startTime));
policy.setRouteResumeRepeatCount(1);
policy.setRouteResumeRepeatInterval(3000);
from("direct:start")
.routeId("test")
.routePolicy(policy)
.to("mock:success");
}
});
context.start();
ServiceHelper.suspendService(context.getRoute("test").getConsumer());
try {
template.sendBody("direct:start", "Ready or not, Here, I come");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
LOG.debug("Consumer successfully suspended");
}
Thread.sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
context.getComponent("quartz2", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
示例5: testScheduledResumeRoutePolicy
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz2", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteResumeTime("*/3 * * * * ?");
from("direct:start")
.routeId("test")
.routePolicy(policy)
.to("mock:success");
}
});
context.start();
ServiceHelper.suspendService(context.getRoute("test").getConsumer());
Thread.sleep(5000);
assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
template.sendBody("direct:start", "Ready or not, Here, I come");
success.assertIsSatisfied();
}
示例6: resumeTest
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
public void resumeTest() throws Exception {
CamelContext context = startRouteWithPolicy("resumePolicy");
MockEndpoint mock = context.getEndpoint("mock:success", MockEndpoint.class);
mock.expectedMinimumMessageCount(1);
ServiceHelper.suspendService(context.getRoute("testRoute").getConsumer());
Thread.sleep(4000);
context.createProducerTemplate().sendBody("direct:start", "Ready or not, Here, I come");
context.stop();
mock.assertIsSatisfied();
}
示例7: testScheduledResumeRoutePolicy
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
long startTime = System.currentTimeMillis() + 3000L;
policy.setRouteResumeDate(new Date(startTime));
policy.setRouteResumeRepeatCount(1);
policy.setRouteResumeRepeatInterval(3000);
from("direct:start")
.routeId("test")
.routePolicy(policy)
.to("mock:success");
}
});
context.start();
ServiceHelper.suspendService(context.getRoute("test").getConsumer());
try {
template.sendBody("direct:start", "Ready or not, Here, I come");
fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
LOG.debug("Consumer successfully suspended");
}
Thread.sleep(4000);
template.sendBody("direct:start", "Ready or not, Here, I come");
context.getComponent("quartz", QuartzComponent.class).stop();
success.assertIsSatisfied();
}
示例8: testScheduledResumeRoutePolicy
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Test
public void testScheduledResumeRoutePolicy() throws Exception {
MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
success.expectedMessageCount(1);
context.getComponent("quartz", QuartzComponent.class).setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
context.addRoutes(new RouteBuilder() {
public void configure() {
CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
policy.setRouteResumeTime("*/3 * * * * ?");
from("direct:start")
.routeId("test")
.routePolicy(policy)
.to("mock:success");
}
});
context.start();
ServiceHelper.suspendService(context.getRoute("test").getConsumer());
Thread.sleep(5000);
assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
template.sendBody("direct:start", "Ready or not, Here, I come");
success.assertIsSatisfied();
}
示例9: doSuspend
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Override
protected void doSuspend() throws Exception {
ServiceHelper.suspendService(processor);
}
示例10: testSuspendResume
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
public void testSuspendResume() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:bar");
mock.expectedMessageCount(1);
template.sendBody("seda:foo", "A");
mock.assertIsSatisfied();
assertEquals("Started", context.getRouteStatus("foo").name());
assertEquals("Started", context.getRouteStatus("bar").name());
// suspend bar consumer (not the route)
SedaConsumer consumer = (SedaConsumer) context.getRoute("bar").getConsumer();
ServiceHelper.suspendService(consumer);
assertEquals("Suspended", consumer.getStatus().name());
// send a message to the route but the consumer is suspended
// so it should not route it
resetMocks();
mock.expectedMessageCount(0);
// wait a bit to ensure consumer is suspended, as it could be in a poll mode where
// it would poll and route (there is a little slack (up till 1 sec) before suspension is empowered)
Thread.sleep(2000);
template.sendBody("seda:foo", "B");
// wait 2 sec to ensure seda consumer thread would have tried to poll otherwise
mock.assertIsSatisfied(2000);
// resume consumer
resetMocks();
mock.expectedMessageCount(1);
// resume bar consumer (not the route)
ServiceHelper.resumeService(consumer);
assertEquals("Started", consumer.getStatus().name());
// the message should be routed now
mock.assertIsSatisfied();
}
示例11: doSuspend
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Override
protected void doSuspend() throws Exception {
ServiceHelper.suspendService(nettyServerBootstrapFactory);
super.doSuspend();
}
示例12: testSuspendResume
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
@Test
public void testSuspendResume() throws Exception {
final MockEndpoint mock = getMockEndpoint("mock:bar");
mock.expectedMessageCount(1);
template.sendBody("disruptor:foo", "A");
mock.assertIsSatisfied();
assertEquals("Started", context.getRouteStatus("foo").name());
assertEquals("Started", context.getRouteStatus("bar").name());
// suspend bar consumer (not the route)
final DisruptorConsumer consumer = (DisruptorConsumer)context.getRoute("bar").getConsumer();
ServiceHelper.suspendService(consumer);
assertEquals("Suspended", consumer.getStatus().name());
// send a message to the route but the consumer is suspended
// so it should not route it
resetMocks();
mock.expectedMessageCount(0);
// wait a bit to ensure consumer is suspended, as it could be in a poll mode where
// it would poll and route (there is a little slack (up till 1 sec) before suspension is empowered)
Thread.sleep(2000);
template.sendBody("disruptor:foo", "B");
// wait 2 sec to ensure disruptor consumer thread would have tried to poll otherwise
mock.assertIsSatisfied(2000);
// resume consumer
resetMocks();
mock.expectedMessageCount(1);
// resume bar consumer (not the route)
ServiceHelper.resumeService(consumer);
assertEquals("Started", consumer.getStatus().name());
// the message should be routed now
mock.assertIsSatisfied();
}
示例13: onSuspend
import org.apache.camel.util.ServiceHelper; //导入方法依赖的package包/类
/**
* The consumer is to be suspended because it exceeded the limit
*
* @param consumer the consumer
* @param endpoint the endpoint
* @throws Exception is thrown if error suspending the consumer
*/
protected void onSuspend(Consumer consumer, Endpoint endpoint) throws Exception {
log.warn("Suspending consumer " + consumer + " after " + limit + " attempts to consume from " + endpoint
+ ". You have to manually resume the consumer!");
ServiceHelper.suspendService(consumer);
}