blob: 5316ae16c0de84e07aee511cc0dc2e9495199948 [file] [log] [blame]
Andrew Brown070dc892015-01-21 09:55:12 -08001/*
Andrew Browna450fad2015-01-22 11:24:40 -08002 * File name: NDNEvent.java
Andrew Brown070dc892015-01-21 09:55:12 -08003 *
4 * Purpose: Signals a Client event for observers to act on
5 *
6 * © Copyright Intel Corporation. All rights reserved.
7 * Intel Corporation, 2200 Mission College Boulevard,
8 * Santa Clara, CA 95052-8119, USA
9 */
10package com.intel.jndn.utils;
11
12/**
Andrew Browna450fad2015-01-22 11:24:40 -080013 * Signals an event (from Client or Server) for observers to act on
Andrew Brown070dc892015-01-21 09:55:12 -080014 * @author Andrew Brown <andrew.brown@intel.com>
15 */
Andrew Browna450fad2015-01-22 11:24:40 -080016public class NDNEvent<T> {
Andrew Brown070dc892015-01-21 09:55:12 -080017
18 protected boolean success;
19 protected long timestamp;
20 protected T packet;
21
22 /**
23 * Constructor
24 */
Andrew Browna450fad2015-01-22 11:24:40 -080025 public NDNEvent() {
Andrew Brown070dc892015-01-21 09:55:12 -080026 timestamp = System.currentTimeMillis();
27 success = false; // an event without a packet is a failed event
28 }
29
30 /**
31 * Constructor
32 *
33 * @param packet
34 */
Andrew Browna450fad2015-01-22 11:24:40 -080035 public NDNEvent(T packet) {
Andrew Brown070dc892015-01-21 09:55:12 -080036 fromPacket(packet);
37 }
38
39 /**
40 * Build this event from a passed packet; the event is considered a failure
41 * if the packet is any type of Exception
42 *
43 * @param packet
44 */
45 public final void fromPacket(T packet) {
46 this.timestamp = System.currentTimeMillis();
47 this.success = !Exception.class.isInstance(packet);
48 this.packet = packet;
49 }
50
51 /**
52 * Retrieve success status
53 *
54 * @return
55 */
56 public boolean isSuccess() {
57 return success;
58 }
59
60 /**
61 * Retrieve event timestamp
62 *
63 * @return
64 */
65 public long getTimestamp() {
66 return timestamp;
67 }
68
69 /**
70 * Retrieve event packet
71 *
72 * @return
73 */
74 public T getPacket() {
75 return packet;
76 }
77}