public CompositeAttributeHolder setInheritable(final String key, final double value) { final CompositeAttributeHolder holder = ((CompositeAttributeHolder)attributes.set(key, value)) .setInheritable(true); MonitoringEngine.getInstance().setInheritable(this, key, holder); return holder; }
/** * Shuts down the MonitoringEngine if it is running. After it is shutdown, the MonitoringEngine * will be started up. * <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 restart() { if (running) { shutdown(); } startup(); }
/** * Process this composite monitor. Delegates to AbstractMonitor.process(). */ @Override protected void process() { MonitoringEngine.getInstance().compositeMonitorCompleted(this); super.process(); }
public final MonitoringLevel getLevel() { final MonitoringLevel overrideLevel = MonitoringEngine.getInstance() .getOverrideLevelForMonitor(this); return (overrideLevel != null ? overrideLevel : monitoringLevel); }
/** * Create a new composite monitor with the provided name, monitoring level and inherited * attributes. * * @param name the name of the monitor * @param monitoringLevel the monitoring level * @param inheritedAttributes the collection of inherited attributes */ public AbstractCompositeMonitor(final String name, final MonitoringLevel monitoringLevel, final Map<String, Object> inheritedAttributes) { super(name, monitoringLevel, inheritedAttributes); MonitoringEngine.getInstance().compositeMonitorStarted(this); }
/** * Sets all properties of the {@link MonitoringEngine} that have been configured, such as * {@link #getMonitoringEnabled()} and {@link #getInheritableStrategy()}, then starts it. After * the {@link MonitoringEngine} is started, schedules all {@link #getTimerTasks() timer tasks}. */ public void startup() { MonitoringEngine.getInstance().setMonitoringEnabled(monitoringEnabled); MonitoringEngine.getInstance().setProcessorFactory(factory); MonitoringEngine.getInstance().setDecomposer(decomposer); MonitoringEngine.getInstance().setInheritableStrategy(inheritableStrategy); MonitoringEngine.getInstance().setStartupRunnable(startupRunnable); if (timerTasks == null) { timerTasks = Collections.emptyMap(); } MonitoringEngine.getInstance().startup(); EventMonitor monitor = new EventMonitor("MonitoringEngineManager.lifecycle", MonitoringLevel.ESSENTIAL); monitor.set("eventType", "startup"); monitor.fire(); scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); for (Entry<Integer, Collection<TimerTask>> entry : timerTasks.entrySet()) { long millis = entry.getKey(); for (Runnable task : entry.getValue()) { scheduledExecutor.scheduleAtFixedRate(task, millis, millis, TimeUnit.MILLISECONDS); } } }
/** * Used to invoke the monitor lifecycle methods MonitoringEngine.initMonitor and * MonitoringEngine.monitorCreated on this monitor. * * @param name the name of the monitor * @param inheritedAttributes the collection of inherited attributes */ protected void init(String name, final Map<String, Object> inheritedAttributes) { MonitoringEngine.getInstance().initMonitor(this); if (name != null) { for (int i = 0; i < name.length(); i++) { if (invalidCharSet.contains(Character.valueOf(name.charAt(i)))) { name = CharSetUtils.delete(name, invalidCharacters); break; } } } set(Attribute.NAME, name); setInheritedAttributes(inheritedAttributes); MonitoringEngine.getInstance().monitorCreated(this); }
/** * Stops all {@link #getTimerTasks() timer tasks} and {@link MonitoringEngine#shutdown() shuts the * monitoring engine down}. */ public void shutdown() { scheduledExecutor.shutdown(); EventMonitor monitor = new EventMonitor("MonitoringEngineManager.lifecycle", MonitoringLevel.ESSENTIAL); monitor.set("eventType", "shutdown"); monitor.fire(); MonitoringEngine.getInstance().shutdown(); }
/** * Used to invoke the monitor lifecycle method MonitoringEngine.process on this monitor. */ protected void process() { if (processed) { log.error("This monitor has already been processed: " + this); } else { MonitoringEngine.getInstance().process(this); processed = true; } }
/** * Get a {@link Serializable} version of this monitor. * @return the {@link Serializable} monitor */ public SerializableMonitor getSerializableMomento() { final MonitoringEngine engine = MonitoringEngine.getInstance(); final Map<String, Serializable> serializableAttributes = engine .makeAttributeHoldersSerializable(attributes.getAllAttributeHolders()); final SerializableMonitor monitor = new SerializableMonitor(null); monitor.setAllAttributeHolders(serializableAttributes); return monitor; }
/** * Gets the override monitor levels by calling * {@link MonitoringEngine#getOverrideMonitorLevelsListing()} * @return description of override monitor levels map * @see MonitoringEngine#getOverrideMonitorLevelsListing() * @@org.springframework.jmx.export.metadata.ManagedAttribute * (description="Gets a view into monitor level overrides" * ) */ @ManagedAttribute(description = "Gets a view into monitor level overrides") // TODO: Remove the Javadoc annotation public String getOverrideMonitorLevelsListing() { return MonitoringEngine.getInstance().getOverrideMonitorLevelsListing(); }
/** * Gets the override processor levels by calling * {@link MonitoringEngine#getOverrideProcessorLevelsListing()} * @return description of override processor levels map * @see MonitoringEngine#getOverrideProcessorLevelsListing() * @@org.springframework.jmx.export.metadata.ManagedAttribute * (description="Gets a view into processor level overrides" * ) */ @ManagedAttribute(description = "Gets a view into processor level overrides") public String getOverrideProcessorLevelsListing() { String returnString = MonitoringEngine.getInstance().getOverrideProcessorLevelsListing(); return returnString; }
/** * Restarts the {@link MonitoringEngine} * @see MonitoringEngine#restart() */ public void reload() { EventMonitor monitor = new EventMonitor("MonitoringEngineManager.lifecycle", MonitoringLevel.ESSENTIAL); monitor.set("eventType", "reload"); monitor.fire(); MonitoringEngine.getInstance().restart(); }
private void startTransactionMonitor() { set(FAILED, true).serializable(); set(START_TIME, new Date()).serializable().lock(); MonitoringEngine.getInstance().monitorStarted(this); } }
/** * Optionally allows for inheritable attributes. * * @param name the name of the monitor * @param value the value * @param includeInheritables set to true if this monitor should support inheritables * @param monitoringLevel monitoring level */ public ValueMonitor(String name, double value, boolean includeInheritables, MonitoringLevel monitoringLevel) { // note we are calling this specific constructor on AbstractMonitor to avoid // the call to init() on AbstractMonitor super(); this.monitoringLevel = monitoringLevel; // perform standard monitor initialization optionally ommitting inheritable // attributes - this is a performance optimization targeted towards a potentially // costly step in monitor construction (inheritable attributes) MonitoringEngine.getInstance().initMonitor(this, includeInheritables); // also intentionally skip the created lifecycle step as this is not a // meaningful event/unnecessary overhead for ValueMonitor //MonitoringEngine.getInstance().monitorCreated(this); set(Attribute.NAME, name).lock(); set(Attribute.VALUE, value).lock(); }
MonitoringEngine.getInstance().addMonitorLevel(nameStartsWith, level); if (log.isInfoEnabled()) { log.info("Added: " + nameStartsWith + " -> " + levelStr
MonitorProcessor processor = processors[i]; if (name.equalsIgnoreCase(processor.getName())) { MonitoringEngine.getInstance().addProcessorLevel(name, MonitoringLevel.toLevel(levelStr)); log.info("Changed Processor level: " + name + " -> " + levelStr); return;// two processors should not have same name
@VisibleForTesting MonitoringEngine findMonitoringEngine() { return MonitoringEngine.getInstance(); }
private void inheritAttributesFromAncestors(final Monitor monitor) { // Inherit from parent if not set. final Map attrs = getInheritableAttributes(); for (final Iterator it = attrs.entrySet().iterator(); it.hasNext();) { final Map.Entry entry = (Map.Entry)it.next(); final String key = (String)entry.getKey(); final AttributeHolder parentAttribute = (AttributeHolder)entry.getValue(); if (!monitor.hasAttribute(key)) { final Object value = parentAttribute.getValue(); final AttributeHolder childAttribute = monitor.set(key, value); if (parentAttribute.isSerializable()) { childAttribute.serializable(); } if (parentAttribute.isLocked()) { childAttribute.lock(); } } } }
public MonitoringLevel getLevel() { MonitoringLevel overrideLevel = MonitoringEngine.getInstance().getOverrideLevelForMonitor(this); return (overrideLevel != null ? overrideLevel : _monitoringLevel); } }