Madan Jampani | 34fec84 | 2015-07-22 14:05:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 16 | package org.onosproject.store.consistent.impl; |
| 17 | |
Madan Jampani | 34fec84 | 2015-07-22 14:05:08 -0700 | [diff] [blame] | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
Madan Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 20 | /** |
| 21 | * Representation of a state machine update. |
| 22 | */ |
| 23 | public 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 Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 32 | MAP_UPDATE, |
Madan Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Madan Jampani | bab51a4 | 2015-08-10 13:53:35 -0700 | [diff] [blame] | 35 | * Update is a transaction commit. |
| 36 | */ |
| 37 | TX_COMMIT, |
| 38 | |
| 39 | /** |
Madan Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 40 | * Update is a queue push. |
| 41 | */ |
| 42 | QUEUE_PUSH, |
| 43 | |
| 44 | /** |
| 45 | * Update is for some other operation. |
Madan Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 46 | */ |
| 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 Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 63 | return Target.MAP_UPDATE; |
Madan Jampani | bab51a4 | 2015-08-10 13:53:35 -0700 | [diff] [blame] | 64 | } else if (operationName.contains("commit") || operationName.contains("prepareAndCommit")) { |
| 65 | return Target.TX_COMMIT; |
Madan Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 66 | } else if (operationName.contains("queuePush")) { |
| 67 | return Target.QUEUE_PUSH; |
Madan Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 68 | } 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 Jampani | 34fec84 | 2015-07-22 14:05:08 -0700 | [diff] [blame] | 82 | |
| 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 Jampani | 648451f | 2015-07-21 22:09:05 -0700 | [diff] [blame] | 91 | } |