Initial pubsub; waiting on MockFace to fully test
diff --git a/src/main/java/com/intel/jndn/utils/ClientObservable.java b/src/main/java/com/intel/jndn/utils/ClientObservable.java
index add1c29..ce6beda 100644
--- a/src/main/java/com/intel/jndn/utils/ClientObservable.java
+++ b/src/main/java/com/intel/jndn/utils/ClientObservable.java
@@ -26,26 +26,105 @@
*/
public class ClientObservable extends Observable implements OnData, OnTimeout, OnInterest {
- protected List<ClientObservableEvent> events = new ArrayList<>();
- protected List<Interest> incomingInterestPackets = new ArrayList<>();
- protected List<Data> incomingDataPackets;
+ protected List<ClientObservableEvent> events = new ArrayList<>();
+ protected List<Interest> incomingInterestPackets = new ArrayList<>();
+ protected List<Data> incomingDataPackets;
- @Override
- public void onData(Interest interest, Data data) {
- notifyObservers(new ClientObservableEvent(data));
- }
-
- public void onError(Exception e){
- notifyObservers(new ClientObservableEvent(e));
- }
+ /**
+ * Generic notification
+ *
+ * @param <T>
+ * @param packet
+ */
+ public <T> void notify(T packet) {
+ setChanged();
+ notifyObservers(new ClientObservableEvent(packet));
+ }
- @Override
- public void onTimeout(Interest interest) {
- notifyObservers(new ClientObservableEvent());
- }
-
- @Override
- public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) {
- notifyObservers(new ClientObservableEvent(interest));
- }
+ /**
+ * Handle data packets
+ *
+ * @param interest
+ * @param data
+ */
+ @Override
+ public void onData(Interest interest, Data data) {
+ notify(data);
+ }
+
+ /**
+ * Handle exceptions
+ *
+ * @param e
+ */
+ public void onError(Exception e) {
+ notify(e);
+ }
+
+ /**
+ * Handle timeouts
+ *
+ * @param interest
+ */
+ @Override
+ public void onTimeout(Interest interest) {
+ notify(interest);
+ }
+
+ /**
+ * Handle incoming interests
+ *
+ * @param prefix
+ * @param interest
+ * @param transport
+ * @param registeredPrefixId
+ */
+ @Override
+ public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) {
+ notify(interest); // TODO wrap
+ }
+
+ /**
+ * Helper to reference both outgoing interest and incoming data packets
+ */
+ class InterestDataPacket {
+
+ private Interest interest;
+ private Data data;
+
+ public InterestDataPacket(Interest interest, Data data) {
+ this.interest = interest;
+ this.data = data;
+ }
+
+ public Data getData() {
+ return data;
+ }
+
+ public Interest getInterest() {
+ return interest;
+ }
+ }
+
+ /**
+ * Helper to reference both incoming interest and the transport to send data on
+ */
+ class InterestTransportPacket{
+ private Interest interest;
+ private Transport transport;
+
+ public InterestTransportPacket(Interest interest, Transport transport) {
+ this.interest = interest;
+ this.transport = transport;
+ }
+
+ public Interest getInterest() {
+ return interest;
+ }
+
+ public Transport getTransport() {
+ return transport;
+ }
+
+ }
}