|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
/* |
|
* @author IBM Corp. |
|
* |
|
* Copyright IBM Corp. 1999-2000. All rights reserved. |
|
*/ |
|
|
|
package javax.management.modelmbean; |
|
|
|
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER; |
|
import com.sun.jmx.mbeanserver.GetPropertyAction; |
|
|
|
import java.io.IOException; |
|
import java.io.ObjectInputStream; |
|
import java.io.ObjectOutputStream; |
|
import java.io.ObjectStreamField; |
|
import java.security.AccessController; |
|
import java.util.logging.Level; |
|
|
|
import javax.management.Descriptor; |
|
import javax.management.DescriptorAccess; |
|
import javax.management.MBeanNotificationInfo; |
|
import javax.management.RuntimeOperationsException; |
|
|
|
/** |
|
* <p>The ModelMBeanNotificationInfo object describes a notification emitted |
|
* by a ModelMBean. |
|
* It is a subclass of MBeanNotificationInfo with the addition of an |
|
* associated Descriptor and an implementation of the Descriptor interface.</p> |
|
* |
|
* <P id="descriptor"> |
|
* The fields in the descriptor are defined, but not limited to, the following. |
|
* Note that when the Type in this table is Number, a String that is the decimal |
|
* representation of a Long can also be used.</P> |
|
* |
|
* <table border="1" cellpadding="5" summary="ModelMBeanNotificationInfo Fields"> |
|
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr> |
|
* <tr><td>name</td><td>String</td> |
|
* <td>Notification name.</td></tr> |
|
* <tr><td>descriptorType</td><td>String</td> |
|
* <td>Must be "notification".</td></tr> |
|
* <tr><td>severity</td><td>Number</td> |
|
* <td>0-6 where 0: unknown; 1: non-recoverable; |
|
* 2: critical, failure; 3: major, severe; |
|
* 4: minor, marginal, error; 5: warning; |
|
* 6: normal, cleared, informative</td></tr> |
|
* <tr><td>messageID</td><td>String</td> |
|
* <td>Unique key for message text (to allow translation, analysis).</td></tr> |
|
* <tr><td>messageText</td><td>String</td> |
|
* <td>Text of notification.</td></tr> |
|
* <tr><td>log</td><td>String</td> |
|
* <td>T - log message, F - do not log message.</td></tr> |
|
* <tr><td>logfile</td><td>String</td> |
|
* <td>fully qualified file name appropriate for operating system.</td></tr> |
|
* <tr><td>visibility</td><td>Number</td> |
|
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr> |
|
* <tr><td>presentationString</td><td>String</td> |
|
* <td>XML formatted string to allow presentation of data.</td></tr> |
|
* </table> |
|
* |
|
* <p>The default descriptor contains the name, descriptorType, |
|
* displayName and severity(=6) fields. The default value of the name |
|
* and displayName fields is the name of the Notification class (as |
|
* specified by the <code>name</code> parameter of the |
|
* ModelMBeanNotificationInfo constructor).</p> |
|
* |
|
* <p>The <b>serialVersionUID</b> of this class is <code>-7445681389570207141L</code>. |
|
* |
|
* @since 1.5 |
|
*/ |
|
|
|
@SuppressWarnings("serial") |
|
public class ModelMBeanNotificationInfo |
|
extends MBeanNotificationInfo |
|
implements DescriptorAccess { |
|
|
|
// Serialization compatibility stuff: |
|
// Two serial forms are supported in this class. The selected form |
|
// depends on system property "jmx.serial.form": |
|
// - "1.0" for JMX 1.0 |
|
// - any other value for JMX 1.1 and higher |
|
// |
|
|
|
private static final long oldSerialVersionUID = -5211564525059047097L; |
|
// |
|
|
|
private static final long newSerialVersionUID = -7445681389570207141L; |
|
// |
|
|
|
private static final ObjectStreamField[] oldSerialPersistentFields = |
|
{ |
|
new ObjectStreamField("notificationDescriptor", Descriptor.class), |
|
new ObjectStreamField("currClass", String.class) |
|
}; |
|
// |
|
|
|
private static final ObjectStreamField[] newSerialPersistentFields = |
|
{ |
|
new ObjectStreamField("notificationDescriptor", Descriptor.class) |
|
}; |
|
// |
|
|
|
private static final long serialVersionUID; |
|
|
|
|
|
|
|
*/ |
|
private static final ObjectStreamField[] serialPersistentFields; |
|
private static boolean compat = false; |
|
static { |
|
try { |
|
GetPropertyAction act = new GetPropertyAction("jmx.serial.form"); |
|
String form = AccessController.doPrivileged(act); |
|
compat = (form != null && form.equals("1.0")); |
|
} catch (Exception e) { |
|
// OK: No compat with 1.0 |
|
} |
|
if (compat) { |
|
serialPersistentFields = oldSerialPersistentFields; |
|
serialVersionUID = oldSerialVersionUID; |
|
} else { |
|
serialPersistentFields = newSerialPersistentFields; |
|
serialVersionUID = newSerialVersionUID; |
|
} |
|
} |
|
// |
|
// END Serialization compatibility stuff |
|
|
|
|
|
|
|
|
|
*/ |
|
private Descriptor notificationDescriptor; |
|
|
|
private static final String currClass = "ModelMBeanNotificationInfo"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public ModelMBeanNotificationInfo(String[] notifTypes, |
|
String name, |
|
String description) { |
|
this(notifTypes,name,description,null); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public ModelMBeanNotificationInfo(String[] notifTypes, |
|
String name, |
|
String description, |
|
Descriptor descriptor) { |
|
super(notifTypes, name, description); |
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"ModelMBeanNotificationInfo", "Entry"); |
|
} |
|
notificationDescriptor = validDescriptor(descriptor); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo inInfo) { |
|
this(inInfo.getNotifTypes(), |
|
inInfo.getName(), |
|
inInfo.getDescription(),inInfo.getDescriptor()); |
|
} |
|
|
|
|
|
|
|
|
|
**/ |
|
public Object clone () { |
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"clone()", "Entry"); |
|
} |
|
return(new ModelMBeanNotificationInfo(this)); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public Descriptor getDescriptor() { |
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"getDescriptor()", "Entry"); |
|
} |
|
|
|
if (notificationDescriptor == null) { |
|
|
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"getDescriptor()", "Descriptor value is null, " + |
|
"setting descriptor to default values"); |
|
} |
|
notificationDescriptor = validDescriptor(null); |
|
} |
|
|
|
return((Descriptor)notificationDescriptor.clone()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public void setDescriptor(Descriptor inDescriptor) { |
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"setDescriptor(Descriptor)", "Entry"); |
|
} |
|
notificationDescriptor = validDescriptor(inDescriptor); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
public String toString() { |
|
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { |
|
MODELMBEAN_LOGGER.logp(Level.FINER, |
|
ModelMBeanNotificationInfo.class.getName(), |
|
"toString()", "Entry"); |
|
} |
|
|
|
final StringBuilder retStr = new StringBuilder(); |
|
|
|
retStr.append("ModelMBeanNotificationInfo: ") |
|
.append(this.getName()); |
|
|
|
retStr.append(" ; Description: ") |
|
.append(this.getDescription()); |
|
|
|
retStr.append(" ; Descriptor: ") |
|
.append(this.getDescriptor()); |
|
|
|
retStr.append(" ; Types: "); |
|
String[] nTypes = this.getNotifTypes(); |
|
for (int i=0; i < nTypes.length; i++) { |
|
if (i > 0) retStr.append(", "); |
|
retStr.append(nTypes[i]); |
|
} |
|
return retStr.toString(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException { |
|
Descriptor clone; |
|
boolean defaulted = (in == null); |
|
if (defaulted) { |
|
clone = new DescriptorSupport(); |
|
MODELMBEAN_LOGGER.finer("Null Descriptor, creating new."); |
|
} else { |
|
clone = (Descriptor) in.clone(); |
|
} |
|
|
|
|
|
if (defaulted && clone.getFieldValue("name")==null) { |
|
clone.setField("name", this.getName()); |
|
MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName()); |
|
} |
|
if (defaulted && clone.getFieldValue("descriptorType")==null) { |
|
clone.setField("descriptorType", "notification"); |
|
MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\""); |
|
} |
|
if (clone.getFieldValue("displayName") == null) { |
|
clone.setField("displayName",this.getName()); |
|
MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName()); |
|
} |
|
if (clone.getFieldValue("severity") == null) { |
|
clone.setField("severity", "6"); |
|
MODELMBEAN_LOGGER.finer("Defaulting Descriptor severity field to 6"); |
|
} |
|
|
|
|
|
if (!clone.isValid()) { |
|
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
|
"The isValid() method of the Descriptor object itself returned false,"+ |
|
"one or more required fields are invalid. Descriptor:" + clone.toString()); |
|
} |
|
if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) { |
|
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
|
"The Descriptor \"name\" field does not match the object described. " + |
|
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name")); |
|
} |
|
if (!"notification".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) { |
|
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"), |
|
"The Descriptor \"descriptorType\" field does not match the object described. " + |
|
" Expected: \"notification\" ," + " was: " + clone.getFieldValue("descriptorType")); |
|
} |
|
|
|
return clone; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
private void readObject(ObjectInputStream in) |
|
throws IOException, ClassNotFoundException { |
|
|
|
in.defaultReadObject(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
**/ |
|
private void writeObject(ObjectOutputStream out) |
|
throws IOException { |
|
if (compat) { |
|
// Serializes this instance in the old serial form |
|
|
|
ObjectOutputStream.PutField fields = out.putFields(); |
|
fields.put("notificationDescriptor", notificationDescriptor); |
|
fields.put("currClass", currClass); |
|
out.writeFields(); |
|
} else { |
|
// Serializes this instance in the new serial form |
|
|
|
out.defaultWriteObject(); |
|
} |
|
} |
|
|
|
} |