/** * Clears away any outstanding CompositeMonitor references held by the MonitoringEngine for the * current thread. This is useful to do in a long-running application at some point before you * create what should be the first/outermost CompositeMonitor for a given thread. It reduces risk * of heap leaks caused by accumulating unfinished CompositeMonitor instances. * * IMPORTANT NOTE: This method does not "close" any monitors that are found and cleared in this * fashion. Only the references to them are removed from an internal stack that's mapped from the * current thread. Since it does not close them, no MonitorProcessors will be notified of this * event. * * @return count of monitor refs cleared */ public int clearCurrentThread() { return inheritableStrategy.clearCurrentThread(); }
/** * Obtains the first CompositeMonitor found on the per thread stack that has its name attribute * equal to the supplied name. This method should be used in situations where stateless code is * unable to hold a reference to the CompositeMonitor that was originally created. Supplying the * name value is needed to ensure that instrumentation errors in code called by users of this * method does not interfere with the ability to correctly obtain the original CompositeMonitor. * * @param name the value of name that our Monitor was created with. * @return the first CompositeMonitor with the supplied name, or null if not found * @throws IllegalArgumentException if name is null */ public CompositeMonitor getCompositeMonitorNamed(final String name) throws IllegalArgumentException { return inheritableStrategy.getCompositeMonitorNamed(name); }
/** * Returns the current inheritable attributes for this thread. * * @return the inheritable attributes that would be applied to a monitor if it were made right * now, or an empty Map if there are none */ public Map getInheritableAttributes() { return inheritableStrategy.getInheritableAttributes(); }
public void setInheritable(final CompositeMonitor compositeMonitor, final String key, final AttributeHolder original) { if (isEnabled() && running) { inheritableStrategy.setInheritable(compositeMonitor, key, original); } }
/** * Pops this monitor off the top of the stack. If this monitor is not on the top of the stack nor * found anywhere within the stack, the monitor is ignored, as this is an error in * instrumentation. If the monitor is found within the stack, the top of the stack is repeatedly * popped and processed until this monitor is on the the top. * <p> * * This method should be called by all CompositeMonitor implementations before they call * process(). * * @param monitor the monitor that is completed */ public void compositeMonitorCompleted(final CompositeMonitor monitor) { if (!isEnabled()) { return; } inheritableStrategy.compositeMonitorCompleted(monitor); }
inheritableStrategy.startup(); processorFactory.startup();
/** * Shuts down the monitoring engine. This method should be called before shutting down the * application to give the ERMA system a chance to cleanly close all its resources. * <p> * * This call disables ERMA and calls shutdown() on the {@link MonitorProcessorFactory} supplied. * <p> * * <b>This method is not thread-safe.</b> Client should take care to ensure that multithreaded * access to this method is synchronized. */ public void shutdown() { if (running) { log.info("MonitoringEngine shutting down"); globalAttributes.clear(); monitorProcessorLevels.clear(); monitorLevels.clear(); running = false; processorFactory.shutdown(); inheritableStrategy.shutdown(); } }
/** * A lifecycle method that notifies observing MonitorProcessors that a monitor is ready to be * processed. All monitor implementations should call as the last call of their lifecycle. * * @param monitor the monitor that should be processed */ public void process(final Monitor monitor) { if (!isEnabled()) { return; } inheritableStrategy.processMonitorForCompositeMonitor(monitor); handleMonitor(monitor, PROCESS_CLOSURE); }
/** * 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); }