{
// initialise statistics
stats = createStatistics();
stats.setEnabled(muleContext.getStatistics().isEnabled());
muleContext.getStatistics().add(stats);
RouterStatistics routerStatistics = null;
// If the router collection already has router statistics, keep using them.
if (outboundRouter instanceof OutboundRouterCollection)
{
routerStatistics = ((OutboundRouterCollection)outboundRouter).getRouterStatistics();
}
if (routerStatistics == null)
{
routerStatistics = new RouterStatistics(RouterStatistics.TYPE_OUTBOUND);
}
stats.setOutboundRouterStat(routerStatistics);
if (outboundRouter != null && outboundRouter instanceof RouterStatisticsRecorder)
{
((RouterStatisticsRecorder)outboundRouter).setRouterStatistics(routerStatistics);
}
RouterStatistics inboundRouterStatistics = new RouterStatistics(RouterStatistics.TYPE_INBOUND);
stats.setInboundRouterStat(inboundRouterStatistics);
if (messageSource instanceof RouterStatisticsRecorder)
{
((RouterStatisticsRecorder) messageSource).setRouterStatistics(inboundRouterStatistics);
}