/** * Sets a global attribute with an int value. Global attributes will be set on all monitors during * the initMonitor() call. * * @param key the attribute to set * @param value the value of that attribute */ public void setGlobalAttribute(final String key, final int value) { globalAttributes.set(key, value); }
/** * Creates a new {@link AttributeMap} * @return a new attribute map */ protected AttributeMap createAttributeMap() { return new AttributeMap(); }
public Object get(String key) { return _attributes.get(key); }
/** * Gets the value at the specified key as a boolean * @param key the key of the value * @param defaultValue the value to return if the specified key doesn't exist * @return If the value is a {@link Boolean}, it is returned. If its {@link Object#toString()} * matches the words "true" or "false", one of those values is returned. If the key * doesn't exist, the specified default value is returned. * @throws CantCoerceException if the key exists, but the value is not a boolean and can't be * converted to one */ public boolean getAsBoolean(final String key, final boolean defaultValue) { if (!hasAttribute(key)) { return defaultValue; } else { return getAsBoolean(key); } }
/** * Gets the value at the specified key as a byte * @param key the key of the value * @param defaultValue the value to return if the key doesn't exist * @return If the value is a {@link Number}, its byte value is returned. Otherwise, its * {@link Object#toString()} is called and the result is passed to * {@link Byte#parseByte(String)}. If the key doesn't exist, the specified default value * is returned. * @throws CantCoerceException if the key exists, but the value is not a byte and can't be * converted to one */ public byte getAsByte(final String key, final byte defaultValue) { if (hasAttribute(key)) { return getAsByte(key); } else { return defaultValue; } }
/** * Sets zero or more attribute holders from a collection. If an entry value is an * {@link AttributeHolder}, it is cloned and its clone is put in this map. If it is not an * {@link AttributeHolder}, it is placed in a new attribute holder and put in this map. * @param attributeHolders a map of string keys to their holders or not holders. Really, anything. */ public void setAllAttributeHolders(final Map<String, ?> attributeHolders) { // TODO: This method should do what its name implies, not infer what to put in the map based on // type if (attributeHolders == null) { return; } for (Entry<String, ?> entry : attributeHolders.entrySet()) { final String key = entry.getKey(); final Object value = entry.getValue(); if (value != null) { if (AttributeHolder.class.isAssignableFrom(value.getClass())) { final AttributeHolder original = (AttributeHolder)value; final AttributeHolder copy = (AttributeHolder)original.clone(); getAttributes().put(key, copy); } else { set(key, value); } } } }
verifyValidKeyName(key); AttributeHolder attributeHolder = attributes.get(key); if (attributeHolder == null) { attributeHolder = createHolderForValue(value); attributes.put(key, attributeHolder); attributeHolder = createHolderForValue(attributeHolder, value); attributes.put(key, attributeHolder);
public <V> Map<String, V> getAll() { Map<String, V> result = attributes.getAll(); return result; }
public byte getAsByte(final String key) { return attributes.getAsByte(key); }
public boolean getAsBoolean(final String key) { return attributes.getAsBoolean(key); }
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(); } } }
/** * @see com.orbitz.monitoring.api.Monitor#getAllSerializable() */ public <V> Map<String, V> getAllSerializable() { return attributes.getAllSerializable(); }
/** * 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(); } }
/** * Constructor. * @param attributes initial attributes */ public CompositeAttributeMap(final AttributeMap attributes) { super(attributes.getAll()); }
public byte getAsByte(final String key, final byte defaultValue) { return attributes.getAsByte(key, defaultValue); }
public boolean getAsBoolean(final String key, final boolean defaultValue) { return attributes.getAsBoolean(key, defaultValue); }
/** * Get a serializable version of this monitor. Also creates serialized versions of any child * monitors. * @return the serializable monitor */ @Override public SerializableMonitor getSerializableMomento() { final List<SerializableMonitor> childMomentos = new ArrayList<SerializableMonitor>( _childMonitors.size()); for (final Monitor monitor : _childMonitors) { childMomentos.add(monitor.getSerializableMomento()); } final MonitoringEngine engine = MonitoringEngine.getInstance(); final Map<String, Serializable> serializableAttributes = engine .makeAttributeHoldersSerializable(attributes.getAllAttributeHolders()); final SerializableCompositeMonitor monitor = new SerializableCompositeMonitor(null, childMomentos); monitor.setAllAttributeHolders(serializableAttributes); return monitor; }
public Map getAllSerializable() { return _attributes.getAllSerializable(); }
/** * Sets a global attribute with an Object value. Global attributes will be set on all monitors * during the initMonitor() call. * * @param key the attribute to set * @param value the value of that attribute */ public void setGlobalAttribute(final String key, final Object value) { globalAttributes.set(key, value); }
public Object get(final String key) { return attributes.get(key); }