1 package org.xerial.snappy.pool;
2 
3 /**
4  * Manages implementation of {@link BufferPool} to use by default. Setting the system property {@link #DISABLE_CACHING_PROPERTY} to {@code true} will
5  * cause the {@link QuiescentBufferPool} to be used by default. Otherwise, {@link CachingBufferPool} will be used by default.
6  * {@link #setDefaultPool(BufferPool)} can be used to explicitly control the implementation to use.
7  */
8 public final class DefaultPoolFactory {
9 
10     /**
11      * Name of system property to disable use of {@link CachingBufferPool} by default.
12      */
13     public static final String DISABLE_CACHING_PROPERTY = "org.xerial.snappy.pool.disable";
14 
15     private static volatile BufferPool defaultPool = "true".equalsIgnoreCase(System.getProperty(DISABLE_CACHING_PROPERTY))
16                                                          ? QuiescentBufferPool.getInstance()
17                                                          : CachingBufferPool.getInstance();
18 
19     /**
20      * @return The default instance to use.
21      */
getDefaultPool()22     public static BufferPool getDefaultPool() {
23         return defaultPool;
24     }
25 
26     /**
27      * Sets the default instance to use.
28      * @param pool The default instance to use. Must not be {@code null}.
29      * @see #getDefaultPool()
30      */
setDefaultPool(BufferPool pool)31     public static void setDefaultPool(BufferPool pool) {
32         if (pool == null) {
33             throw new IllegalArgumentException("pool is null");
34         }
35         defaultPool = pool;
36     }
37 }
38