d550c6653008afbd941df0e0a884beedfe4798d6
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / OvsdbMonitorCallback.java
1 /*
2  * Copyright (c) 2015 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.ovsdb.southbound;
9
10 import java.util.concurrent.atomic.AtomicBoolean;
11
12 import org.opendaylight.ovsdb.lib.MonitorCallBack;
13 import org.opendaylight.ovsdb.lib.message.TableUpdates;
14 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
15 import org.opendaylight.ovsdb.southbound.transactions.md.OvsdbOperationalCommandAggregator;
16 import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvoker;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class OvsdbMonitorCallback implements MonitorCallBack {
21
22     private static final Logger LOG = LoggerFactory.getLogger(OvsdbMonitorCallback.class);
23     private final InstanceIdentifierCodec instanceIdentifierCodec;
24     private TransactionInvoker txInvoker;
25     private OvsdbConnectionInstance key;
26     private AtomicBoolean intialUpdate = new AtomicBoolean(false);
27
28     OvsdbMonitorCallback(InstanceIdentifierCodec instanceIdentifierCodec, OvsdbConnectionInstance key,
29             TransactionInvoker txInvoker) {
30         this.instanceIdentifierCodec = instanceIdentifierCodec;
31         this.txInvoker = txInvoker;
32         this.key = key;
33     }
34
35     @Override
36     public void update(TableUpdates result, DatabaseSchema dbSchema) {
37         boolean isFirstUpdate = intialUpdate.compareAndSet(false, true);
38         txInvoker.invoke(new OvsdbOperationalCommandAggregator(instanceIdentifierCodec, key, result,
39                 dbSchema, isFirstUpdate));
40         LOG.trace("Updated dbSchema: {} and result: {}", dbSchema, result);
41     }
42
43     @Override
44     public void exception(Throwable exception) {
45         LOG.warn("exception", exception);
46     }
47
48 }