public V apply(final AttributeHolder attribute) { return (V)attribute.getValue(); } });
@Override Serializable createMutableContainer(final Object object) { AttributeHolder holder = (AttributeHolder)object; return new AttributeHolder(holder.getValue()); }
@Override void decomposeInto(final Object o, final Serializable container, final IdentityHashMap<Object, Serializable> alreadyDecomposed) { AttributeHolder holder = (AttributeHolder)o; updatedValue = _delegate.decompose(holder.getValue(), alreadyDecomposed); }
public void setInheritable(CompositeMonitor monitor, String key, AttributeHolder original) { Map inheritableAttributes = getInheritableAttributes(); if(!inheritableAttributes.containsKey(key) && original != null) { compositeMonitorStarted(monitor); Map map = (Map) threadBasedMap.get(Thread.currentThread()); if(!map.containsKey(monitor)) { map.put(monitor, new HashMap()); } Map monitorMap = (Map) map.get(monitor); monitorMap.put(key, original); } else { if(log.isDebugEnabled()) { AttributeHolder holder = (AttributeHolder) inheritableAttributes.get(key); log.debug("Attempted to re-add " + key + " with new value [" + original.getValue() + "] to inheritableMap; old value is [" + 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; }
/** * 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 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; }
/** * Gets the value of a key * @param key the key to find * @return the value at the specified key * @throws AttributeUndefinedException if the key doesn't exist */ public Object get(final String key) { if (this.hasAttribute(key)) { AttributeHolder attribute = attributes.get(key); return (attribute == null) ? attribute : attribute.getValue(); } throw new AttributeUndefinedException(key); }
/** * 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(); } } } }
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(); } } }
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(); } } } }
final CompositeAttributeHolder copy = new CompositeAttributeHolder(original.getValue()); if (original.isSerializable()) { copy.serializable();