blob: 3d6af4a2ba33ca3e5e17ef588c3c54f0d46996e8 [file] [log] [blame]
andrewsbrown1f28bcf2015-04-20 13:29:20 -07001/*
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 */
14package com.intel.jndn.mock;
15
16import java.io.IOException;
17import java.nio.ByteBuffer;
18import net.named_data.jndn.Data;
19import net.named_data.jndn.Face;
20import net.named_data.jndn.ForwardingFlags;
21import net.named_data.jndn.Interest;
22import net.named_data.jndn.InterestFilter;
23import net.named_data.jndn.Name;
24import net.named_data.jndn.OnData;
25import net.named_data.jndn.OnInterest;
26import net.named_data.jndn.OnInterestCallback;
27import net.named_data.jndn.OnRegisterFailed;
28import net.named_data.jndn.OnTimeout;
29import net.named_data.jndn.encoding.EncodingException;
30import net.named_data.jndn.encoding.WireFormat;
31import 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 */
40public 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}