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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.arrow
.memory
;
21 * An allocation listener being notified for allocation/deallocation
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.
26 public interface AllocationListener
{
28 AllocationListener NOOP
= new AllocationListener() {};
31 * Called each time a new buffer has been requested.
33 * <p>An exception can be safely thrown by this method to terminate the allocation.
35 * @param size the buffer size being allocated
37 default void onPreAllocation(long size
) {}
40 * Called each time a new buffer has been allocated.
42 * <p>An exception cannot be thrown by this method.
44 * @param size the buffer size being allocated
46 default void onAllocation(long size
) {}
49 * Informed each time a buffer is released from allocation.
51 * <p>An exception cannot be thrown by this method.
52 * @param size The size of the buffer being released.
54 default void onRelease(long size
) {}
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.
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
66 default boolean onFailedAllocation(long size
, AllocationOutcome outcome
) {
71 * Called immediately after a child allocator was added to the parent allocator.
73 * @param parentAllocator The parent allocator to which a child was added
74 * @param childAllocator The child allocator that was just added
76 default void onChildAdded(BufferAllocator parentAllocator
, BufferAllocator childAllocator
) {}
79 * Called immediately after a child allocator was removed from the parent allocator.
81 * @param parentAllocator The parent allocator from which a child was removed
82 * @param childAllocator The child allocator that was just removed
84 default void onChildRemoved(BufferAllocator parentAllocator
, BufferAllocator childAllocator
) {}