blob: 885c9fa4302ad58fda03193785480286815515de [file] [log] [blame]
Madan Jampani12390c12014-11-12 00:35:56 -08001package org.onlab.onos.store.service.impl;
2
Madan Jampani44e6a542014-11-12 01:06:51 -08003/**
4 * A table modification event.
5 */
6public final class TableModificationEvent {
Madan Jampani12390c12014-11-12 00:35:56 -08007
Madan Jampani44e6a542014-11-12 01:06:51 -08008 /**
9 * Type of table modification event.
10 *
11 */
Madan Jampani12390c12014-11-12 00:35:56 -080012 public enum Type {
13 ROW_ADDED,
14 ROW_DELETED,
15 ROW_UPDATED
16 }
Madan Jampani44e6a542014-11-12 01:06:51 -080017
Madan Jampani12390c12014-11-12 00:35:56 -080018 private final String tableName;
19 private final String key;
20 private final Type type;
21
Madan Jampani44e6a542014-11-12 01:06:51 -080022 /**
23 * Creates a new row deleted table modification event.
24 * @param tableName table name.
25 * @param key row key
26 * @return table modification event.
27 */
Madan Jampani12390c12014-11-12 00:35:56 -080028 public static TableModificationEvent rowDeleted(String tableName, String key) {
29 return new TableModificationEvent(tableName, key, Type.ROW_DELETED);
30 }
Madan Jampani44e6a542014-11-12 01:06:51 -080031
32 /**
33 * Creates a new row added table modification event.
34 * @param tableName table name.
35 * @param key row key
36 * @return table modification event.
37 */
Madan Jampani12390c12014-11-12 00:35:56 -080038 public static TableModificationEvent rowAdded(String tableName, String key) {
39 return new TableModificationEvent(tableName, key, Type.ROW_ADDED);
40 }
Madan Jampani44e6a542014-11-12 01:06:51 -080041
42 /**
43 * Creates a new row updated table modification event.
44 * @param tableName table name.
45 * @param key row key
46 * @return table modification event.
47 */
Madan Jampani12390c12014-11-12 00:35:56 -080048 public static TableModificationEvent rowUpdated(String tableName, String key) {
49 return new TableModificationEvent(tableName, key, Type.ROW_UPDATED);
50 }
51
52 private TableModificationEvent(String tableName, String key, Type type) {
53 this.tableName = tableName;
54 this.key = key;
55 this.type = type;
56 }
57
Madan Jampani44e6a542014-11-12 01:06:51 -080058 /**
59 * Returns name of table this event is for.
60 * @return table name
61 */
Madan Jampani12390c12014-11-12 00:35:56 -080062 public String tableName() {
63 return tableName;
64 }
65
Madan Jampani44e6a542014-11-12 01:06:51 -080066 /**
67 * Returns the row key this event is for.
68 * @return row key
69 */
Madan Jampani12390c12014-11-12 00:35:56 -080070 public String key() {
71 return key;
72 }
73
Madan Jampani44e6a542014-11-12 01:06:51 -080074 /**
75 * Returns the type of table modification event.
76 * @return event type.
77 */
Madan Jampani12390c12014-11-12 00:35:56 -080078 public Type type() {
79 return type;
80 }
81}