Add basic netty replication utility
[mdsal.git] / replicate / mdsal-replicate-netty / src / main / java / org / opendaylight / mdsal / replicate / netty / SinkTransactionChainListener.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.mdsal.replicate.netty;
9
10 import static java.util.Objects.requireNonNull;
11
12 import io.netty.channel.Channel;
13 import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
14 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
15 import org.opendaylight.mdsal.dom.api.DOMTransactionChainListener;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 final class SinkTransactionChainListener implements DOMTransactionChainListener {
20     private static final Logger LOG = LoggerFactory.getLogger(SinkTransactionChainListener.class);
21
22     private final Channel channel;
23
24     SinkTransactionChainListener(final Channel channel) {
25         this.channel = requireNonNull(channel);
26     }
27
28     @Override
29     public void onTransactionChainFailed(final DOMTransactionChain chain, final DOMDataTreeTransaction transaction,
30             final Throwable cause) {
31         LOG.error("Transaction chain for channel {} failed", channel, cause);
32         channel.close();
33     }
34
35     @Override
36     public void onTransactionChainSuccessful(final DOMTransactionChain chain) {
37         LOG.info("Transaction chain for channel {} completed", channel);
38     }
39 }