Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public int decrement(int decrement) {
* @return The ledger associated with the BufferAllocator.
*/
public BufferLedger getLedgerForAllocator(BufferAllocator allocator) {
return associate((BaseAllocator) allocator);
return associate(allocator.unwrap(BaseAllocator.class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,16 @@ public static enum Verbosity {
}
}

@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> c) {
if (BaseAllocator.class.isAssignableFrom(c)) {
return (T) this;
}

throw new UnsupportedOperationException("Unable to unwrap type to class: " + c.getName());
}

public static boolean isDebug() {
return DEBUG;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public interface BufferAllocator extends AutoCloseable {
@Override
public void close();

/**
* Unwrap the class so that exposes the provided interface, if possible. Otherwise, throw Exception.
* @param c
* The class or interface that you want this class to implement/extend.
* @return The instance of that class related to 'this'
*/
public <T> T unwrap(Class<T> c);

/**
* Returns the amount of memory currently allocated from this allocator.
*
Expand Down