blob: b0962dc7f0a2bdda4dc99e2db0c663a41ed1a3a4 [file] [log] [blame]
Madan Jampani12390c12014-11-12 00:35:56 -08001package org.onlab.onos.store.service.impl;
2
Madan Jampani9b37d572014-11-12 11:53:24 -08003import org.onlab.onos.store.service.VersionedValue;
4
Madan Jampani44e6a542014-11-12 01:06:51 -08005/**
6 * A table modification event.
7 */
8public final class TableModificationEvent {
Madan Jampani12390c12014-11-12 00:35:56 -08009
Madan Jampani44e6a542014-11-12 01:06:51 -080010 /**
11 * Type of table modification event.
12 *
13 */
Madan Jampani12390c12014-11-12 00:35:56 -080014 public enum Type {
15 ROW_ADDED,
16 ROW_DELETED,
17 ROW_UPDATED
18 }
Madan Jampani44e6a542014-11-12 01:06:51 -080019
Madan Jampani12390c12014-11-12 00:35:56 -080020 private final String tableName;
21 private final String key;
Madan Jampani9b37d572014-11-12 11:53:24 -080022 private final VersionedValue value;
Madan Jampani12390c12014-11-12 00:35:56 -080023 private final Type type;
24
Madan Jampani44e6a542014-11-12 01:06:51 -080025 /**
26 * Creates a new row deleted table modification event.
27 * @param tableName table name.
28 * @param key row key
Madan Jampani9b37d572014-11-12 11:53:24 -080029 * @param value value associated with the key when it was deleted.
Madan Jampani44e6a542014-11-12 01:06:51 -080030 * @return table modification event.
31 */
Madan Jampani9b37d572014-11-12 11:53:24 -080032 public static TableModificationEvent rowDeleted(String tableName, String key, VersionedValue value) {
33 return new TableModificationEvent(tableName, key, value, Type.ROW_DELETED);
Madan Jampani12390c12014-11-12 00:35:56 -080034 }
Madan Jampani44e6a542014-11-12 01:06:51 -080035
36 /**
37 * Creates a new row added table modification event.
38 * @param tableName table name.
39 * @param key row key
Madan Jampani9b37d572014-11-12 11:53:24 -080040 * @param value value associated with the key
Madan Jampani44e6a542014-11-12 01:06:51 -080041 * @return table modification event.
42 */
Madan Jampani9b37d572014-11-12 11:53:24 -080043 public static TableModificationEvent rowAdded(String tableName, String key, VersionedValue value) {
44 return new TableModificationEvent(tableName, key, value, Type.ROW_ADDED);
Madan Jampani12390c12014-11-12 00:35:56 -080045 }
Madan Jampani44e6a542014-11-12 01:06:51 -080046
47 /**
48 * Creates a new row updated table modification event.
49 * @param tableName table name.
50 * @param key row key
Madan Jampani9b37d572014-11-12 11:53:24 -080051 * @param newValue value
Madan Jampani44e6a542014-11-12 01:06:51 -080052 * @return table modification event.
53 */
Madan Jampani9b37d572014-11-12 11:53:24 -080054 public static TableModificationEvent rowUpdated(String tableName, String key, VersionedValue newValue) {
55 return new TableModificationEvent(tableName, key, newValue, Type.ROW_UPDATED);
Madan Jampani12390c12014-11-12 00:35:56 -080056 }
57
Madan Jampani9b37d572014-11-12 11:53:24 -080058 private TableModificationEvent(String tableName, String key, VersionedValue value, Type type) {
Madan Jampani12390c12014-11-12 00:35:56 -080059 this.tableName = tableName;
60 this.key = key;
Madan Jampani9b37d572014-11-12 11:53:24 -080061 this.value = value;
Madan Jampani12390c12014-11-12 00:35:56 -080062 this.type = type;
63 }
64
Madan Jampani44e6a542014-11-12 01:06:51 -080065 /**
66 * Returns name of table this event is for.
67 * @return table name
68 */
Madan Jampani12390c12014-11-12 00:35:56 -080069 public String tableName() {
70 return tableName;
71 }
72
Madan Jampani44e6a542014-11-12 01:06:51 -080073 /**
74 * Returns the row key this event is for.
75 * @return row key
76 */
Madan Jampani12390c12014-11-12 00:35:56 -080077 public String key() {
78 return key;
79 }
80
Madan Jampani44e6a542014-11-12 01:06:51 -080081 /**
Madan Jampani9b37d572014-11-12 11:53:24 -080082 * Returns the value associated with the key. If the event for a deletion, this
83 * method returns value that was deleted.
84 * @return row value
85 */
86 public VersionedValue value() {
87 return value;
88 }
89
90 /**
Madan Jampani44e6a542014-11-12 01:06:51 -080091 * Returns the type of table modification event.
92 * @return event type.
93 */
Madan Jampani12390c12014-11-12 00:35:56 -080094 public Type type() {
95 return type;
96 }
97}