Merge "Bug 3141 - OVSDB southbound operational MDSAL stops getting populated after...
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TransactInvokerImpl.java
1 /*
2  * Copyright (c) 2014 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.ovsdb.transact;
9
10 import java.util.List;
11
12 import org.opendaylight.ovsdb.lib.operations.OperationResult;
13 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
14 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
15 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import com.google.common.util.concurrent.ListenableFuture;
20
21 public class TransactInvokerImpl implements TransactInvoker {
22     private static final Logger LOG = LoggerFactory.getLogger(BridgeUpdateCommand.class);
23     private OvsdbConnectionInstance connectionInstance;
24     private DatabaseSchema dbSchema;
25
26     public TransactInvokerImpl(OvsdbConnectionInstance connectionInstance, DatabaseSchema dbSchema) {
27         this.connectionInstance = connectionInstance;
28         this.dbSchema = dbSchema;
29     }
30
31     @Override
32     public void invoke(TransactCommand command) {
33         TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
34         command.execute(tb);
35         ListenableFuture<List<OperationResult>> result = tb.execute();
36         LOG.debug("invoke: command: {}, tb: {}", command, tb);
37         if (tb.getOperations().size() > 0) {
38             try {
39                 List<OperationResult> got = result.get();
40                 LOG.debug("OVSDB transaction result: {}", got);
41             } catch (Exception e) {
42                 LOG.warn("Transact execution exception: ", e);
43             }
44             LOG.trace("invoke exit command: {}, tb: {}", command, tb);
45         }
46     }
47
48 }