xref: /illumos-gate/usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/ErrorEvent.java (revision 058561cbaa119a6f2659bc27ef343e1b47266bb2)
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  * Notification that DTrace has encountered an error.
35  *
36  * @see ConsumerListener#errorEncountered(ErrorEvent e)
37  *
38  * @author Tom Erickson
39  */
40 public class ErrorEvent extends EventObject {
41     static final long serialVersionUID = 2236600660422267215L;
42 
43     /** @serial */
44     private Error error;
45 
46     /**
47      * Creates an {@link ConsumerListener#errorEncountered(ErrorEvent e)
48      * errorEncountered()} event that reports an error encountered in
49      * the native DTrace library during tracing.
50      *
51      * @param source the {@link Consumer} that is the source of this event
52      * @param dtraceError the error encountered by DTrace
53      * @throws NullPointerException if the given error is {@code null}
54      */
55     public
56     ErrorEvent(Object source, Error dtraceError)
57     {
58 	super(source);
59 	error = dtraceError;
60 	validate();
61     }
62 
63     private final void
64     validate()
65     {
66 	if (error == null) {
67 	    throw new NullPointerException("error is null");
68 	}
69     }
70 
71     /**
72      * Gets the error reported by DTrace.
73      *
74      * @return non-null error reported by DTrace
75      */
76     public Error
77     getError()
78     {
79 	return error;
80     }
81 
82     private void
83     readObject(ObjectInputStream s)
84             throws IOException, ClassNotFoundException
85     {
86 	s.defaultReadObject();
87 	// check invariants
88 	try {
89 	    validate();
90 	} catch (Exception e) {
91 	    throw new InvalidObjectException(e.getMessage());
92 	}
93     }
94 
95     /**
96      * Gets a string representation of this event useful for logging and
97      * not intended for display.  The exact details of the
98      * representation are unspecified and subject to change, but the
99      * following format may be regarded as typical:
100      * <pre><code>
101      * class-name[property1 = value1, property2 = value2]
102      * </code></pre>
103      */
104     public String
105     toString()
106     {
107 	StringBuffer buf = new StringBuffer();
108 	buf.append(ErrorEvent.class.getName());
109 	buf.append("[source = ");
110 	buf.append(getSource());
111 	buf.append(", error = ");
112 	buf.append(error);
113 	buf.append(']');
114 	return buf.toString();
115     }
116 }
117