KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > management > relation > RelationNotification


1 /*
2  * @(#)RelationNotification.java 1.31 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.management.relation;
9
10 import javax.management.Notification JavaDoc;
11 import javax.management.ObjectName JavaDoc;
12
13 import java.io.IOException JavaDoc;
14 import java.io.ObjectInputStream JavaDoc;
15 import java.io.ObjectOutputStream JavaDoc;
16 import java.io.ObjectStreamField JavaDoc;
17
18 import java.security.AccessController JavaDoc;
19 import java.security.PrivilegedAction JavaDoc;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24
25 import com.sun.jmx.mbeanserver.GetPropertyAction;
26
27 /**
28  * A notification of a change in the Relation Service.
29  * A RelationNotification notification is sent when a relation is created via
30  * the Relation Service, or an MBean is added as a relation in the Relation
31  * Service, or a role is updated in a relation, or a relation is removed from
32  * the Relation Service.
33  *
34  * @since 1.5
35  */

36 public class RelationNotification extends Notification JavaDoc {
37
38     // Serialization compatibility stuff:
39
// Two serial forms are supported in this class. The selected form depends
40
// on system property "jmx.serial.form":
41
// - "1.0" for JMX 1.0
42
// - any other value for JMX 1.1 and higher
43
//
44
// Serial version for old serial form
45
private static final long oldSerialVersionUID = -2126464566505527147L;
46     //
47
// Serial version for new serial form
48
private static final long newSerialVersionUID = -6871117877523310399L;
49     //
50
// Serializable fields in old serial form
51
private static final ObjectStreamField JavaDoc[] oldSerialPersistentFields =
52     {
53     new ObjectStreamField JavaDoc("myNewRoleValue", ArrayList JavaDoc.class),
54     new ObjectStreamField JavaDoc("myOldRoleValue", ArrayList JavaDoc.class),
55     new ObjectStreamField JavaDoc("myRelId", String JavaDoc.class),
56     new ObjectStreamField JavaDoc("myRelObjName", ObjectName JavaDoc.class),
57     new ObjectStreamField JavaDoc("myRelTypeName", String JavaDoc.class),
58     new ObjectStreamField JavaDoc("myRoleName", String JavaDoc.class),
59     new ObjectStreamField JavaDoc("myUnregMBeanList", ArrayList JavaDoc.class)
60     };
61     //
62
// Serializable fields in new serial form
63
private static final ObjectStreamField JavaDoc[] newSerialPersistentFields =
64     {
65     new ObjectStreamField JavaDoc("newRoleValue", List JavaDoc.class),
66     new ObjectStreamField JavaDoc("oldRoleValue", List JavaDoc.class),
67     new ObjectStreamField JavaDoc("relationId", String JavaDoc.class),
68     new ObjectStreamField JavaDoc("relationObjName", ObjectName JavaDoc.class),
69     new ObjectStreamField JavaDoc("relationTypeName", String JavaDoc.class),
70     new ObjectStreamField JavaDoc("roleName", String JavaDoc.class),
71     new ObjectStreamField JavaDoc("unregisterMBeanList", List JavaDoc.class)
72     };
73     //
74
// Actual serial version and serial form
75
private static final long serialVersionUID;
76     /**
77      * @serialField relationId String Relation identifier of created/removed/updated relation
78      * @serialField relationTypeName String Relation type name of created/removed/updated relation
79      * @serialField relationObjName ObjectName {@link ObjectName} of the relation MBean of created/removed/updated relation
80      * (only if the relation is represented by an MBean)
81      * @serialField unregisterMBeanList List List of {@link ObjectName}s of referenced MBeans to be unregistered due to
82      * relation removal
83      * @serialField roleName String Name of updated role (only for role update)
84      * @serialField oldRoleValue List Old role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
85      * @serialField newRoleValue List New role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
86      */

87     private static final ObjectStreamField JavaDoc[] serialPersistentFields;
88     private static boolean compat = false;
89     static {
90     try {
91         PrivilegedAction JavaDoc act = new GetPropertyAction("jmx.serial.form");
92         String JavaDoc form = (String JavaDoc) AccessController.doPrivileged(act);
93         compat = (form != null && form.equals("1.0"));
94     } catch (Exception JavaDoc e) {
95         // OK : Too bad, no compat with 1.0
96
}
97     if (compat) {
98         serialPersistentFields = oldSerialPersistentFields;
99         serialVersionUID = oldSerialVersionUID;
100     } else {
101         serialPersistentFields = newSerialPersistentFields;
102         serialVersionUID = newSerialVersionUID;
103     }
104     }
105     //
106
// END Serialization compatibility stuff
107

108     //
109
// Notification types
110
//
111

112     /**
113      * Type for the creation of an internal relation.
114      */

115     public static final String JavaDoc RELATION_BASIC_CREATION = "jmx.relation.creation.basic";
116     /**
117      * Type for the relation MBean added into the Relation Service.
118      */

119     public static final String JavaDoc RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean";
120     /**
121      * Type for an update of an internal relation.
122      */

123     public static final String JavaDoc RELATION_BASIC_UPDATE = "jmx.relation.update.basic";
124     /**
125      * Type for the update of a relation MBean.
126      */

127     public static final String JavaDoc RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean";
128     /**
129      * Type for the removal from the Relation Service of an internal relation.
130      */

131     public static final String JavaDoc RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic";
132     /**
133      * Type for the removal from the Relation Service of a relation MBean.
134      */

135     public static final String JavaDoc RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean";
136
137     //
138
// Private members
139
//
140

141     /**
142      * @serial Relation identifier of created/removed/updated relation
143      */

144     private String JavaDoc relationId = null;
145
146     /**
147      * @serial Relation type name of created/removed/updated relation
148      */

149     private String JavaDoc relationTypeName = null;
150
151     /**
152      * @serial {@link ObjectName} of the relation MBean of created/removed/updated relation
153      * (only if the relation is represented by an MBean)
154      */

155     private ObjectName JavaDoc relationObjName = null;
156
157     /**
158      * @serial List of {@link ObjectName}s of referenced MBeans to be unregistered due to
159      * relation removal
160      */

161     private List JavaDoc unregisterMBeanList = null;
162
163     /**
164      * @serial Name of updated role (only for role update)
165      */

166     private String JavaDoc roleName = null;
167
168     /**
169      * @serial Old role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
170      */

171     private List JavaDoc oldRoleValue = null;
172
173     /**
174      * @serial New role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
175      */

176     private List JavaDoc newRoleValue = null;
177
178     //
179
// Constructors
180
//
181

182     /**
183      * Creates a notification for either a relation creation (RelationSupport
184      * object created internally in the Relation Service, or an MBean added as a
185      * relation) or for a relation removal from the Relation Service.
186      *
187      * @param theNtfType type of the notification; either:
188      * <P>- RELATION_BASIC_CREATION
189      * <P>- RELATION_MBEAN_CREATION
190      * <P>- RELATION_BASIC_REMOVAL
191      * <P>- RELATION_MBEAN_REMOVAL
192      * @param theSrcObj source object, sending the notification. Will always
193      * be a RelationService object.
194      * @param TheSeqNbr sequence number to identify the notification
195      * @param theTimeStamp time stamp
196      * @param theMsg human-readable message describing the notification
197      * @param theRelId relation id identifying the relation in the Relation
198      * Service
199      * @param theRelTypeName name of the relation type
200      * @param theRelObjName ObjectName of the relation object if it is an MBean
201      * (null for relations internally handled by the Relation Service)
202      * @param theUnregMBeanList list of ObjectNames of referenced MBeans
203      * expected to be unregistered due to relation removal (only for removal,
204      * due to CIM qualifiers, can be null)
205      *
206      * @exception IllegalArgumentException if:
207      * <P>- no value for the notification type
208      * <P>- the notification type is not RELATION_BASIC_CREATION,
209      * RELATION_MBEAN_CREATION, RELATION_BASIC_REMOVAL or
210      * RELATION_MBEAN_REMOVAL
211      * <P>- no source object
212      * <P>- the source object is not a Relation Service
213      * <P>- no relation id
214      * <P>- no relation type name
215      */

216     public RelationNotification(String JavaDoc theNtfType,
217                 Object JavaDoc theSrcObj,
218                 long TheSeqNbr,
219                 long theTimeStamp,
220                 String JavaDoc theMsg,
221                 String JavaDoc theRelId,
222                 String JavaDoc theRelTypeName,
223                 ObjectName JavaDoc theRelObjName,
224                 List JavaDoc theUnregMBeanList)
225     throws IllegalArgumentException JavaDoc {
226
227     super(theNtfType, theSrcObj, TheSeqNbr, theTimeStamp, theMsg);
228
229     // Can throw IllegalArgumentException
230
initMembers(1,
231             theNtfType,
232             theSrcObj,
233             TheSeqNbr,
234             theTimeStamp,
235             theMsg,
236             theRelId,
237             theRelTypeName,
238             theRelObjName,
239             theUnregMBeanList,
240             null,
241             null,
242             null);
243     return;
244     }
245
246     /**
247      * Creates a notification for a role update in a relation.
248      *
249      * @param theNtfType type of the notification; either:
250      * <P>- RELATION_BASIC_UPDATE
251      * <P>- RELATION_MBEAN_UPDATE
252      * @param theSrcObj source object, sending the notification. Will always
253      * be a RelationService object.
254      * @param TheSeqNbr sequence number to identify the notification
255      * @param theTimeStamp time stamp
256      * @param theMsg human-readable message describing the notification
257      * @param theRelId relation id identifying the relation in the Relation
258      * Service
259      * @param theRelTypeName name of the relation type
260      * @param theRelObjName ObjectName of the relation object if it is an MBean
261      * (null for relations internally handled by the Relation Service)
262      * @param theRoleName name of the updated role
263      * @param theNewRoleValue new value (List of ObjectName objects)
264      * @param theOldRoleValue old value (List of ObjectName objects)
265      *
266      * @exception IllegalArgumentException if null parameter
267      */

268     public RelationNotification(String JavaDoc theNtfType,
269                 Object JavaDoc theSrcObj,
270                 long TheSeqNbr,
271                 long theTimeStamp,
272                 String JavaDoc theMsg,
273                 String JavaDoc theRelId,
274                 String JavaDoc theRelTypeName,
275                 ObjectName JavaDoc theRelObjName,
276                 String JavaDoc theRoleName,
277                 List JavaDoc theNewRoleValue,
278                 List JavaDoc theOldRoleValue
279                 )
280     throws IllegalArgumentException JavaDoc {
281
282     super(theNtfType, theSrcObj, TheSeqNbr, theTimeStamp, theMsg);
283
284     // Can throw IllegalArgumentException
285
initMembers(2,
286             theNtfType,
287             theSrcObj,
288             TheSeqNbr,
289             theTimeStamp,
290             theMsg,
291             theRelId,
292             theRelTypeName,
293             theRelObjName,
294             null,
295             theRoleName,
296             theNewRoleValue,
297             theOldRoleValue);
298     return;
299     }
300
301     //
302
// Accessors
303
//
304

305     /**
306      * Returns the relation identifier of created/removed/updated relation.
307      *
308      * @return the relation id.
309      */

310     public String JavaDoc getRelationId() {
311     return relationId;
312     }
313
314     /**
315      * Returns the relation type name of created/removed/updated relation.
316      *
317      * @return the relation type name.
318      */

319     public String JavaDoc getRelationTypeName() {
320     return relationTypeName;
321     }
322
323     /**
324      * Returns the ObjectName of the
325      * created/removed/updated relation.
326      *
327      * @return the ObjectName if the relation is an MBean, otherwise null.
328      */

329     public ObjectName JavaDoc getObjectName() {
330     return relationObjName;
331     }
332
333     /**
334      * Returns the list of ObjectNames of MBeans expected to be unregistered
335      * due to a relation removal (only for relation removal).
336      *
337      * @return a {@link List} of {@link ObjectName}.
338      */

339     public List JavaDoc getMBeansToUnregister() {
340     List JavaDoc result = null;
341     if (unregisterMBeanList != null) {
342         result = (List JavaDoc)((ArrayList JavaDoc)unregisterMBeanList).clone();
343     } else {
344         result = Collections.EMPTY_LIST;
345     }
346     return result;
347     }
348
349     /**
350      * Returns name of updated role of updated relation (only for role update).
351      *
352      * @return the name of the updated role.
353      */

354     public String JavaDoc getRoleName() {
355     String JavaDoc result = null;
356     if (roleName != null) {
357         result = roleName;
358     }
359     return result;
360     }
361
362     /**
363      * Returns old value of updated role (only for role update).
364      *
365      * @return the old value of the updated role.
366      */

367     public List JavaDoc getOldRoleValue() {
368     List JavaDoc result = null;
369     if (oldRoleValue != null) {
370         result = (List JavaDoc)((ArrayList JavaDoc)oldRoleValue).clone();
371     } else {
372         result = Collections.EMPTY_LIST;
373     }
374     return result;
375     }
376
377     /**
378      * Returns new value of updated role (only for role update).
379      *
380      * @return the new value of the updated role.
381      */

382     public List JavaDoc getNewRoleValue() {
383     List JavaDoc result = null;
384     if (newRoleValue != null) {
385         result = (List JavaDoc)((ArrayList JavaDoc)newRoleValue).clone();
386     } else {
387         result = Collections.EMPTY_LIST;
388     }
389     return result;
390     }
391
392     //
393
// Misc
394
//
395

396     // Initialises members
397
//
398
// -param theNtfKind 1 for creation/removal, 2 for update
399
// -param theNtfType type of the notification; either:
400
// - RELATION_BASIC_UPDATE
401
// - RELATION_MBEAN_UPDATE
402
// for an update, or:
403
// - RELATION_BASIC_CREATION
404
// - RELATION_MBEAN_CREATION
405
// - RELATION_BASIC_REMOVAL
406
// - RELATION_MBEAN_REMOVAL
407
// for a creation or removal
408
// -param theSrcObj source object, sending the notification. Will always
409
// be a RelationService object.
410
// -param TheSeqNbr sequence number to identify the notification
411
// -param theTimeStamp time stamp
412
// -param theMsg human-readable message describing the notification
413
// -param theRelId relation id identifying the relation in the Relation
414
// Service
415
// -param theRelTypeName name of the relation type
416
// -param theRelObjName ObjectName of the relation object if it is an MBean
417
// (null for relations internally handled by the Relation Service)
418
// -param theUnregMBeanList list of ObjectNames of MBeans expected to be
419
// removed due to relation removal
420
// -param theRoleName name of the updated role
421
// -param theNewRoleValue new value (List of ObjectName objects)
422
// -param theOldRoleValue old value (List of ObjectName objects)
423
//
424
// -exception IllegalArgumentException if:
425
// - no value for the notification type
426
// - incorrect notification type
427
// - no source object
428
// - the source object is not a Relation Service
429
// - no relation id
430
// - no relation type name
431
// - no role name (for role update)
432
// - no role old value (for role update)
433
// - no role new value (for role update)
434
private void initMembers(int theNtfKind,
435                  String JavaDoc theNtfType,
436                  Object JavaDoc theSrcObj,
437                  long TheSeqNbr,
438                  long theTimeStamp,
439                  String JavaDoc theMsg,
440                  String JavaDoc theRelId,
441                  String JavaDoc theRelTypeName,
442                  ObjectName JavaDoc theRelObjName,
443                  List JavaDoc theUnregMBeanList,
444                  String JavaDoc theRoleName,
445                  List JavaDoc theNewRoleValue,
446                  List JavaDoc theOldRoleValue)
447     throws IllegalArgumentException JavaDoc {
448
449       boolean badInitFlg = false;
450
451       if (theNtfType == null ||
452       theSrcObj == null ||
453       (!(theSrcObj instanceof RelationService JavaDoc)) ||
454       theRelId == null ||
455       theRelTypeName == null) {
456
457       badInitFlg = true;
458       }
459
460       if (theNtfKind == 1) {
461
462        if ((!(theNtfType.equals(RelationNotification.RELATION_BASIC_CREATION)))
463        &&
464        (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_CREATION)))
465        &&
466        (!(theNtfType.equals(RelationNotification.RELATION_BASIC_REMOVAL)))
467        &&
468        (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_REMOVAL)))
469        ) {
470
471           // Creation/removal
472
badInitFlg = true;
473          }
474
475        } else if (theNtfKind == 2) {
476
477        if (((!(theNtfType.equals(RelationNotification.RELATION_BASIC_UPDATE)))
478         &&
479         (!(theNtfType.equals(RelationNotification.RELATION_MBEAN_UPDATE))))
480        || theRoleName == null ||
481        theOldRoleValue == null ||
482        theNewRoleValue == null) {
483
484        // Role update
485
badInitFlg = true;
486        }
487       }
488
489     if (badInitFlg) {
490     // Revisit [cebro] Localize message
491
String JavaDoc excMsg = "Invalid parameter.";
492     throw new IllegalArgumentException JavaDoc(excMsg);
493     }
494
495     relationId = theRelId;
496     relationTypeName = theRelTypeName;
497     relationObjName = theRelObjName;
498     if (theUnregMBeanList != null) {
499     unregisterMBeanList = new ArrayList JavaDoc(theUnregMBeanList);
500     }
501     if (theRoleName != null) {
502     roleName = theRoleName;
503     }
504     if (theOldRoleValue != null) {
505     oldRoleValue = new ArrayList JavaDoc(theOldRoleValue);
506     }
507     if (theNewRoleValue != null) {
508     newRoleValue = new ArrayList JavaDoc(theNewRoleValue);
509     }
510     return;
511     }
512
513     /**
514      * Deserializes a {@link RelationNotification} from an {@link ObjectInputStream}.
515      */

516     private void readObject(ObjectInputStream JavaDoc in)
517         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
518       if (compat)
519       {
520         // Read an object serialized in the old serial form
521
//
522
ObjectInputStream.GetField JavaDoc fields = in.readFields();
523     newRoleValue = (List JavaDoc) fields.get("myNewRoleValue", null);
524     if (fields.defaulted("myNewRoleValue"))
525         {
526           throw new NullPointerException JavaDoc("newRoleValue");
527         }
528     oldRoleValue = (List JavaDoc) fields.get("myOldRoleValue", null);
529     if (fields.defaulted("myOldRoleValue"))
530         {
531           throw new NullPointerException JavaDoc("oldRoleValue");
532         }
533     relationId = (String JavaDoc) fields.get("myRelId", null);
534     if (fields.defaulted("myRelId"))
535         {
536           throw new NullPointerException JavaDoc("relationId");
537         }
538     relationObjName = (ObjectName JavaDoc) fields.get("myRelObjName", null);
539     if (fields.defaulted("myRelObjName"))
540         {
541           throw new NullPointerException JavaDoc("relationObjName");
542         }
543     relationTypeName = (String JavaDoc) fields.get("myRelTypeName", null);
544     if (fields.defaulted("myRelTypeName"))
545         {
546           throw new NullPointerException JavaDoc("relationTypeName");
547         }
548     roleName = (String JavaDoc) fields.get("myRoleName", null);
549     if (fields.defaulted("myRoleName"))
550         {
551           throw new NullPointerException JavaDoc("roleName");
552         }
553     unregisterMBeanList = (List JavaDoc) fields.get("myUnregMBeanList", null);
554     if (fields.defaulted("myUnregMBeanList"))
555         {
556           throw new NullPointerException JavaDoc("unregisterMBeanList");
557         }
558       }
559       else
560       {
561         // Read an object serialized in the new serial form
562
//
563
in.defaultReadObject();
564       }
565     }
566
567
568     /**
569      * Serializes a {@link RelationNotification} to an {@link ObjectOutputStream}.
570      */

571     private void writeObject(ObjectOutputStream JavaDoc out)
572         throws IOException JavaDoc {
573       if (compat)
574       {
575         // Serializes this instance in the old serial form
576
//
577
ObjectOutputStream.PutField JavaDoc fields = out.putFields();
578     fields.put("myNewRoleValue", newRoleValue);
579     fields.put("myOldRoleValue", oldRoleValue);
580     fields.put("myRelId", relationId);
581     fields.put("myRelObjName", relationObjName);
582     fields.put("myRelTypeName", relationTypeName);
583     fields.put("myRoleName",roleName);
584     fields.put("myUnregMBeanList", unregisterMBeanList);
585     out.writeFields();
586       }
587       else
588       {
589         // Serializes this instance in the new serial form
590
//
591
out.defaultWriteObject();
592       }
593     }
594 }
595
Popular Tags