broadcastConsumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
try {
Object obj = ((ObjectMessage) message).getObject();
if (obj instanceof EndpointEvent) {
EndpointEvent event = (EndpointEvent) obj;
String container = ((InternalEndpoint) event.getEndpoint()).getComponentNameSpace()
.getContainerName();
if (!getBroker().getContainer().getName().equals(container)) {
if (event.getEventType() == EndpointEvent.INTERNAL_ENDPOINT_REGISTERED) {
onRemoteEndpointRegistered(event);
} else if (event.getEventType() == EndpointEvent.INTERNAL_ENDPOINT_UNREGISTERED) {
onRemoteEndpointUnregistered(event);
}
}
}
} catch (Exception e) {
log.error("Error processing incoming broadcast message", e);
}
}
});
// Start queue consumers for all components
for (ComponentMBeanImpl cmp : broker.getContainer().getRegistry().getComponents()) {
if (cmp.isStarted()) {
onComponentStarted(new ComponentEvent(cmp, ComponentEvent.COMPONENT_STARTED));
}
}
// Start queue consumers for all endpoints
ServiceEndpoint[] endpoints = broker.getContainer().getRegistry().getEndpointsForInterface(null);
for (int i = 0; i < endpoints.length; i++) {
if (endpoints[i] instanceof InternalEndpoint && ((InternalEndpoint) endpoints[i]).isLocal()) {
onInternalEndpointRegistered(new EndpointEvent(endpoints[i],
EndpointEvent.INTERNAL_ENDPOINT_REGISTERED), false);
}
}
startConsumerMonitor();