9bb7cbe26b5b81fdcc1723e00832c4e86b64ffb4
[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 class ActionableResourceImpl implements ActionableResource {
18     private final Object instance;
19     private final Object oldInstance;
20     private final Object key;
21     private final InstanceIdentifier identifier;
22     private final short action;
23     private final SettableFuture future = SettableFuture.create();
24
25     ActionableResourceImpl(InstanceIdentifier identifier, short action, Object updatedData, Object oldData) {
26         this.key = null;
27         this.action = action;
28         this.identifier = requireNonNull(identifier);
29         this.instance = updatedData;
30         this.oldInstance = oldData;
31     }
32
33     ActionableResourceImpl(Identifier key, InstanceIdentifier identifier, short action, Object updatedData,
34             Object oldData) {
35         this.key = requireNonNull(key);
36         this.action = action;
37         this.identifier = requireNonNull(identifier);
38         this.instance = updatedData;
39         this.oldInstance = oldData;
40     }
41
42     @Override
43     public Object getInstance() {
44         return this.instance;
45     }
46
47     @Override
48     public Object getOldInstance() {
49         return this.oldInstance;
50     }
51
52     @Override
53     public InstanceIdentifier getInstanceIdentifier() {
54         return this.identifier;
55     }
56
57     @Override
58     public short getAction() {
59         return action;
60     }
61
62     @Override
63     public ListenableFuture<Void> getResultFuture() {
64         return future;
65     }
66
67     @Override
68     public String toString() {
69         return key != null ? key.toString() : identifier.toString();
70     }
71 }