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.util.EventListener; 31 32 /** 33 * Listener for data generated by a single DTrace {@link Consumer}. 34 * 35 * @author Tom Erickson 36 */ 37 public interface ConsumerListener extends EventListener { 38 /** 39 * Called whenever a DTrace probe fires (that is, once for each 40 * instance of {@link ProbeData} generated by DTrace). Identifies 41 * the probe and provides data generated by the probe's actions. To 42 * terminate the consumer in the event of unexpected data, throw a 43 * {@link ConsumerException} from this method. 44 * 45 * @throws ConsumerException if the implementation should terminate 46 * the running consumer 47 */ dataReceived(DataEvent e)48 public void dataReceived(DataEvent e) throws ConsumerException; 49 50 /** 51 * Called when traced data is dropped because of inadequate buffer 52 * space. To terminate the consumer in the event of a drop, throw 53 * a {@link ConsumerException} from this method. 54 * 55 * @throws ConsumerException if the implementation should terminate 56 * the running consumer 57 */ dataDropped(DropEvent e)58 public void dataDropped(DropEvent e) throws ConsumerException; 59 60 /** 61 * Called when an error is encountered in the native DTrace library 62 * while tracing probe data. To terminate the consumer, throw a 63 * {@link ConsumerException} from this method. 64 * 65 * @throws ConsumerException if the implementation should terminate 66 * the running consumer 67 */ errorEncountered(ErrorEvent e)68 public void errorEncountered(ErrorEvent e) throws ConsumerException; 69 70 /** 71 * Called when the state of a target process changes. To terminate 72 * the consumer in the event of unexpected process state, throw a 73 * {@link ConsumerException} from this method. 74 * 75 * @throws ConsumerException if the implementation should terminate 76 * the running consumer 77 * @see Consumer#createProcess(String command) 78 * @see Consumer#grabProcess(int pid) 79 */ processStateChanged(ProcessEvent e)80 public void processStateChanged(ProcessEvent e) throws ConsumerException; 81 82 /** 83 * Called once when the source {@link Consumer} is successfully 84 * started in response to {@link Consumer#go()}. 85 * 86 * @see #consumerStopped(ConsumerEvent e) 87 */ consumerStarted(ConsumerEvent e)88 public void consumerStarted(ConsumerEvent e); 89 90 /** 91 * Called once when the source {@link Consumer} is stopped, 92 * indicating that this listener should expect no further events. 93 * Guaranteed to be called whether the consumer was stopped by 94 * request (by calling {@link Consumer#stop()} or {@link 95 * Consumer#abort()}), terminated normally as a result of the DTrace 96 * {@code exit()} action (see <a 97 * href=http://docs.sun.com/app/docs/doc/817-6223/6mlkidlhm?a=view> 98 * <tt>exit()</tt></a> in the <b>Special Actions</b> section of the 99 * <b>Actions and Subroutines</b> chapter of the <i>Solaris Dynamic 100 * Tracing Guide</i>) or after the completion of all target 101 * processes, or terminated abnormally because of an exception. It 102 * is necessary to call {@link Consumer#close()} to release any 103 * system resources still held by the stopped consumer. 104 * 105 * @see #consumerStarted(ConsumerEvent e) 106 */ consumerStopped(ConsumerEvent e)107 public void consumerStopped(ConsumerEvent e); 108 109 /** 110 * Called when the source {@link Consumer} wakes up to process its 111 * buffer of traced probe data. 112 * 113 * @see #intervalEnded(ConsumerEvent e) 114 */ intervalBegan(ConsumerEvent e)115 public void intervalBegan(ConsumerEvent e); 116 117 /** 118 * Called when the source {@link Consumer} finishes processing its 119 * buffer of traced probe data and is about to sleep until the next 120 * interval. The rate of consumption may be controlled with the 121 * {@link Option#switchrate switchrate} and {@link Option#aggrate 122 * aggrate} options (see {@link Consumer#setOption(String option, 123 * String value)}). 124 * 125 * @see #intervalBegan(ConsumerEvent e) 126 */ intervalEnded(ConsumerEvent e)127 public void intervalEnded(ConsumerEvent e); 128 } 129