]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/java/memory/memory-core/src/main/java/org/apache/arrow/memory/AllocationListener.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / memory / memory-core / src / main / java / org / apache / arrow / memory / AllocationListener.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.arrow.memory;
19
20 /**
21 * An allocation listener being notified for allocation/deallocation
22 *
23 * <p>It might be called from multiple threads if the allocator hierarchy shares a listener, in which
24 * case, the provider should take care of making the implementation thread-safe.
25 */
26 public interface AllocationListener {
27
28 AllocationListener NOOP = new AllocationListener() {};
29
30 /**
31 * Called each time a new buffer has been requested.
32 *
33 * <p>An exception can be safely thrown by this method to terminate the allocation.
34 *
35 * @param size the buffer size being allocated
36 */
37 default void onPreAllocation(long size) {}
38
39 /**
40 * Called each time a new buffer has been allocated.
41 *
42 * <p>An exception cannot be thrown by this method.
43 *
44 * @param size the buffer size being allocated
45 */
46 default void onAllocation(long size) {}
47
48 /**
49 * Informed each time a buffer is released from allocation.
50 *
51 * <p>An exception cannot be thrown by this method.
52 * @param size The size of the buffer being released.
53 */
54 default void onRelease(long size) {}
55
56
57 /**
58 * Called whenever an allocation failed, giving the caller a chance to create some space in the
59 * allocator (either by freeing some resource, or by changing the limit), and, if successful,
60 * allowing the allocator to retry the allocation.
61 *
62 * @param size the buffer size that was being allocated
63 * @param outcome the outcome of the failed allocation. Carries information of what failed
64 * @return true, if the allocation can be retried; false if the allocation should fail
65 */
66 default boolean onFailedAllocation(long size, AllocationOutcome outcome) {
67 return false;
68 }
69
70 /**
71 * Called immediately after a child allocator was added to the parent allocator.
72 *
73 * @param parentAllocator The parent allocator to which a child was added
74 * @param childAllocator The child allocator that was just added
75 */
76 default void onChildAdded(BufferAllocator parentAllocator, BufferAllocator childAllocator) {}
77
78 /**
79 * Called immediately after a child allocator was removed from the parent allocator.
80 *
81 * @param parentAllocator The parent allocator from which a child was removed
82 * @param childAllocator The child allocator that was just removed
83 */
84 default void onChildRemoved(BufferAllocator parentAllocator, BufferAllocator childAllocator) {}
85 }