2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.genius.mdsalutil.internal;
10 import java.util.concurrent.BlockingQueue;
11 import java.util.concurrent.LinkedBlockingQueue;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.genius.utils.batching.ActionableResource;
14 import org.opendaylight.genius.utils.batching.ActionableResourceImpl;
15 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
16 import org.opendaylight.genius.utils.batching.ResourceHandler;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class FlowBatchingUtils {
23 private static final Logger LOG = LoggerFactory.getLogger(FlowBatchingUtils.class);
24 public static final int BATCH_SIZE = 1000;
25 public static final int PERIODICITY = 500;
26 public static Integer batchSize;
27 public static Integer batchInterval;
28 private static DataBroker dataBroker;
29 private static BlockingQueue<ActionableResource> inventoryConfigShardBufferQ;
31 public static DataBroker getBroker() {
35 public static void setBroker(DataBroker broker) {
39 public static void registerWithBatchManager(ResourceHandler resourceHandler, DataBroker dataBroker) {
40 FlowBatchingUtils.setBroker(dataBroker);
42 if (Integer.getInteger("batch.size") != null) {
43 batchSize = Integer.getInteger("batch.size");
46 if (Integer.getInteger("batch.wait.time") != null) {
47 batchInterval = Integer.getInteger("batch.wait.time");
49 ResourceBatchingManager resBatchingManager = ResourceBatchingManager.getInstance();
50 resBatchingManager.registerBatchableResource("MDSALUTIL-INVENTORY-CONFIG", inventoryConfigShardBufferQ,
54 static <T extends DataObject> void update(InstanceIdentifier<T> path, T data) {
55 ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
56 actResource.setAction(ActionableResource.UPDATE);
57 actResource.setInstanceIdentifier(path);
58 actResource.setInstance(data);
59 inventoryConfigShardBufferQ.add(actResource);
62 public static <T extends DataObject> void write(InstanceIdentifier<T> path, T data) {
63 ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
64 actResource.setAction(ActionableResource.CREATE);
65 actResource.setInstanceIdentifier(path);
66 actResource.setInstance(data);
67 inventoryConfigShardBufferQ.add(actResource);
70 static <T extends DataObject> void delete(InstanceIdentifier<T> path) {
71 ActionableResourceImpl actResource = new ActionableResourceImpl(path.toString());
72 actResource.setAction(ActionableResource.DELETE);
73 actResource.setInstanceIdentifier(path);
74 actResource.setInstance(null);
75 inventoryConfigShardBufferQ.add(actResource);
79 inventoryConfigShardBufferQ = new LinkedBlockingQueue<>();