/** * Adds the supplied CompositeMonitor to the stack for this thread. If this is the first * CompositeMonitor on this thread, a new LinkedList is created and added to a map holding all * stacks by Thread. * <p> * * This method should be called by all CompositeMonitor implementations before they call * monitorStarted(). * * @param compositeMonitor the monitor to add to the stack */ public void compositeMonitorStarted(final CompositeMonitor compositeMonitor) { if (!isEnabled()) { return; } // this null check can probably go away if we replace the Monitor interface // with AbstractMonitor if (compositeMonitor.getLevel() == null) { if (log.isDebugEnabled()) { log.debug("skipping composite monitor with name " + compositeMonitor.get(Attribute.NAME) + ", it has no defined level"); } return; } inheritableStrategy.compositeMonitorStarted(compositeMonitor); }
CompositeMonitor monitor = stackFrame.getCompositeMonitor(); if (name.equals(monitor.get(Attribute.NAME))) { monitorToReturn = monitor; break;
/** * This method should be called by all CompositeMonitor implementations * before they call process(). * * @param monitor the monitor that is completed */ public void compositeMonitorCompleted(CompositeMonitor monitor) { LinkedList stack = getStack(); if (stack != null && !stack.isEmpty()) { StackFrame target = new StackFrame(monitor); if (!stack.getLast().equals(target) && !stack.contains(target)) { // This monitor is being double processed on accident. // Ignore it. return; } while (!stack.getLast().equals(target)) { // A child monitor was not processed, process them now. StackFrame stackFrame = (StackFrame) stack.removeLast(); CompositeMonitor missedMonitor = stackFrame.getCompositeMonitor(); String name = (String) missedMonitor.get(Attribute.NAME); log.warn("unfinished child monitor \""+name+"\" found so will process now and remove; app is fine"); MonitoringEngine.getInstance().process(missedMonitor); } stack.removeLast(); } }