• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.camera.processing.memory;
18 
19 import com.android.camera.async.SafeCloseable;
20 
21 import javax.annotation.Nullable;
22 
23 /**
24  * Pool for and/or creating or reusing expensive resources.
25  */
26 public interface LruResourcePool<TKey, TValue> {
27     /**
28      * Returns a wrapped reference to a resource.
29      *
30      * @param key size of memory.
31      * @return T object representing a reusable n-bytes of memory.
32      */
acquire(TKey key)33     public Resource<TValue> acquire(TKey key);
34 
35     /**
36      * Closeable resource object that will release the underlying object back to the
37      * source resource pool. A resource may be released or closed multiple times,
38      * and calls to get will return null if the resource has already been released.
39      */
40     public interface Resource<T> extends SafeCloseable {
41         /**
42          * Get the underlying resource. This will return null if the resource has been
43          * closed and returned to the pool.
44          *
45          * @return the resource represented by this instance.
46          */
47         @Nullable
get()48         public T get();
49     }
50 }
51