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