1 /**
2 * Copyright 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.impl;
18
19 import java.util.Collection;
20 import java.util.Collections;
21
22 import net.sf.ehcache.pool.Pool;
23 import net.sf.ehcache.pool.PoolAccessor;
24 import net.sf.ehcache.pool.PoolEvictor;
25 import net.sf.ehcache.pool.PoolableStore;
26 import net.sf.ehcache.pool.SizeOfEngine;
27
28 /**
29 * A no-op pool which does not enforce any resource consumption limit.
30 *
31 * @author Ludovic Orban
32 */
33 public class UnboundedPool implements Pool<PoolableStore> {
34
35 /**
36 * Create an UnboundedPool instance
37 */
38 public UnboundedPool() {
39 }
40
41 /**
42 * {@inheritDoc}
43 */
44 public long getSize() {
45 return -1L;
46 }
47
48 /**
49 * {@inheritDoc}
50 */
51 public long getMaxSize() {
52 return -1L;
53 }
54
55 /**
56 * {@inheritDoc}
57 */
58 public void setMaxSize(long newSize) {
59 }
60
61 /**
62 * {@inheritDoc}
63 */
64 public PoolAccessor<PoolableStore> createPoolAccessor(PoolableStore store, int maxDepth, boolean abortWhenMaxDepthExceeded) {
65 return new UnboundedPoolAccessor();
66 }
67
68 /**
69 * {@inheritDoc}
70 */
71 public PoolAccessor createPoolAccessor(PoolableStore store, SizeOfEngine sizeOfEngine) {
72 return new UnboundedPoolAccessor();
73 }
74
75 /**
76 * {@inheritDoc}
77 */
78 public void registerPoolAccessor(PoolAccessor<? extends PoolableStore> accessor) {
79 //no-op
80 }
81
82 /**
83 * {@inheritDoc}
84 */
85 public void removePoolAccessor(PoolAccessor<?> accessor) {
86 //no-op
87 }
88
89 /**
90 * {@inheritDoc}
91 */
92 public Collection<PoolableStore> getPoolableStores() {
93 return Collections.emptyList();
94 }
95
96 /**
97 * {@inheritDoc}
98 */
99 public PoolEvictor<PoolableStore> getEvictor() {
100 throw new UnsupportedOperationException();
101 }
102
103 /**
104 * The PoolAccessor class of the UnboundedPool
105 */
106 private final class UnboundedPoolAccessor implements PoolAccessor {
107
108 private UnboundedPoolAccessor() {
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 public long add(Object key, Object value, Object container, boolean force) {
115 return 0L;
116 }
117
118 /**
119 * {@inheritDoc}
120 */
121 public boolean canAddWithoutEvicting(Object key, Object value, Object container) {
122 return true;
123 }
124
125 /**
126 * {@inheritDoc}
127 */
128 public long delete(long sizeOf) {
129 return 0L;
130 }
131
132 /**
133 * {@inheritDoc}
134 */
135 public long replace(long currentSize, Object key, Object value, Object container, boolean force) {
136 return 0L;
137 }
138
139 /**
140 * {@inheritDoc}
141 */
142 public long getSize() {
143 return -1L;
144 }
145
146 /**
147 * {@inheritDoc}
148 */
149 public void unlink() {
150 }
151
152 /**
153 * {@inheritDoc}
154 */
155 public void clear() {
156 }
157
158 /**
159 * {@inheritDoc}
160 */
161 public Object getStore() {
162 throw new UnsupportedOperationException();
163 }
164
165 /**
166 * {@inheritDoc}
167 */
168 public void setMaxSize(final long newValue) {
169 }
170
171 /**
172 * {@inheritDoc}
173 */
174 public boolean hasAbortedSizeOf() {
175 return false;
176 }
177 }
178 }
179