1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
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 net.sf.ehcache.pool;
18
19 import java.util.Collection;
20
21 /***
22 * Pools are used to track shared resource consumption. Each store participating in a pool creates an accessor
23 * which it uses to tell the pool about its consumption. A SizeOf engine is used to calculate the size of the
24 * objects added to the pool.
25 *
26 * @param <T> type of store that uses this pool
27 *
28 * @author Ludovic Orban
29 */
30 public interface Pool<T> {
31
32 /***
33 * Return the used size of the pool.
34 *
35 * @return used size of the pool.
36 */
37 long getSize();
38
39 /***
40 * Return the maximum size of the pool.
41 *
42 * @return the maximum size of the pool.
43 */
44 long getMaxSize();
45
46 /***
47 * Change the maximum size of the pool.
48 *
49 * @param newSize the new pool size.
50 */
51 void setMaxSize(long newSize);
52
53 /***
54 * Return a PoolAccessor whose consumption is tracked by this pool, using a default SizeOf engine.
55 *
56 * @param store the store which will use the created accessor.
57 * @return a PoolAccessor whose consumption is tracked by this pool.
58 */
59 PoolAccessor<T> createPoolAccessor(T store);
60
61 /***
62 * Register an accessor implementation with this pool.
63 *
64 * @param accessor accessor to be registered
65 */
66 void registerPoolAccessor(PoolAccessor<? extends T> accessor);
67
68 /***
69 * Remove the supplied accessor from this pool.
70 *
71 * @param accessor accessor to be removed
72 */
73 void removePoolAccessor(PoolAccessor<?> accessor);
74
75 /***
76 * Return a PoolAccessor whose consumption is tracked by this pool, using a specific SizeOf engine.
77 *
78 * @param store the store which will use the created accessor.
79 * @param sizeOfEngine the SizeOf engine used to measure the size of objects added through the created accessor.
80 * @return a PoolAccessor whose consumption is tracked by this pool.
81 */
82 PoolAccessor<T> createPoolAccessor(T store, SizeOfEngine sizeOfEngine);
83
84 /***
85 * Return the stores accessing this pool.
86 *
87 * @return stores using this pool
88 */
89 Collection<T> getPoolableStores();
90
91 /***
92 * Return the pool evictor used by this pool.
93 *
94 * @return the pool evictor
95 */
96 PoolEvictor<T> getEvictor();
97
98 }