/** * Used to set the inherited attributes on this monitor. * * @param inheritedAttributes the collection of inherited attributes */ protected void setInheritedAttributes(final Map<String, Object> inheritedAttributes) { if (inheritedAttributes != null) { for (final Map.Entry<String, Object> entry : inheritedAttributes.entrySet()) { final String key = entry.getKey(); Object value = entry.getValue(); if (value != null && AttributeHolder.class.isAssignableFrom(value.getClass())) { value = ((AttributeHolder)value).getValue(); } set(key, value).lock(); } } }
@Override protected void init(String name, Map inheritedAttributes) { set(Attribute.NAME, name).lock(); setInheritedAttributes(inheritedAttributes); }
/** * Stops the stop watch for this monitor. Delegates to AbstractMonitor.process(). */ public void done() { Date endTime = new Date(); set(Attribute.END_TIME, endTime).serializable().lock(); Date startTime = (Date) get(Attribute.START_TIME); set(Attribute.LATENCY, endTime.getTime() - startTime.getTime()).serializable().lock(); process(); }
public void initMonitor(final Monitor monitor, final boolean includeInheritables) { if (!isEnabled()) { return; } monitor.set(Attribute.CREATED_AT, new Date()).serializable().lock(); final String threadId = Integer.toHexString(Thread.currentThread().hashCode()); monitor.set(Attribute.THREAD_ID, threadId).serializable().lock(); inheritGlobals(monitor); if (includeInheritables) { inheritAttributesFromAncestors(monitor); } }
private void inheritGlobals(final Monitor monitor) { for (final Iterator it = globalAttributes.getAllAttributeHolders().entrySet().iterator(); it .hasNext();) { final Map.Entry entry = (Map.Entry)it.next(); final String key = (String)entry.getKey(); final AttributeHolder holder = (AttributeHolder)entry.getValue(); final Object value = holder.getValue(); final AttributeHolder attribute = monitor.set(key, value); if (holder.isSerializable()) { attribute.serializable(); } if (holder.isLocked()) { attribute.lock(); } } }
/** * 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(); }
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(); } } } }
private void startTransactionMonitor() { set(FAILED, true).serializable(); set(START_TIME, new Date()).serializable().lock(); MonitoringEngine.getInstance().monitorStarted(this); } }