1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  *
26  * ident	"%Z%%M%	%I%	%E% SMI"
27  */
28 package org.opensolaris.os.dtrace;
29 
30 import java.io.*;
31 import java.util.EventObject;
32 
33 /**
34  * An event used to pass probe data generated by a DTrace {@link
35  * Consumer} to interested listeners.
36  *
37  * @see ConsumerListener#dataReceived(DataEvent e)
38  *
39  * @author Tom Erickson
40  */
41 public class DataEvent extends EventObject {
42     static final long serialVersionUID = 3068774547474769821L;
43 
44     /** @serial */
45     private ProbeData probeData;
46 
47     /**
48      * Creates a {@link ConsumerListener#dataReceived(DataEvent e)
49      * dataReceived()} event that conveys data generated by DTrace from
50      * a single probe firing.
51      *
52      * @throws NullPointerException if the given probe data is {@code
53      * null}
54      */
55     public
DataEvent(Object source, ProbeData generatedData)56     DataEvent(Object source, ProbeData generatedData)
57     {
58 	super(source);
59 	probeData = generatedData;
60 	validate();
61     }
62 
63     private final void
validate()64     validate()
65     {
66 	if (probeData == null) {
67 	    throw new NullPointerException("probe data is null");
68 	}
69     }
70 
71     /**
72      * Gets the data generated by DTrace from a single probe firing.
73      *
74      * @return non-null probe data generated by DTrace from a single
75      * probe firing
76      */
77     public ProbeData
getProbeData()78     getProbeData()
79     {
80 	return probeData;
81     }
82 
83     private void
readObject(ObjectInputStream s)84     readObject(ObjectInputStream s)
85             throws IOException, ClassNotFoundException
86     {
87 	s.defaultReadObject();
88 	// check invariants
89 	try {
90 	    validate();
91 	} catch (Exception e) {
92 	    InvalidObjectException x = new InvalidObjectException(
93 		    e.getMessage());
94 	    x.initCause(e);
95 	    throw x;
96 	}
97     }
98 
99     /**
100      * Gets a string representation of this event useful for logging and
101      * not intended for display.  The exact details of the
102      * representation are unspecified and subject to change, but the
103      * following format may be regarded as typical:
104      * <pre><code>
105      * class-name[property1 = value1, property2 = value2]
106      * </code></pre>
107      */
108     public String
toString()109     toString()
110     {
111 	StringBuilder buf = new StringBuilder();
112 	buf.append(DataEvent.class.getName());
113 	buf.append("[source = ");
114 	buf.append(getSource());
115 	buf.append(", probeData = ");
116 	buf.append(probeData);
117 	buf.append(']');
118 	return buf.toString();
119     }
120 }
121