public Map getInheritableAttributes() { Map inheritableAttributes = new HashMap(); Map map = (Map) threadBasedMap.get(Thread.currentThread()); if(map != null) { for(Iterator it = map.values().iterator(); it.hasNext(); ) { Map attributes = (Map) it.next(); for(Iterator ij = attributes.entrySet().iterator(); ij.hasNext(); ) { Map.Entry entry = (Map.Entry) ij.next(); AttributeHolder original = (AttributeHolder) entry.getValue(); AttributeHolder copy = new AttributeHolder(original.getValue()); if(original.isSerializable()) { copy.serializable(); } inheritableAttributes.put(entry.getKey(), copy); } } } return inheritableAttributes; }
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(); } } }
@Override public Object clone() { return super.clone(); }
@Override Serializable createMutableContainer(final Object object) { AttributeHolder holder = (AttributeHolder)object; return new AttributeHolder(holder.getValue()); }
/** * Gets the items from this map that have indicated they are {@link Serializable} through * {@link AttributeHolder#isSerializable()}. * @return a new map of keys to the {@link Serializable} values. */ public <V> Map<String, V> getAllSerializable() { final Map<String, V> allSerializable = new HashMap<String, V>(); for (Entry<String, AttributeHolder> entry : attributes.entrySet()) { final AttributeHolder attributeHolder = entry.getValue(); if (attributeHolder.isSerializable()) { @SuppressWarnings("unchecked") final V value = (V)attributeHolder.getValue(); allSerializable.put(entry.getKey(), value); } } return allSerializable; }
/** * 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(); }
/** * 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(); } } }
public AttributeHolder set(final String key, final float value) { return attributes.set(key, value).serializable(); }
final CompositeAttributeHolder copy = new CompositeAttributeHolder(original.getValue()); if (original.isSerializable()) { copy.serializable(); if (original.isLocked()) { copy.lock();
public V apply(final AttributeHolder attribute) { return (V)attribute.getValue(); } });
/** * Used to set the inherited attributes on this monitor. * * @param inheritedAttributes the collection of inherited attributes */ @Override protected void setInheritedAttributes(final Map<String, Object> inheritedAttributes) { if (inheritedAttributes != null) { for (final 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(); } final AttributeHolder holder = setInheritable(key, value).lock(); if (value != null && SERIALIZABLE.contains(value.getClass())) { holder.serializable(); } } } }
@Override protected void init(String name, Map inheritedAttributes) { set(Attribute.NAME, name).lock(); setInheritedAttributes(inheritedAttributes); }
@Override public Serializable decompose(final Object object, final IdentityHashMap<Object, Serializable> alreadyDecomposed) { if (object == null) { return null; } if (alreadyDecomposed.containsKey(object)) { return alreadyDecomposed.get(object); } else { Serializable mutableContainer = createMutableContainer(object); alreadyDecomposed.put(object, mutableContainer); decomposeInto(object, mutableContainer, alreadyDecomposed); Serializable holder = new AttributeHolder(updatedValue); return holder; } }
/** * Takes the supplied attributes and returns an equivalent set that are ready to be serialized. * Will only return those attributes that are marked as serializable. * * @param attributeHolders the attributes to prepare for serialization * @return an equivalent set of attributes that can be serialized */ public Map<String, Serializable> makeAttributeHoldersSerializable( final Map<String, ? extends AttributeHolder> attributeHolders) { if (!isEnabled()) { return new HashMap<String, Serializable>(); } final Map<String, Serializable> renderedAttributes = new HashMap<String, Serializable>( attributeHolders.size()); for (final Entry<String, ? extends AttributeHolder> entry : attributeHolders.entrySet()) { final AttributeHolder holder = entry.getValue(); if (holder.isSerializable()) { renderedAttributes.put(entry.getKey(), decomposer.decompose(holder)); } } return renderedAttributes; }
@Override public boolean equals(final Object o) { if (o instanceof CompositeAttributeHolder) { CompositeAttributeHolder that = (CompositeAttributeHolder)o; return Objects.equal(this.inheritable, that.inheritable) && super.equals(that); } return false; }
@Override public int hashCode() { return Objects.hashCode(this.inheritable, super.hashCode()); }
if (attributeHolder.isLocked()) { if (logger.isDebugEnabled()) { logger.debug("Attempt to overwrite locked attribute with key '" + key + "'");
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); } }
public AttributeHolder set(final String key, final char value) { return attributes.set(key, value).serializable(); }
@Override void decomposeInto(final Object o, final Serializable container, final IdentityHashMap<Object, Serializable> alreadyDecomposed) { AttributeHolder holder = (AttributeHolder)o; updatedValue = _delegate.decompose(holder.getValue(), alreadyDecomposed); }