public <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type) { // jmx must be enabled if (getManagementStrategy().getManagementAgent() == null) { return null; } Route route = getRoute(routeId); if (route != null) { try { ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForRoute(route); return getManagementStrategy().getManagementAgent().newProxyClient(on, type); } catch (MalformedObjectNameException e) { throw ObjectHelper.wrapRuntimeCamelException(e); } } return null; }
public void testStopRoute() throws Exception { // JMX tests dont work well on AIX CI servers (hangs them) if (isPlatform("aix")) { return; } // fire a message to get it running getMockEndpoint("mock:result").expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); MBeanServer mbeanServer = getMBeanServer(); Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null); assertEquals(1, set.size()); ObjectName on = set.iterator().next(); ManagedRouteMBean mbean = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class); // the route has this starting endpoint uri assertEquals("direct://start", mbean.getEndpointUri()); // should be started assertEquals("Should be started", ServiceStatus.Started.name(), mbean.getState()); mbean.stop(); // should be stopped assertEquals("Should be stopped", ServiceStatus.Stopped.name(), mbean.getState()); }
@Test public void testOldestReporter() throws Exception { getMockEndpoint("mock:done").expectedMessageCount(size); ManagedRouteMBean route = context.getManagedRoute("myRoute", ManagedRouteMBean.class); OldestDurationReporter reporter = new OldestDurationReporter(route); // schedule a background task that logs the current throttle count scheduler = context.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "OldestReporter"); scheduler.scheduleAtFixedRate(reporter, 1, 1, TimeUnit.SECONDS); // send some orders for (int i = 0; i < size; i++) { template.sendBody("seda:foo", "Message " + i); } assertMockEndpointsSatisfied(1, TimeUnit.MINUTES); // just a little delay before running Thread.sleep(5000); resetMocks(); getMockEndpoint("mock:done").expectedMessageCount(size); log.info("Running again a 2nd time"); // send some orders for (int i = 0; i < size; i++) { template.sendBody("seda:foo", "2nd-Message " + i); } assertMockEndpointsSatisfied(1, TimeUnit.MINUTES); // shutdown thread pool context.getExecutorServiceManager().shutdown(scheduler); }
@Test public void testExchangesCompleted() throws Exception { ManagedRouteMBean route = context.getManagedRoute(context.getRoute("consumer-route").getId(), ManagedRouteMBean.class); assertThat("Number of exchanges completed is incorrect!", route.getExchangesCompleted(), equalTo(1L)); }
public OldestDurationReporter(ManagedRouteMBean route) { this.route = route; }
@Override public <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type) { return context.getManagedRoute(routeId, type); }
@Test public void test() throws Exception { assertThat("Number of routes is incorrect!", context.getRoutes().size(), is(equalTo(1))); ManagedRouteMBean route = context.getManagedRoute(context.getRoutes().get(0).getId(), ManagedRouteMBean.class); assertThat("Number of exchanges completed is incorrect!", route.getExchangesCompleted(), is(equalTo(1L))); }
/** * Gets the managed route client api with the given route id * * @param routeId id of the route * @param type the managed route type from the {@link org.apache.camel.api.management.mbean} package. * @return the route or <tt>null</tt> if not found * @throws IllegalArgumentException if the type is not compliant */ <T extends ManagedRouteMBean> T getManagedRoute(String routeId, Class<T> type);