Home / Class/ ObjectPool Class — netty Architecture

ObjectPool Class — netty Architecture

Architecture documentation for the ObjectPool class in ObjectPool.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  cd9a4a8a_7fb0_bcfa_142c_bfa8537dffe1["ObjectPool"]
  0a0bc0a2_7cf9_65c8_840c_cbc9ea2d857e["ObjectPool.java"]
  cd9a4a8a_7fb0_bcfa_142c_bfa8537dffe1 -->|defined in| 0a0bc0a2_7cf9_65c8_840c_cbc9ea2d857e
  052eb0d1_3cf1_6104_4c0a_ba7bd0c8cf4d["ObjectPool()"]
  cd9a4a8a_7fb0_bcfa_142c_bfa8537dffe1 -->|method| 052eb0d1_3cf1_6104_4c0a_ba7bd0c8cf4d
  d9fafe33_51f4_20b6_ece7_50a0ec3cd191["T()"]
  cd9a4a8a_7fb0_bcfa_142c_bfa8537dffe1 -->|method| d9fafe33_51f4_20b6_ece7_50a0ec3cd191
  ef0c21ee_1dd6_84c6_e937_452562a9b7c9["newPool()"]
  cd9a4a8a_7fb0_bcfa_142c_bfa8537dffe1 -->|method| ef0c21ee_1dd6_84c6_e937_452562a9b7c9

Relationship Graph

Source Code

common/src/main/java/io/netty/util/internal/ObjectPool.java lines 25–99

public abstract class ObjectPool<T> {

    ObjectPool() { }

    /**
     * Get a {@link Object} from the {@link ObjectPool}. The returned {@link Object} may be created via
     * {@link ObjectCreator#newObject(Handle)} if no pooled {@link Object} is ready to be reused.
     *
     * @deprecated For removal. Please use {@link Recycler#get()} instead.
     */
    @Deprecated
    public abstract T get();

    /**
     * Handle for an pooled {@link Object} that will be used to notify the {@link ObjectPool} once it can
     * reuse the pooled {@link Object} again.
     * @param <T>
     */
    public interface Handle<T> {
        /**
         * Recycle the {@link Object} if possible and so make it ready to be reused.
         */
        void recycle(T self);
    }

    /**
     * Creates a new Object which references the given {@link Handle} and calls {@link Handle#recycle(Object)} once
     * it can be re-used.
     *
     * @param <T> the type of the pooled object
     *
     * @deprecated For removal. Please use {@link Recycler()} instead.
     */
    @Deprecated
    public interface ObjectCreator<T> {

        /**
         * Creates an returns a new {@link Object} that can be used and later recycled via
         * {@link Handle#recycle(Object)}.
         *
         * @param handle can NOT be null.
         */
        T newObject(Handle<T> handle);
    }

    /**
     * Creates a new {@link ObjectPool} which will use the given {@link ObjectCreator} to create the {@link Object}
     * that should be pooled.
     *
     * @deprecated For removal. Please use {@link Recycler()} instead.
     */
    @Deprecated
    public static <T> ObjectPool<T> newPool(final ObjectCreator<T> creator) {
        return new RecyclerObjectPool<T>(ObjectUtil.checkNotNull(creator, "creator"));
    }

    @Deprecated
    private static final class RecyclerObjectPool<T> extends ObjectPool<T> {
        private final Recycler<T> recycler;

        RecyclerObjectPool(final ObjectCreator<T> creator) {
             recycler = new Recycler<T>() {
                @Override
                protected T newObject(Handle<T> handle) {
                    return creator.newObject(handle);
                }
            };
        }

        @Override
        public T get() {
            return recycler.get();
        }
    }
}

Frequently Asked Questions

What is the ObjectPool class?
ObjectPool is a class in the netty codebase, defined in common/src/main/java/io/netty/util/internal/ObjectPool.java.
Where is ObjectPool defined?
ObjectPool is defined in common/src/main/java/io/netty/util/internal/ObjectPool.java at line 25.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free