View Javadoc

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.constructs.nonstop.store;
18  
19  import java.util.Collection;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Set;
23  
24  import net.sf.ehcache.CacheException;
25  import net.sf.ehcache.Element;
26  import net.sf.ehcache.Status;
27  import net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType;
28  import net.sf.ehcache.constructs.nonstop.ClusterOperation;
29  import net.sf.ehcache.constructs.nonstop.NonStopCacheException;
30  import net.sf.ehcache.constructs.nonstop.NonstopActiveDelegateHolder;
31  import net.sf.ehcache.constructs.nonstop.NonstopTimeoutBehaviorFactory;
32  import net.sf.ehcache.search.Attribute;
33  import net.sf.ehcache.search.Results;
34  import net.sf.ehcache.search.attribute.AttributeExtractor;
35  import net.sf.ehcache.store.ElementValueComparator;
36  import net.sf.ehcache.store.Policy;
37  import net.sf.ehcache.store.StoreListener;
38  import net.sf.ehcache.store.StoreQuery;
39  import net.sf.ehcache.writer.CacheWriterManager;
40  
41  /***
42   * Implementation of {@link NonstopStore} that throws {@link NonStopCacheException} for all operations.
43   *
44   * @author Abhishek Sanoujam
45   *
46   */
47  public final class ExceptionOnTimeoutStore implements NonstopStore {
48  
49      /***
50       * The {@link NonstopTimeoutBehaviorFactory} to create {@link ExceptionOnTimeoutStore} stores
51       */
52      public static final NonstopTimeoutBehaviorFactory FACTORY = new NonstopTimeoutBehaviorFactory() {
53          public NonstopStore createNonstopTimeoutBehaviorStore(NonstopActiveDelegateHolder nonstopActiveDelegateHolder) {
54              return ExceptionOnTimeoutStore.getInstance();
55          }
56      };
57  
58      /***
59       * the singleton instance
60       */
61      private static final ExceptionOnTimeoutStore INSTANCE = new ExceptionOnTimeoutStore();
62  
63      /***
64       * private constructor
65       */
66      private ExceptionOnTimeoutStore() {
67          //
68      }
69  
70      /***
71       * returns the singleton instance
72       *
73       */
74      public static ExceptionOnTimeoutStore getInstance() {
75          return INSTANCE;
76      }
77  
78      /***
79       * {@inheritDoc}.
80       * <p>
81       * Throws {@link NonStopCacheException}
82       */
83      public Element get(final Object key) throws IllegalStateException, CacheException {
84          throw new NonStopCacheException("get for key - '" + key + "'  timed out");
85      }
86  
87      /***
88       * {@inheritDoc}
89       */
90      public Element getQuiet(final Object key) throws IllegalStateException, CacheException {
91          throw new NonStopCacheException("getQuiet for key - '" + key + "'  timed out");
92      }
93  
94      /***
95       * {@inheritDoc}.
96       * <p>
97       * Throws {@link NonStopCacheException}
98       */
99      public List getKeys() throws IllegalStateException, CacheException {
100         throw new NonStopCacheException("getKeys timed out");
101     }
102 
103     /***
104      * {@inheritDoc}.
105      * <p>
106      * Throws {@link NonStopCacheException}
107      */
108     public boolean put(final Element element) throws IllegalArgumentException, IllegalStateException, CacheException {
109         throw new NonStopCacheException("put for element - '" + element + "' timed out");
110     }
111 
112     /***
113      * {@inheritDoc}.
114      * <p>
115      * Throws {@link NonStopCacheException}
116      */
117     public void putAll(final Collection<Element> elements) throws CacheException {
118         throw new NonStopCacheException("putAll for " + elements.size() + " elements timed out");
119     }
120 
121     /***
122      * {@inheritDoc}.
123      * <p>
124      * Throws {@link NonStopCacheException}
125      */
126     public Element remove(final Object key) throws IllegalStateException {
127         throw new NonStopCacheException("remove for key - '" + key + "' timed out");
128     }
129 
130     /***
131      * {@inheritDoc}.
132      * <p>
133      * Throws {@link NonStopCacheException}
134      */
135     public void removeAll(final Collection<Object> keys) throws IllegalStateException {
136         throw new NonStopCacheException("removeAll for " + keys.size() + "  keys timed out");
137     }
138 
139     /***
140      * {@inheritDoc}.
141      * <p>
142      * Throws {@link NonStopCacheException}
143      */
144     public void removeAll() throws IllegalStateException, CacheException {
145         throw new NonStopCacheException("removeAll timed out");
146     }
147 
148     /***
149      * {@inheritDoc}.
150      * <p>
151      * Throws {@link NonStopCacheException}
152      */
153     public void flush() throws IllegalStateException, CacheException {
154         throw new NonStopCacheException("flush timed out");
155     }
156 
157     /***
158      * {@inheritDoc}.
159      * <p>
160      * Throws {@link NonStopCacheException}
161      */
162     public Object getInternalContext() {
163         throw new NonStopCacheException("getInternalContext timed out");
164     }
165 
166     /***
167      * {@inheritDoc}.
168      * <p>
169      * Throws {@link NonStopCacheException}
170      */
171     public int getSize() throws IllegalStateException, CacheException {
172         throw new NonStopCacheException("getSize timed out");
173     }
174 
175     /***
176      * {@inheritDoc}.
177      * <p>
178      * Throws {@link NonStopCacheException}
179      */
180     public Element putIfAbsent(Element element) throws NullPointerException {
181         throw new NonStopCacheException("putIfAbsent timed out");
182     }
183 
184     /***
185      * {@inheritDoc}.
186      * <p>
187      * Throws {@link NonStopCacheException}
188      */
189     public Element replace(Element element) throws NullPointerException {
190         throw new NonStopCacheException("replace timed out");
191     }
192 
193     /***
194      * {@inheritDoc}.
195      * <p>
196      * Throws {@link NonStopCacheException}
197      */
198     public void addStoreListener(StoreListener listener) {
199         throw new NonStopCacheException("addStoreListener timed out");
200     }
201 
202     /***
203      * {@inheritDoc}.
204      * <p>
205      * Throws {@link NonStopCacheException}
206      */
207     public boolean bufferFull() {
208         throw new NonStopCacheException("bufferFull timed out");
209     }
210 
211     /***
212      * {@inheritDoc}.
213      * <p>
214      * Throws {@link NonStopCacheException}
215      */
216     public boolean containsKey(Object key) {
217         throw new NonStopCacheException("containsKey timed out");
218     }
219 
220     /***
221      * {@inheritDoc}.
222      * <p>
223      * Throws {@link NonStopCacheException}
224      */
225     public boolean containsKeyInMemory(Object key) {
226         throw new NonStopCacheException("containsKeyInMemory timed out");
227     }
228 
229     /***
230      * {@inheritDoc}.
231      * <p>
232      * Throws {@link NonStopCacheException}
233      */
234     public boolean containsKeyOffHeap(Object key) {
235         throw new NonStopCacheException("containsKeyOffHeap timed out");
236     }
237 
238     /***
239      * {@inheritDoc}.
240      * <p>
241      * Throws {@link NonStopCacheException}
242      */
243     public boolean containsKeyOnDisk(Object key) {
244         throw new NonStopCacheException("containsKeyOnDisk timed out");
245     }
246 
247     /***
248      * {@inheritDoc}.
249      * <p>
250      * Throws {@link NonStopCacheException}
251      */
252     public void dispose() {
253         throw new NonStopCacheException("dispose timed out");
254     }
255 
256     /***
257      * {@inheritDoc}.
258      * <p>
259      * Throws {@link NonStopCacheException}
260      */
261     public Results executeQuery(StoreQuery query) {
262         throw new NonStopCacheException("executeQuery timed out");
263     }
264 
265     /***
266      * {@inheritDoc}.
267      * <p>
268      * Throws {@link NonStopCacheException}
269      */
270     public void expireElements() {
271         throw new NonStopCacheException("expireElements timed out");
272     }
273 
274     /***
275      * {@inheritDoc}.
276      * <p>
277      * Throws {@link NonStopCacheException}
278      */
279     public Policy getInMemoryEvictionPolicy() {
280         throw new NonStopCacheException("getInMemoryEvictionPolicy timed out");
281     }
282 
283     /***
284      * {@inheritDoc}.
285      * <p>
286      * Throws {@link NonStopCacheException}
287      */
288     public int getInMemorySize() {
289         throw new NonStopCacheException("getInMemorySize timed out");
290     }
291 
292     /***
293      * {@inheritDoc}.
294      * <p>
295      * Throws {@link NonStopCacheException}
296      */
297     public long getInMemorySizeInBytes() {
298         throw new NonStopCacheException("getInMemorySizeInBytes timed out");
299     }
300 
301     /***
302      * {@inheritDoc}.
303      * <p>
304      * Throws {@link NonStopCacheException}
305      */
306     public Object getMBean() {
307         throw new NonStopCacheException("getMBean timed out");
308     }
309 
310     /***
311      * {@inheritDoc}.
312      * <p>
313      * Throws {@link NonStopCacheException}
314      */
315     public int getOffHeapSize() {
316         throw new NonStopCacheException("getOffHeapSize timed out");
317     }
318 
319     /***
320      * {@inheritDoc}.
321      * <p>
322      * Throws {@link NonStopCacheException}
323      */
324     public long getOffHeapSizeInBytes() {
325         throw new NonStopCacheException("getOffHeapSizeInBytes timed out");
326     }
327 
328     /***
329      * {@inheritDoc}.
330      * <p>
331      * Throws {@link NonStopCacheException}
332      */
333     public int getOnDiskSize() {
334         throw new NonStopCacheException("getOnDiskSize timed out");
335     }
336 
337     /***
338      * {@inheritDoc}.
339      * <p>
340      * Throws {@link NonStopCacheException}
341      */
342     public long getOnDiskSizeInBytes() {
343         throw new NonStopCacheException("getOnDiskSizeInBytes timed out");
344     }
345 
346     /***
347      * {@inheritDoc}.
348      * <p>
349      * Throws {@link NonStopCacheException}
350      */
351     public Status getStatus() {
352         throw new NonStopCacheException("getStatus timed out");
353     }
354 
355     /***
356      * {@inheritDoc}.
357      * <p>
358      * Throws {@link NonStopCacheException}
359      */
360     public int getTerracottaClusteredSize() {
361         throw new NonStopCacheException("getTerracottaClusteredSize timed out");
362     }
363 
364     /***
365      * {@inheritDoc}.
366      * <p>
367      * Throws {@link NonStopCacheException}
368      */
369     public boolean isCacheCoherent() {
370         throw new NonStopCacheException("isCacheCoherent timed out");
371     }
372 
373     /***
374      * {@inheritDoc}.
375      * <p>
376      * Throws {@link NonStopCacheException}
377      */
378     public boolean isClusterCoherent() {
379         throw new NonStopCacheException("isClusterCoherent timed out");
380     }
381 
382     /***
383      * {@inheritDoc}.
384      * <p>
385      * Throws {@link NonStopCacheException}
386      */
387     public boolean isNodeCoherent() {
388         throw new NonStopCacheException("isNodeCoherent timed out");
389     }
390 
391     /***
392      * {@inheritDoc}.
393      * <p>
394      * Throws {@link NonStopCacheException}
395      */
396     public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException {
397         throw new NonStopCacheException("putWithWriter timed out");
398     }
399 
400     /***
401      * {@inheritDoc}.
402      * <p>
403      * Throws {@link NonStopCacheException}
404      */
405     public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException {
406         throw new NonStopCacheException("removeElement timed out");
407     }
408 
409     /***
410      * {@inheritDoc}.
411      * <p>
412      * Throws {@link NonStopCacheException}
413      */
414     public void removeStoreListener(StoreListener listener) {
415         throw new NonStopCacheException("removeStoreListener timed out");
416     }
417 
418     /***
419      * {@inheritDoc}.
420      * <p>
421      * Throws {@link NonStopCacheException}
422      */
423     public Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException {
424         throw new NonStopCacheException("removeWithWriter timed out");
425     }
426 
427     /***
428      * {@inheritDoc}.
429      * <p>
430      * Throws {@link NonStopCacheException}
431      */
432     public boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException,
433             IllegalArgumentException {
434         throw new NonStopCacheException("replace timed out");
435     }
436 
437     /***
438      * {@inheritDoc}.
439      * <p>
440      * Throws {@link NonStopCacheException}
441      */
442     public void setAttributeExtractors(Map<String, AttributeExtractor> extractors) {
443         throw new NonStopCacheException("setAttributeExtractors timed out");
444     }
445 
446     /***
447      * {@inheritDoc}.
448      * <p>
449      * Throws {@link NonStopCacheException}
450      */
451     public void setInMemoryEvictionPolicy(Policy policy) {
452         throw new NonStopCacheException("setInMemoryEvictionPolicy timed out");
453     }
454 
455     /***
456      * {@inheritDoc}.
457      * <p>
458      * Throws {@link NonStopCacheException}
459      */
460     public void setNodeCoherent(boolean coherent) throws UnsupportedOperationException {
461         throw new NonStopCacheException("setNodeCoherent timed out");
462     }
463 
464     /***
465      * {@inheritDoc}.
466      * <p>
467      * Throws {@link NonStopCacheException}
468      */
469     public void waitUntilClusterCoherent() throws UnsupportedOperationException {
470         throw new NonStopCacheException("waitUntilClusterCoherent timed out");
471     }
472 
473     /***
474      * {@inheritDoc}.
475      * <p>
476      * Throws {@link NonStopCacheException}
477      */
478     public <T> Attribute<T> getSearchAttribute(String attributeName) {
479         throw new NonStopCacheException("getSearchAttribute timed out");
480     }
481 
482     /***
483      * {@inheritDoc}
484      */
485     public Set getLocalKeys() {
486         throw new NonStopCacheException("getLocalKeys() timed out");
487     }
488 
489     /***
490      * {@inheritDoc}
491      */
492     public Element unlockedGet(Object key) {
493         throw new NonStopCacheException("unlockedGet() timed out");
494     }
495 
496     /***
497      * {@inheritDoc}
498      */
499     public Element unlockedGetQuiet(Object key) {
500         throw new NonStopCacheException("unlockedGetQuiet() timed out");
501     }
502 
503     /***
504      * {@inheritDoc}
505      */
506     public Element unsafeGet(Object key) {
507         throw new NonStopCacheException("unsafeGet() timed out");
508     }
509 
510     /***
511      * {@inheritDoc}
512      */
513     public Element unsafeGetQuiet(Object key) {
514         throw new NonStopCacheException("unsafeGetQuiet() timed out");
515     }
516 
517     /***
518      * {@inheritDoc}
519      */
520     public <V> V executeClusterOperation(ClusterOperation<V> operation) {
521         return operation.performClusterOperationTimedOut(TimeoutBehaviorType.EXCEPTION);
522     }
523 }