/** * 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); }
/** * This method should be called by all CompositeMonitor implementations * before they call monitorStarted(). * * @param compositeMonitor the composite monitor */ public void compositeMonitorStarted(CompositeMonitor compositeMonitor) { if (getEventPatternLevel().hasHigherPriorityThan(compositeMonitor.getLevel())) { if (log.isDebugEnabled()) { log.debug("skipping " + compositeMonitor.getAsString(Attribute.NAME)); } return; } LinkedList stack = getStack(); if (stack == null) { stack = new LinkedList(); threadBasedMap.put(Thread.currentThread(), stack); } stack.addLast(new StackFrame(compositeMonitor)); }
protected void writeMonitor(HierarchicalStreamWriter writer, Monitor monitor) { String monitorClassName = monitor.getClass().getName(); int classIdx = monitorClassName.lastIndexOf('.'); if (classIdx >= 0) { monitorClassName = monitorClassName.substring(classIdx + 1); } writer.startNode(monitorClassName); appendMonitorDataAsAttributes(writer, monitor); // recursively add all child monitors to dom tree if (CompositeMonitor.class.isAssignableFrom(monitor.getClass())) { CompositeMonitor cm = (CompositeMonitor) monitor; Collection childMonitors = cm.getChildMonitors(); Iterator childIterator = childMonitors.iterator(); while (childIterator.hasNext()) { Monitor childMonitor = (Monitor) childIterator.next(); writeMonitor(writer, childMonitor); } } writer.endNode(); }
StackFrame stackFrame = (StackFrame) i.next(); CompositeMonitor monitor = stackFrame.getCompositeMonitor(); inheritable.putAll(monitor.getInheritableAttributeHolders()); parentSequenceId = parent.getAsString(Attribute.SEQUENCE_ID);
CompositeMonitor monitor = stackFrame.getCompositeMonitor(); if (name.equals(monitor.get(Attribute.NAME))) { monitorToReturn = monitor; break;
public void processMonitorForCompositeMonitor(Monitor monitor) { LinkedList stack = getStack(); if (stack != null) { if (! stack.isEmpty()) { StackFrame stackFrame = (StackFrame) stack.getLast(); CompositeMonitor parentMonitor = stackFrame.getCompositeMonitor(); // only add this monitor being processed to a parent if it is enabled // by its monitoring level MonitoringLevel monitorLevel = monitor.getLevel(); if ((monitorLevel != null) && (monitorLevel.hasHigherOrEqualPriorityThan(getEventPatternLevel()))) { parentMonitor.addChildMonitor(monitor); } } else { threadBasedMap.remove(Thread.currentThread()); } } }
/** * 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(); } }
Collection childMonitors = compositeMonitor.getChildMonitors(); if(!childMonitors.isEmpty()) { StringBuffer lastBuffer = null;
private Monitor getRenamedMonitor(Monitor monitor) { String newName = getMonitorNamePrefix(monitor) + getAttributeAsStringWithDefault(monitor, Attribute.NAME, ""); Monitor renamedMonitor; if (CompositeMonitor.class.isAssignableFrom(monitor.getClass())) { renamedMonitor = new NonLifecycleMonitor(newName, monitor.getAll(), ((CompositeMonitor) monitor).getChildMonitors()); } else { renamedMonitor = new NonLifecycleMonitor(newName, monitor.getAll()); } return renamedMonitor; }