blob: 6d1dcd7d10ed3a661b4471295c53d868ea76847e [file] [log] [blame]
Madan Jampani34fec842015-07-22 14:05:08 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Madan Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampani648451f2015-07-21 22:09:05 -070017
Madan Jampani34fec842015-07-22 14:05:08 -070018import static com.google.common.base.MoreObjects.toStringHelper;
19
Madan Jampani648451f2015-07-21 22:09:05 -070020/**
21 * Representation of a state machine update.
22 */
23public class StateMachineUpdate {
24
25 /**
26 * Target data structure type this update is for.
27 */
28 enum Target {
29 /**
30 * Update is for a map.
31 */
Madan Jampania6d787b2015-08-11 11:02:02 -070032 MAP_UPDATE,
Madan Jampani648451f2015-07-21 22:09:05 -070033
34 /**
Madan Jampanibab51a42015-08-10 13:53:35 -070035 * Update is a transaction commit.
36 */
37 TX_COMMIT,
38
39 /**
Madan Jampania6d787b2015-08-11 11:02:02 -070040 * Update is a queue push.
41 */
42 QUEUE_PUSH,
43
44 /**
45 * Update is for some other operation.
Madan Jampani648451f2015-07-21 22:09:05 -070046 */
47 OTHER
48 }
49
50 private final String operationName;
51 private final Object input;
52 private final Object output;
53
54 public StateMachineUpdate(String operationName, Object input, Object output) {
55 this.operationName = operationName;
56 this.input = input;
57 this.output = output;
58 }
59
60 public Target target() {
61 // FIXME: This check is brittle
62 if (operationName.contains("mapUpdate")) {
Madan Jampania6d787b2015-08-11 11:02:02 -070063 return Target.MAP_UPDATE;
Madan Jampanibab51a42015-08-10 13:53:35 -070064 } else if (operationName.contains("commit") || operationName.contains("prepareAndCommit")) {
65 return Target.TX_COMMIT;
Madan Jampania6d787b2015-08-11 11:02:02 -070066 } else if (operationName.contains("queuePush")) {
67 return Target.QUEUE_PUSH;
Madan Jampani648451f2015-07-21 22:09:05 -070068 } else {
69 return Target.OTHER;
70 }
71 }
72
73 @SuppressWarnings("unchecked")
74 public <T> T input() {
75 return (T) input;
76 }
77
78 @SuppressWarnings("unchecked")
79 public <T> T output() {
80 return (T) output;
81 }
Madan Jampani34fec842015-07-22 14:05:08 -070082
83 @Override
84 public String toString() {
85 return toStringHelper(this)
86 .add("name", operationName)
87 .add("input", input)
88 .add("output", output)
89 .toString();
90 }
Madan Jampani648451f2015-07-21 22:09:05 -070091}