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 /***
20 * PoolAccessors are used by stores to tell the pools about their resource consumption
21 *
22 * @param <T> type of the store that uses this accessor
23 *
24 * @author Ludovic Orban
25 */
26 public interface PoolAccessor<T> {
27
28 /***
29 * Add an element to the pool.
30 *
31 * @param key the key of the element
32 * @param value the value of the element
33 * @param container the element-container object
34 * @param force true if the pool should accept adding the element, even if it's out of resources
35 * @return how many bytes have been added to the pool or -1 if add failed.
36 */
37 long add(Object key, Object value, Object container, boolean force);
38
39 /***
40 * Check if there is enough room in the pool to add an element without provoking any eviction
41 * @param key the key of the element
42 * @param value the value of the element
43 * @param container the element-container object
44 * @return true if there is enough room left
45 */
46 boolean canAddWithoutEvicting(Object key, Object value, Object container);
47
48 /***
49 * Delete an element from the pool.
50 *
51 * @param key the key of the element
52 * @param value the value of the element
53 * @param container the element-container object
54 * @return how many bytes have been freed from the pool.
55 */
56 long delete(Object key, Object value, Object container);
57
58 /***
59 * Replace an element's component from the pool
60 *
61 * @param role which element component to replace
62 * @param current the currently replaced object
63 * @param replacement the replacement object
64 * @param force true if the pool should accept replacing the element, even if it's out of resources
65 * @return how many bytes have been freed from the pool, may be negative. Long.MAX_VALUE is returned if replace failed.
66 */
67 long replace(Role role, Object current, Object replacement, boolean force);
68
69 /***
70 * Return how many bytes this accessor consumes from the pool.
71 *
72 * @return how many bytes this accessor consumes from the pool.
73 */
74 long getSize();
75
76 /***
77 * unlink this PoolAccessor from its pool.
78 */
79 void unlink();
80
81 /***
82 * Free resources used by this accessor.
83 */
84 void clear();
85
86 /***
87 * Return the store that uses this accessor
88 *
89 * @return store using this accessor
90 */
91 T getStore();
92 }