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 dropped data due to inadequate buffer 35 * space. 36 * 37 * @see ConsumerListener#dataDropped(DropEvent e) 38 * 39 * @author Tom Erickson 40 */ 41 public class DropEvent extends EventObject { 42 static final long serialVersionUID = 5454623535426339134L; 43 44 /** @serial */ 45 private Drop drop; 46 47 /** 48 * Creates a {@link ConsumerListener#dataDropped(DropEvent e) 49 * dataDropped()} event that reports dropped data. 50 * 51 * @throws NullPointerException if the given drop is {@code null} 52 */ 53 public 54 DropEvent(Object source, Drop dataDrop) 55 { 56 super(source); 57 drop = dataDrop; 58 validate(); 59 } 60 61 private final void 62 validate() 63 { 64 if (drop == null) { 65 throw new NullPointerException("drop is null"); 66 } 67 } 68 69 /** 70 * Gets the drop information generated by DTrace. 71 * 72 * @return non-null drop information generated by DTrace 73 */ 74 public Drop 75 getDrop() 76 { 77 return drop; 78 } 79 80 private void 81 readObject(ObjectInputStream s) 82 throws IOException, ClassNotFoundException 83 { 84 s.defaultReadObject(); 85 // check invariants 86 try { 87 validate(); 88 } catch (Exception e) { 89 InvalidObjectException x = new InvalidObjectException( 90 e.getMessage()); 91 x.initCause(e); 92 throw x; 93 } 94 } 95 96 /** 97 * Gets a string representation of this event useful for logging and 98 * not intended for display. The exact details of the 99 * representation are unspecified and subject to change, but the 100 * following format may be regarded as typical: 101 * <pre><code> 102 * class-name[property1 = value1, property2 = value2] 103 * </code></pre> 104 */ 105 public String 106 toString() 107 { 108 StringBuilder buf = new StringBuilder(); 109 buf.append(DropEvent.class.getName()); 110 buf.append("[source = "); 111 buf.append(getSource()); 112 buf.append(", drop = "); 113 buf.append(drop); 114 buf.append(']'); 115 return buf.toString(); 116 } 117 } 118