1 /*
2 * Copyright 2021 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty5.buffer.api;
17
18 import io.netty5.buffer.api.LeakInfo.TracePoint;
19 import io.netty5.util.Resource;
20 import io.netty5.util.internal.UnstableApi;
21
22 import java.util.function.Consumer;
23 import java.util.stream.Stream;
24
25 /**
26 * Information about a resource leak that happened.
27 * This information is provided to callbacks of the {@link MemoryManager#onLeakDetected(Consumer)} method.
28 */
29 @UnstableApi
30 public interface LeakInfo extends Iterable<TracePoint> {
31 /**
32 * Create a {@link Stream} of all the {@link TracePoint}s in this {@link LeakInfo}.
33 * The returned {@link Stream} does not need to be closed.
34 *
35 * @return A {@link Stream} of {@link TracePoint}s, covering the life-cycle of the leaked resource.
36 */
37 Stream<TracePoint> stream();
38
39 /**
40 * A human-readable description of the object that leaked.
41 *
42 * @return A description of the leaked object.
43 */
44 String objectDescription();
45
46 /**
47 * A moment in the life of the leaked object, for which some information was recorded.
48 */
49 interface TracePoint {
50 /**
51 * Get the hint object from a {@linkplain Resource#touch(Object) touch} call, if any.
52 * If this trace point is not a {@code touch} call, or if the hint argument was {@code null},
53 * then {@code null} will be returned.
54 *
55 * @return A hint object, if there is any on this trace point, otherwise {@code null}.
56 */
57 Object hint();
58
59 /**
60 * Get a {@link Throwable} instance that holds the recorded stack trace of this trace point.
61 *
62 * @return A {@link Throwable} with the stack trace of this trace point.
63 */
64 Throwable traceback();
65 }
66 }