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