use of java.util.Set in project camel by apache.
the class DefaultCamelContext method removeRoute.
public synchronized boolean removeRoute(String routeId) throws Exception {
// remove the route from ErrorHandlerBuilder if possible
if (getErrorHandlerBuilder() instanceof ErrorHandlerBuilderSupport) {
ErrorHandlerBuilderSupport builder = (ErrorHandlerBuilderSupport) getErrorHandlerBuilder();
builder.removeOnExceptionList(routeId);
}
// gather a map of all the endpoints in use by the routes, so we can known if a given endpoints is in use
// by one or more routes, when we remove the route
Map<String, Set<Endpoint>> endpointsInUse = new HashMap<String, Set<Endpoint>>();
for (Map.Entry<String, RouteService> entry : routeServices.entrySet()) {
endpointsInUse.put(entry.getKey(), entry.getValue().gatherEndpoints());
}
RouteService routeService = routeServices.get(routeId);
if (routeService != null) {
if (getRouteStatus(routeId).isStopped()) {
routeService.setRemovingRoutes(true);
shutdownRouteService(routeService);
removeRouteDefinition(routeId);
routeServices.remove(routeId);
// remove route from startup order as well, as it was removed
Iterator<RouteStartupOrder> it = routeStartupOrder.iterator();
while (it.hasNext()) {
RouteStartupOrder order = it.next();
if (order.getRoute().getId().equals(routeId)) {
it.remove();
}
}
// from the route which we have removed, then remove all its private endpoints
// (eg the endpoints which are not in use by other routes)
Set<Endpoint> toRemove = new LinkedHashSet<Endpoint>();
for (Endpoint endpoint : endpointsInUse.get(routeId)) {
// how many times is the endpoint in use
int count = 0;
for (Set<Endpoint> endpoints : endpointsInUse.values()) {
if (endpoints.contains(endpoint)) {
count++;
}
}
// notice we will count ourselves so if there is only 1 then its safe to remove
if (count <= 1) {
toRemove.add(endpoint);
}
}
for (Endpoint endpoint : toRemove) {
log.debug("Removing: {} which was only in use by route: {}", endpoint, routeId);
removeEndpoint(endpoint);
}
return true;
} else {
return false;
}
}
return false;
}
use of java.util.Set in project camel by apache.
the class BacklogDebuggerTest method testBacklogDebuggerRemoveBodyAndHeader.
@SuppressWarnings("unchecked")
public void testBacklogDebuggerRemoveBodyAndHeader() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
// enable debugger
mbeanServer.invoke(on, "enableDebugger", null, null);
enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
// add breakpoint at bar
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
mock.setSleepForEmptyTest(1000);
template.sendBody("seda:start", "Hello World");
assertMockEndpointsSatisfied();
// add breakpoint at bar
Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("foo", nodes.iterator().next());
// update body and header
mbeanServer.invoke(on, "removeMessageBodyOnBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
mbeanServer.invoke(on, "removeMessageHeaderOnBreakpoint", new Object[] { "foo", "beer" }, new String[] { "java.lang.String", "java.lang.String" });
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
Thread.sleep(1000);
// add breakpoint at bar
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("bar", nodes.iterator().next());
// the message should be ours
String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(xml);
log.info(xml);
assertTrue("Should not contain our body", xml.contains("<body>[Body is null]</body>"));
assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
assertFalse("Should not contain any headers", xml.contains("<header"));
resetMocks();
mock.expectedMessageCount(1);
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertMockEndpointsSatisfied();
// and no suspended anymore
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
}
use of java.util.Set in project camel by apache.
the class BacklogDebuggerTest method testBacklogDebuggerConditional.
@SuppressWarnings("unchecked")
public void testBacklogDebuggerConditional() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
// enable debugger
mbeanServer.invoke(on, "enableDebugger", null, null);
enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
// validate conditional breakpoint (mistake on purpose)
Object out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "unknown", "${body contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
assertEquals("No language could be found for: unknown", out);
// validate conditional breakpoint (mistake on purpose)
out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "simple", "${body contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
assertNotNull(out);
assertTrue(out.toString().startsWith("Invalid syntax ${body contains 'Camel'"));
// validate conditional breakpoint (is correct)
out = mbeanServer.invoke(on, "validateConditionalBreakpoint", new Object[] { "simple", "${body} contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String" });
assertNull(out);
// add breakpoint at bar
mbeanServer.invoke(on, "addConditionalBreakpoint", new Object[] { "bar", "simple", "${body} contains 'Camel'" }, new String[] { "java.lang.String", "java.lang.String", "java.lang.String" });
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("seda:start", "Hello World");
assertMockEndpointsSatisfied();
// add not breakpoint at bar as condition did not match
Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
resetMocks();
mock.expectedMessageCount(0);
mock.setSleepForEmptyTest(1000);
template.sendBody("seda:start", "Hello Camel");
assertMockEndpointsSatisfied();
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("bar", nodes.iterator().next());
// the message should be ours
String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(xml);
log.info(xml);
assertTrue("Should contain our body", xml.contains("Hello Camel"));
assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
resetMocks();
mock.expectedMessageCount(1);
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertMockEndpointsSatisfied();
// and no suspended anymore
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
}
use of java.util.Set in project camel by apache.
the class BacklogDebuggerTest method testBacklogDebuggerUpdateBodyAndHeader.
@SuppressWarnings("unchecked")
public void testBacklogDebuggerUpdateBodyAndHeader() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
// enable debugger
mbeanServer.invoke(on, "enableDebugger", null, null);
enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
// add breakpoint at bar
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(0);
mock.setSleepForEmptyTest(1000);
template.sendBody("seda:start", "Hello World");
assertMockEndpointsSatisfied();
// add breakpoint at bar
Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("foo", nodes.iterator().next());
// update body and header
mbeanServer.invoke(on, "setMessageBodyOnBreakpoint", new Object[] { "foo", "Changed body" }, new String[] { "java.lang.String", "java.lang.Object" });
mbeanServer.invoke(on, "setMessageHeaderOnBreakpoint", new Object[] { "foo", "beer", "Carlsberg" }, new String[] { "java.lang.String", "java.lang.String", "java.lang.Object" });
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "foo" }, new String[] { "java.lang.String" });
Thread.sleep(1000);
// add breakpoint at bar
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("bar", nodes.iterator().next());
// the message should be ours
String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(xml);
log.info(xml);
assertTrue("Should contain our body", xml.contains("Changed body"));
assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
assertTrue("Should contain our added header", xml.contains("<header key=\"beer\" type=\"java.lang.String\">Carlsberg</header>"));
resetMocks();
mock.expectedMessageCount(1);
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertMockEndpointsSatisfied();
// and no suspended anymore
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
}
use of java.util.Set in project camel by apache.
the class BacklogDebuggerTest method testBacklogDebuggerSuspendOnlyOneAtBreakpoint.
@SuppressWarnings("unchecked")
public void testBacklogDebuggerSuspendOnlyOneAtBreakpoint() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = new ObjectName("org.apache.camel:context=camel-1,type=tracer,name=BacklogDebugger");
assertNotNull(on);
mbeanServer.isRegistered(on);
Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should not be enabled", Boolean.FALSE, enabled);
// enable debugger
mbeanServer.invoke(on, "enableDebugger", null, null);
enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
assertEquals("Should be enabled", Boolean.TRUE, enabled);
// add breakpoint at bar
mbeanServer.invoke(on, "addBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(2);
// only one of them is suspended
template.sendBody("seda:start", "Hello World");
template.sendBody("seda:start", "Hello Camel");
template.sendBody("seda:start", "Hello Earth");
assertMockEndpointsSatisfied();
// add breakpoint at bar
Set<String> nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(1, nodes.size());
assertEquals("bar", nodes.iterator().next());
// the message should be ours
String xml = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertNotNull(xml);
log.info(xml);
assertTrue("Should contain bar node", xml.contains("<toNode>bar</toNode>"));
resetMocks();
mock.expectedMessageCount(1);
// resume breakpoint
mbeanServer.invoke(on, "resumeBreakpoint", new Object[] { "bar" }, new String[] { "java.lang.String" });
assertMockEndpointsSatisfied();
// and no suspended anymore
nodes = (Set<String>) mbeanServer.invoke(on, "getSuspendedBreakpointNodeIds", null, null);
assertNotNull(nodes);
assertEquals(0, nodes.size());
}
Aggregations