2121 * @author carcassi
2222 */
2323public final class PVEvent {
24- public enum Type {READ_CONNECTION , WRITE_CONNECTION , VALUE , EXCEPTION , WRITE_SUCCEEDED , WRITE_FAILED };
24+ /**
25+ * The type of the event.
26+ */
27+ public enum Type {
28+ /**
29+ * The read connection value has changed. For example, the network
30+ * channel was connected/disconnected, the read access rights were
31+ * changed, ...
32+ */
33+ READ_CONNECTION ,
34+
35+ /**
36+ * The write connection value has changed. For example, the network
37+ * channel was connected/disconnected, the write access rights were
38+ * changed, ...
39+ */
40+ WRITE_CONNECTION ,
41+
42+ /**
43+ * The value has changed. For example, a new value was posted for
44+ * this channel, the metadata associated with it changed, ...
45+ */
46+ VALUE ,
47+
48+ /**
49+ * An error was posted on this channel. For example, a timeout expired,
50+ * the channel was not found, the value did not match the type requested, .,..
51+ */
52+ EXCEPTION ,
53+
54+ /**
55+ * The write was successful. The exact meaning will depend on the
56+ * channel. For example, one channel may return successful if the value
57+ * was posted successfully, one may return successful only if the value
58+ * was processed correctly, ...
59+ */
60+ WRITE_SUCCEEDED ,
61+
62+ /**
63+ * The write was not successful. The exact meaning will depend on the
64+ * channel. For example, one channel may deem the write failed even
65+ * if the value was received correctly, but its processing caused
66+ * an error.
67+ */
68+ WRITE_FAILED };
2569
2670 private final List <Type > types ;
2771 private final Exception exception ;
@@ -36,23 +80,53 @@ private PVEvent(Exception ex, Exception writeError, List<Type> types) {
3680 private PVEvent (Type type ) {
3781 this (null , null , Collections .singletonList (type ));
3882 }
39-
83+
84+ /**
85+ * Checks whether the type of this event contains the given type.
86+ *
87+ * @param type an event type
88+ * @return true if this event is of that type
89+ */
4090 public boolean isType (Type type ) {
4191 return types .contains (type );
4292 }
4393
94+ /**
95+ * All the types of this event. An event may be aggregated and can, therefore,
96+ * map to more than one type.
97+ *
98+ * @return the type list
99+ */
44100 public List <Type > getType () {
45101 return types ;
46102 }
47103
104+ /**
105+ * If the type is {@link Type#EXCEPTION}, it contains the exception. Null
106+ * otherwise.
107+ *
108+ * @return the error associated with the event
109+ */
48110 public Exception getException () {
49111 return exception ;
50112 }
51113
114+ /**
115+ * If the type is {@link Type#WRITE_FAILED}, it contains the error. Null
116+ * otherwise.
117+ *
118+ * @return the error associated with the event
119+ */
52120 public Exception getWriteError () {
53121 return writeError ;
54122 }
55-
123+
124+ /**
125+ * Returns a new event that aggregates this event with the given event.
126+ *
127+ * @param event the event to aggregate to this
128+ * @return the new aggregated event
129+ */
56130 public PVEvent addEvent (PVEvent event ) {
57131 List <Type > newTypes = new ArrayList <>(getType ());
58132 for (Type type : event .getType ()) {
@@ -126,31 +200,68 @@ public String toString() {
126200 private static final PVEvent READ_CONNECTION_VALUE_EVENT = new PVEvent (null , null , Arrays .asList (Type .READ_CONNECTION , Type .VALUE ));
127201 private static final PVEvent WRITE_CONNECTION_EVENT = new PVEvent (Type .WRITE_CONNECTION );
128202 private static final PVEvent WRITE_SUCCEEDED_EVENT = new PVEvent (Type .WRITE_SUCCEEDED );
129-
203+
204+ /**
205+ * A read connection event.
206+ *
207+ * @return an event
208+ */
130209 public static PVEvent readConnectionEvent () {
131210 return READ_CONNECTION_EVENT ;
132211 }
133212
213+ /**
214+ * A value event.
215+ *
216+ * @return an event
217+ */
134218 public static PVEvent valueEvent () {
135219 return VALUE_EVENT ;
136220 }
137-
221+
222+ /**
223+ * A read connection and value event.
224+ *
225+ * @return an event
226+ */
138227 public static PVEvent readConnectionValueEvent () {
139228 return READ_CONNECTION_VALUE_EVENT ;
140229 }
141-
230+
231+ /**
232+ * An exception event.
233+ *
234+ * @param ex the exception to associate with the event
235+ * @return an event
236+ */
142237 public static PVEvent exceptionEvent (Exception ex ) {
143238 return new PVEvent (ex , null , Collections .singletonList (Type .EXCEPTION ));
144239 }
145240
241+ /**
242+ * A write connection event.
243+ *
244+ * @return an event
245+ */
146246 public static PVEvent writeConnectionEvent () {
147247 return WRITE_CONNECTION_EVENT ;
148248 }
149249
250+ /**
251+ * A write succeeded event.
252+ *
253+ * @return an event
254+ */
150255 public static PVEvent writeSucceededEvent () {
151256 return WRITE_SUCCEEDED_EVENT ;
152257 }
153-
258+
259+ /**
260+ * A write failed event.
261+ *
262+ * @param writeError the error associated with the write
263+ * @return an event
264+ */
154265 public static PVEvent writeFailedEvent (Exception writeError ) {
155266 return new PVEvent (null , writeError , Collections .singletonList (Type .WRITE_FAILED ));
156267 }
0 commit comments