001package org.cache2k.impl;
002
003/*
004 * #%L
005 * cache2k core package
006 * %%
007 * Copyright (C) 2000 - 2015 headissue GmbH, Munich
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the 
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public 
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025import org.cache2k.ClosableIterator;
026import org.cache2k.impl.threading.Futures;
027import org.cache2k.storage.StorageEntry;
028
029import java.util.concurrent.Future;
030
031/**
032 * @author Jens Wilke; created: 2014-06-02
033 */
034public class FailureStorageAdapter extends StorageAdapter {
035
036  Throwable exception;
037
038  public FailureStorageAdapter(Throwable exception) {
039    this.exception = exception;
040  }
041
042  void throwException() {
043    rethrow("failure in past", exception);
044  }
045
046  @Override
047  public void open() {
048
049  }
050
051  @Override
052  public void flush() {
053    throwException();
054  }
055
056  @Override
057  public void purge() {
058    throwException();
059  }
060
061  @Override
062  public boolean checkStorageStillDisconnectedForClear() {
063    throwException();
064    return false;
065  }
066
067  @Override
068  public void disconnectStorageForClear() {
069    throwException();
070  }
071
072  @Override
073  public Future<Void> clearAndReconnect() {
074    throwException();
075    return null;
076  }
077
078  @Override
079  public void put(Entry e, long _nextRefreshTime) {
080    throwException();
081
082  }
083
084  @Override
085  public StorageEntry get(Object key) {
086    throwException();
087    return null;
088  }
089
090  @Override
091  public boolean remove(Object key) {
092    throwException();
093    return false;
094  }
095
096  @Override
097  public void evict(Entry e) {
098    throwException();
099
100  }
101
102  @Override
103  public void expire(Entry e) {
104    throwException();
105
106  }
107
108  @Override
109  public ClosableIterator<Entry> iterateAll() {
110    throwException();
111    return null;
112  }
113
114  @Override
115  public int getTotalEntryCount() {
116    return 0;
117  }
118
119  @Override
120  public int getAlert() {
121    return 3;
122  }
123
124  @Override
125  public void disable(Throwable t) {
126  }
127
128  @Override
129  public Future<Void> cancelTimerJobs() {
130    return new Futures.FinishedFuture<Void>();
131  }
132
133  @Override
134  public Future<Void> shutdown() {
135    return new Futures.ExceptionFuture<Void>(
136      buildThrowable("shutdown impossible, exception in past", exception));
137  }
138
139}