Turn ActionableResource into an abstract class
[genius.git] / mdsalutil / mdsalutil-impl / src / main / java / org / opendaylight / genius / mdsalutil / internal / FlowBatchingUtils.java
1 /*
2  * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. 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.genius.mdsalutil.internal;
9
10 import java.util.concurrent.BlockingQueue;
11 import java.util.concurrent.LinkedBlockingQueue;
12 import org.opendaylight.genius.utils.batching.ActionableResource;
13 import org.opendaylight.genius.utils.batching.ActionableResources;
14 import org.opendaylight.genius.utils.batching.ResourceBatchingManager;
15 import org.opendaylight.genius.utils.batching.ResourceHandler;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18
19 class FlowBatchingUtils {
20     private final BlockingQueue<ActionableResource<?>> inventoryConfigShardBufferQ = new LinkedBlockingQueue<>();
21
22     public void registerWithBatchManager(ResourceHandler resourceHandler) {
23         ResourceBatchingManager resBatchingManager = ResourceBatchingManager.getInstance();
24         resBatchingManager.registerBatchableResource("MDSALUTIL-INVENTORY-CONFIG", inventoryConfigShardBufferQ,
25                 resourceHandler);
26     }
27
28     <T extends DataObject> void update(InstanceIdentifier<T> path, T data) {
29         inventoryConfigShardBufferQ.add(ActionableResources.update(path, data));
30     }
31
32     <T extends DataObject> void write(InstanceIdentifier<T> path, T data) {
33         inventoryConfigShardBufferQ.add(ActionableResources.create(path, data));
34     }
35
36     <T extends DataObject> void delete(InstanceIdentifier<T> path) {
37         inventoryConfigShardBufferQ.add(ActionableResources.delete(path));
38     }
39 }