BUG-5280: expose queue messages during reconnect
[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 java.util.function.Consumer;
12 import org.opendaylight.controller.cluster.access.concepts.Request;
13 import org.opendaylight.controller.cluster.access.concepts.Response;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Forwarder class responsible for routing requests from the previous connection incarnation back to the originator,
19  * which can then convert them as appropriate.
20  *
21  * @author Robert Varga
22  */
23 public abstract class ReconnectForwarder {
24     static final Logger LOG = LoggerFactory.getLogger(ReconnectForwarder.class);
25     // Visible for subclass method handle
26     private final AbstractReceivingClientConnection<?> successor;
27
28     protected ReconnectForwarder(final AbstractReceivingClientConnection<?> successor) {
29         this.successor = Preconditions.checkNotNull(successor);
30     }
31
32     protected final void sendToSuccessor(final Request<?, ?> request, final Consumer<Response<?, ?>> callback) {
33         successor.sendRequest(request, callback);
34     }
35
36     protected abstract void forwardEntry(ConnectionEntry entry, long now);
37
38     final AbstractReceivingClientConnection<?> successor() {
39         return successor;
40     }
41 }