import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
*
* @author Robert Varga
*/
-abstract class AbstractClientHistory extends LocalAbortable implements Identifiable<LocalHistoryIdentifier> {
+public abstract class AbstractClientHistory extends LocalAbortable implements Identifiable<LocalHistoryIdentifier> {
enum State {
IDLE,
TX_OPEN,
LOG.debug("Client history {} changed state from {} to {}", this, expected, next);
}
+ final synchronized void doClose() {
+ final State local = state;
+ if (local != State.CLOSED) {
+ Preconditions.checkState(local == State.IDLE, "Local history %s has an open transaction", this);
+ histories.values().forEach(ProxyHistory::close);
+ updateState(local, State.CLOSED);
+ }
+ }
+
+ final synchronized void onProxyDestroyed(final ProxyHistory proxyHistory) {
+ histories.remove(proxyHistory.getIdentifier().getCookie());
+ LOG.debug("{}: removed destroyed proxy {}", this, proxyHistory);
+ }
+
@Override
- public final LocalHistoryIdentifier getIdentifier() {
+ public LocalHistoryIdentifier getIdentifier() {
return identifier;
}
return ret;
}
- abstract ProxyHistory createHistoryProxy(final LocalHistoryIdentifier historyId,
- final AbstractClientConnection<ShardBackendInfo> connection);
+ abstract ProxyHistory createHistoryProxy(LocalHistoryIdentifier historyId,
+ AbstractClientConnection<ShardBackendInfo> connection);
private void createHistoryCallback(final Response<?, ?> response) {
LOG.debug("Create history response {}", response);
* @throws TransactionChainClosedException if this history is closed
* @throws IllegalStateException if a previous dependent transaction has not been closed
*/
- public final ClientTransaction createTransaction() {
+ public ClientTransaction createTransaction() {
checkNotClosed();
synchronized (this) {
* @throws TransactionChainClosedException if this history is closed
* @throws IllegalStateException if a previous dependent transaction has not been closed
*/
- public final ClientSnapshot takeSnapshot() {
+ public ClientSnapshot takeSnapshot() {
checkNotClosed();
synchronized (this) {
}
@Override
- void replaySuccessfulRequests(final Iterable<ConnectionEntry> previousEntries) {
- proxy.replaySuccessfulRequests(previousEntries);
+ void replayRequests(final Collection<ConnectionEntry> previousEntries) {
+ proxy.replayRequests(previousEntries);
}
@Override
}
};
}
+
}