3550ae606d12f0317b8b13fa43f88303059b275f
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / utils / batching / ActionableResourceImpl.java
1 /*
2  * Copyright (c) 2015 - 2016 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.utils.batching;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.yangtools.concepts.Identifier;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16
17 public class ActionableResourceImpl implements ActionableResource {
18     private Object instance;
19     private Object oldInstance;
20     private Object key;
21     private InstanceIdentifier identifier;
22     private short action;
23     private final SettableFuture future = SettableFuture.create();
24
25     @Deprecated
26     public ActionableResourceImpl(String key) {
27         this.key = requireNonNull(key);
28     }
29
30     ActionableResourceImpl(InstanceIdentifier identifier, short action, Object updatedData, Object oldData) {
31         this.key = null;
32         this.action = action;
33         this.identifier = requireNonNull(identifier);
34         this.instance = updatedData;
35         this.oldInstance = oldData;
36     }
37
38     ActionableResourceImpl(Identifier key, InstanceIdentifier identifier, short action, Object updatedData,
39             Object oldData) {
40         this.key = requireNonNull(key);
41         this.action = action;
42         this.identifier = requireNonNull(identifier);
43         this.instance = updatedData;
44         this.oldInstance = oldData;
45     }
46
47     @Deprecated
48     public ActionableResourceImpl(String key, InstanceIdentifier identifier, short action, Object updatedData,
49             Object oldData) {
50         this.instance = updatedData;
51         this.oldInstance = oldData;
52         this.key = key;
53         this.identifier = identifier;
54         this.action = action;
55     }
56
57     public void setInstance(Object instance) {
58         this.instance = instance;
59     }
60
61     @Override
62     public Object getInstance() {
63         return this.instance;
64     }
65
66     public void setOldInstance(Object oldInstance) {
67         this.oldInstance = oldInstance;
68     }
69
70     @Override
71     public Object getOldInstance() {
72         return this.oldInstance;
73     }
74
75     public void setInstanceIdentifier(InstanceIdentifier instanceIdentifier) {
76         this.identifier = instanceIdentifier;
77     }
78
79     @Override
80     public InstanceIdentifier getInstanceIdentifier() {
81         return this.identifier;
82     }
83
84     public void setAction(short action) {
85         this.action = action;
86     }
87
88     @Override
89     public short getAction() {
90         return action;
91     }
92
93     public void setKey(String key) {
94         this.key = key;
95     }
96
97     @Override
98     public ListenableFuture<Void> getResultFuture() {
99         return future;
100     }
101
102     @Override
103     public String toString() {
104         return key != null ? key.toString() : identifier.toString();
105     }
106 }