1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr; 27 28 29 /** 30 * Callback interface to monitor Flight Recorder's life cycle. 31 * 32 * @since 9 33 */ 34 public interface FlightRecorderListener { 35 36 /** 37 * Receives notification when Flight Recorder is initialized. 38 * <p> 39 * This method is also be invoked when a listener is added to an already 40 * initialized Flight Recorder. 41 * <p> 42 * This method allows clients to implement their own initialization mechanism 43 * that is executed before a {@code FlightRecorder} instance is returned by 44 * {@code FlightRecorder#getFlightRecorder()}. 45 * 46 * @implNote This method should return as soon as possible, to avoid blocking 47 * initialization of Flight Recorder. To avoid deadlocks or unexpected 48 * behavior, this method should not call 49 * {@link FlightRecorder#getFlightRecorder()} or start new recordings. 50 * 51 * @implSpec The default implementation of this method is empty. 52 * 53 * @param recorder Flight Recorder instance, not {@code null} 54 * 55 * @see FlightRecorder#addListener(FlightRecorderListener) 56 */ recorderInitialized(FlightRecorder recorder)57 default void recorderInitialized(FlightRecorder recorder) { 58 } 59 60 /** 61 * Receives notification when the state of a recording changes. 62 * <p> 63 * Callback is invoked when a recording reaches the {@code RUNNING}, 64 * {@code STOPPED} and {@code CLOSED} state. 65 * 66 * @implNote The implementation of this method should return as soon as possible 67 * to avoid blocking normal operation of Flight Recorder. 68 * 69 * @implSpec The default implementation of this method is empty. 70 * 71 * @param recording the recording where the state change occurred, not 72 * {@code null} 73 * 74 * @see FlightRecorder#addListener(FlightRecorderListener) 75 * @see RecordingState 76 * 77 */ recordingStateChanged(Recording recording)78 default void recordingStateChanged(Recording recording) { 79 } 80 } 81