Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * File name: ClientObservable.java |
| 3 | * |
| 4 | * Purpose: |
| 5 | * |
| 6 | * © Copyright Intel Corporation. All rights reserved. |
| 7 | * Intel Corporation, 2200 Mission College Boulevard, |
| 8 | * Santa Clara, CA 95052-8119, USA |
| 9 | */ |
| 10 | package com.intel.jndn.utils; |
| 11 | |
| 12 | import java.util.ArrayList; |
| 13 | import java.util.List; |
| 14 | import java.util.Observable; |
| 15 | import net.named_data.jndn.Data; |
| 16 | import net.named_data.jndn.Interest; |
| 17 | import net.named_data.jndn.Name; |
| 18 | import net.named_data.jndn.OnData; |
| 19 | import net.named_data.jndn.OnInterest; |
| 20 | import net.named_data.jndn.OnTimeout; |
| 21 | import net.named_data.jndn.transport.Transport; |
| 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @author Andrew Brown <andrew.brown@intel.com> |
| 26 | */ |
| 27 | public class ClientObservable extends Observable implements OnData, OnTimeout, OnInterest { |
| 28 | |
| 29 | protected List<ClientObservableEvent> events = new ArrayList<>(); |
| 30 | protected List<Interest> incomingInterestPackets = new ArrayList<>(); |
| 31 | protected List<Data> incomingDataPackets; |
| 32 | |
| 33 | @Override |
| 34 | public void onData(Interest interest, Data data) { |
| 35 | notifyObservers(new ClientObservableEvent(data)); |
| 36 | } |
| 37 | |
| 38 | public void onError(Exception e){ |
| 39 | notifyObservers(new ClientObservableEvent(e)); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void onTimeout(Interest interest) { |
| 44 | notifyObservers(new ClientObservableEvent()); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void onInterest(Name prefix, Interest interest, Transport transport, long registeredPrefixId) { |
| 49 | notifyObservers(new ClientObservableEvent(interest)); |
| 50 | } |
| 51 | } |