2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.md.controller.topology.manager;
10 import java.util.concurrent.BlockingQueue;
11 import java.util.concurrent.ExecutionException;
12 import java.util.concurrent.LinkedBlockingQueue;
14 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
15 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
16 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import com.google.common.base.Preconditions;
23 final class OperationProcessor implements Runnable {
24 private static final Logger LOG = LoggerFactory.getLogger(OperationProcessor.class);
25 private static final int MAX_TRANSACTION_OPERATIONS = 100;
26 private static final int OPERATION_QUEUE_DEPTH = 500;
28 private final BlockingQueue<TopologyOperation> queue = new LinkedBlockingQueue<>(OPERATION_QUEUE_DEPTH);
29 // FIXME: Flow capable topology exporter should use transaction chaining API
30 private final DataProviderService dataService;
32 OperationProcessor(final DataProviderService dataService) {
33 this.dataService = Preconditions.checkNotNull(dataService);
36 void enqueueOperation(final TopologyOperation task) {
39 } catch (InterruptedException e) {
40 LOG.warn("Interrupted while submitting task {}", task, e);
48 TopologyOperation op = queue.take();
50 LOG.debug("New operations available, starting transaction");
51 final DataModificationTransaction tx = dataService.beginTransaction();
55 op.applyOperation(tx);
58 if (ops < MAX_TRANSACTION_OPERATIONS) {
65 LOG.debug("Processed {} operations, submitting transaction", ops);
68 final RpcResult<TransactionStatus> s = tx.commit().get();
69 if (!s.isSuccessful()) {
70 LOG.error("Topology export failed for Tx:{}", tx.getIdentifier());
72 } catch (ExecutionException e) {
73 LOG.error("Topology export transaction {} failed", tx.getIdentifier(), e.getCause());
76 } catch (InterruptedException e) {
77 LOG.info("Interrupted processing, terminating", e);
80 // Drain all events, making sure any blocked threads are unblocked
81 while (!queue.isEmpty()) {