BUG-8445: check sessionId before propagating failures
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / ReconnectForwarder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.client;
9
10 import com.google.common.base.Preconditions;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 /**
15  * Forwarder class responsible for routing requests from the previous connection incarnation back to the originator,
16  * which can then convert them as appropriate.
17  *
18  * @author Robert Varga
19  */
20 public abstract class ReconnectForwarder {
21     static final Logger LOG = LoggerFactory.getLogger(ReconnectForwarder.class);
22     // Visible for subclass method handle
23     private final AbstractReceivingClientConnection<?> successor;
24
25     protected ReconnectForwarder(final AbstractReceivingClientConnection<?> successor) {
26         this.successor = Preconditions.checkNotNull(successor);
27     }
28
29     protected final void sendToSuccessor(final ConnectionEntry entry) {
30         successor.sendRequest(entry.getRequest(), entry.getCallback());
31     }
32
33     protected final void replayToSuccessor(final ConnectionEntry entry) {
34         successor.enqueueRequest(entry.getRequest(), entry.getCallback(), entry.getEnqueuedTicks());
35     }
36
37     protected abstract void forwardEntry(ConnectionEntry entry, long now);
38
39     protected abstract void replayEntry(ConnectionEntry entry, long now);
40
41     final AbstractReceivingClientConnection<?> successor() {
42         return successor;
43     }
44 }