ovsdb enable checkstyle on error
[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 com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collection;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.ovsdb.lib.operations.OperationResult;
16 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
17 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
18 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 public class TransactInvokerImpl implements TransactInvoker {
26     private static final Logger LOG = LoggerFactory.getLogger(TransactInvokerImpl.class);
27     private OvsdbConnectionInstance connectionInstance;
28     private DatabaseSchema dbSchema;
29
30     public TransactInvokerImpl(OvsdbConnectionInstance connectionInstance, DatabaseSchema dbSchema) {
31         this.connectionInstance = connectionInstance;
32         this.dbSchema = dbSchema;
33     }
34
35     @Override
36     public void invoke(TransactCommand command, BridgeOperationalState state,
37                        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
38         TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
39         command.execute(tb, state, events);
40         invoke(command, tb);
41     }
42
43     @Override
44     public void invoke(TransactCommand command, BridgeOperationalState state,
45                        Collection<DataTreeModification<Node>> modifications) {
46         TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
47         command.execute(tb, state, modifications);
48         invoke(command, tb);
49     }
50
51     private void invoke(TransactCommand command, TransactionBuilder tb) {
52         ListenableFuture<List<OperationResult>> result = tb.execute();
53         LOG.debug("invoke: command: {}, tb: {}", command, tb);
54         if (tb.getOperations().size() > 0) {
55             try {
56                 List<OperationResult> got = result.get();
57                 LOG.debug("OVSDB transaction result: {}", got);
58             } catch (Exception e) {
59                 LOG.warn("Transact execution exception: ", e);
60             }
61             LOG.trace("invoke exit command: {}, tb: {}", command, tb);
62         }
63     }
64
65 }