andrewsbrown | 1f28bcf | 2015-04-20 13:29:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * jndn-mock |
| 3 | * Copyright (c) 2015, Intel Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU Lesser General Public License, |
| 7 | * version 3, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT ANY |
| 10 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | package com.intel.jndn.mock; |
| 15 | |
| 16 | import java.io.IOException; |
| 17 | import java.nio.ByteBuffer; |
| 18 | import net.named_data.jndn.Data; |
| 19 | import net.named_data.jndn.Face; |
| 20 | import net.named_data.jndn.ForwardingFlags; |
| 21 | import net.named_data.jndn.Interest; |
| 22 | import net.named_data.jndn.InterestFilter; |
| 23 | import net.named_data.jndn.Name; |
| 24 | import net.named_data.jndn.OnData; |
| 25 | import net.named_data.jndn.OnInterest; |
| 26 | import net.named_data.jndn.OnInterestCallback; |
| 27 | import net.named_data.jndn.OnRegisterFailed; |
| 28 | import net.named_data.jndn.OnTimeout; |
| 29 | import net.named_data.jndn.encoding.EncodingException; |
| 30 | import net.named_data.jndn.encoding.WireFormat; |
| 31 | import net.named_data.jndn.util.Blob; |
| 32 | |
| 33 | /** |
| 34 | * Provides help for extending {@link Face}; this should be an interface but |
| 35 | * until it is we need a way to know what is the minimal set of methods to |
| 36 | * override. |
| 37 | * |
| 38 | * @author Andrew Brown <andrew.brown@intel.com> |
| 39 | */ |
| 40 | public abstract class FaceExtension extends Face { |
| 41 | |
| 42 | public long expressInterest(Interest interest, OnData onData, OnTimeout onTimeout, |
| 43 | WireFormat wireFormat) throws IOException { |
| 44 | return expressInterest(interest, onData, onTimeout, wireFormat); |
| 45 | } |
| 46 | |
| 47 | public long expressInterest(Interest interest, OnData onData, OnTimeout onTimeout) throws IOException { |
| 48 | return expressInterest(interest, onData, onTimeout, WireFormat.getDefaultWireFormat()); |
| 49 | } |
| 50 | |
| 51 | public long expressInterest(Interest interest, OnData onData, WireFormat wireFormat) throws IOException { |
| 52 | return expressInterest(interest, onData, null, wireFormat); |
| 53 | } |
| 54 | |
| 55 | public long expressInterest(Interest interest, OnData onData) throws IOException { |
| 56 | return expressInterest(interest, onData, null, WireFormat.getDefaultWireFormat()); |
| 57 | } |
| 58 | |
| 59 | public long expressInterest(Name name, Interest interestTemplate, OnData onData, OnTimeout onTimeout, |
| 60 | WireFormat wireFormat) throws IOException { |
| 61 | Interest interest = new Interest(name); |
| 62 | if (interestTemplate != null) { |
| 63 | interest.setMinSuffixComponents(interestTemplate.getMinSuffixComponents()); |
| 64 | interest.setMaxSuffixComponents(interestTemplate.getMaxSuffixComponents()); |
| 65 | interest.setKeyLocator(interestTemplate.getKeyLocator()); |
| 66 | interest.setExclude(interestTemplate.getExclude()); |
| 67 | interest.setChildSelector(interestTemplate.getChildSelector()); |
| 68 | interest.setMustBeFresh(interestTemplate.getMustBeFresh()); |
| 69 | interest.setScope(interestTemplate.getScope()); |
| 70 | interest.setInterestLifetimeMilliseconds( |
| 71 | interestTemplate.getInterestLifetimeMilliseconds()); |
| 72 | } else { |
| 73 | interest.setInterestLifetimeMilliseconds(4000.0); |
| 74 | } |
| 75 | |
| 76 | return expressInterest(interest, onData, onTimeout, wireFormat); |
| 77 | } |
| 78 | |
| 79 | public abstract long registerPrefix(Name prefix, |
| 80 | OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed, ForwardingFlags flags, |
| 81 | WireFormat wireFormat) throws IOException, net.named_data.jndn.security.SecurityException; |
| 82 | |
| 83 | public abstract long registerPrefix(Name prefix, final OnInterest onInterest, |
| 84 | OnRegisterFailed onRegisterFailed, ForwardingFlags flags, |
| 85 | WireFormat wireFormat) throws IOException, net.named_data.jndn.security.SecurityException; |
| 86 | |
| 87 | public abstract void removeRegisteredPrefix(long registeredPrefixId); |
| 88 | |
| 89 | public abstract long setInterestFilter(InterestFilter filter, OnInterestCallback onInterest); |
| 90 | |
| 91 | public long setInterestFilter(Name prefix, OnInterestCallback onInterest) { |
| 92 | return setInterestFilter(new InterestFilter(prefix), onInterest); |
| 93 | } |
| 94 | |
| 95 | public abstract void unsetInterestFilter(long interestFilterId); |
| 96 | |
| 97 | public abstract void putData(Data data, WireFormat wireFormat) throws IOException; |
| 98 | |
| 99 | public void putData(Data data) throws IOException { |
| 100 | putData(data, WireFormat.getDefaultWireFormat()); |
| 101 | } |
| 102 | |
| 103 | public abstract void send(ByteBuffer encoding) throws IOException; |
| 104 | |
| 105 | public void send(Blob encoding) throws IOException { |
| 106 | send(encoding.buf()); |
| 107 | } |
| 108 | |
| 109 | public abstract void processEvents() throws IOException, EncodingException; |
| 110 | |
| 111 | public abstract boolean isLocal() throws IOException; |
| 112 | |
| 113 | public abstract void shutdown(); |
| 114 | } |