Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 1 | /* |
andrewsbrown | 4feb2da | 2015-03-03 16:05:29 -0800 | [diff] [blame] | 2 | * jndn-utils |
| 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. |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 13 | */ |
| 14 | package com.intel.jndn.utils; |
| 15 | |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 16 | import net.named_data.jndn.Data; |
| 17 | import net.named_data.jndn.Face; |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 18 | import net.named_data.jndn.Interest; |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 19 | import net.named_data.jndn.Name; |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 20 | |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 21 | import java.io.IOException; |
| 22 | import java.util.concurrent.CompletableFuture; |
| 23 | |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 24 | /** |
andrewsbrown | 69d5329 | 2015-03-17 19:37:34 +0100 | [diff] [blame] | 25 | * Base functionality provided by all NDN clients in this package. |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 26 | * |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 27 | * @author Andrew Brown, andrew.brown@intel.com |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 28 | */ |
andrewsbrown | 69d5329 | 2015-03-17 19:37:34 +0100 | [diff] [blame] | 29 | public interface Client { |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 30 | |
Andrew Brown | 7b1daf3 | 2015-01-19 16:36:01 -0800 | [diff] [blame] | 31 | /** |
andrewsbrown | 8372eaa | 2015-02-23 10:08:17 -0800 | [diff] [blame] | 32 | * Asynchronously request the Data for an Interest. This will send the |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 33 | * Interest and return immediately; with this method, the user is responsible |
| 34 | * for calling {@link Face#processEvents()} in order for the |
| 35 | * {@link CompletableFuture} to complete. |
Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 36 | * |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 37 | * @param face the {@link Face} on which to make the request; call |
| 38 | * {@link Face#processEvents()} separately to complete the request |
| 39 | * @param interest the {@link Interest} to send over the network |
| 40 | * @return a future {@link Data} packet |
Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 41 | */ |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 42 | CompletableFuture<Data> getAsync(Face face, Interest interest); |
Andrew Brown | db45705 | 2015-02-21 15:41:58 -0800 | [diff] [blame] | 43 | |
| 44 | /** |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 45 | * Convenience method for calling |
| 46 | * {@link #getAsync(net.named_data.jndn.Face, net.named_data.jndn.Interest)} |
| 47 | * with a default {@link Interest} packet. |
Andrew Brown | 7b1daf3 | 2015-01-19 16:36:01 -0800 | [diff] [blame] | 48 | * |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 49 | * @param face the {@link Face} on which to make the request; call |
| 50 | * {@link Face#processEvents()} separately to complete the request |
| 51 | * @param name the {@link Name} to wrap inside a default {@link Interest} |
| 52 | * @return a future {@link Data} packet |
| 53 | */ |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 54 | CompletableFuture<Data> getAsync(Face face, Name name); |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Synchronously retrieve the {@link Data} for an {@link Interest}; this will |
| 58 | * block until complete (i.e. either the data is received or the interest |
| 59 | * times out). |
| 60 | * |
| 61 | * @param face the {@link Face} on which to make the request; this method will |
| 62 | * call {@link Face#processEvents()} at a configurable interval until complete |
| 63 | * or timeout |
| 64 | * @param interest the {@link Interest} to send over the network |
| 65 | * @return a {@link Data} packet |
| 66 | * @throws java.io.IOException if the request fails |
Andrew Brown | 7b1daf3 | 2015-01-19 16:36:01 -0800 | [diff] [blame] | 67 | */ |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 68 | Data getSync(Face face, Interest interest) throws IOException; |
andrewsbrown | 8d5ae29 | 2015-07-01 17:38:22 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Convenience method for calling |
| 72 | * {@link #getSync(net.named_data.jndn.Face, net.named_data.jndn.Interest)} |
| 73 | * with a default {@link Interest} packet. |
| 74 | * |
| 75 | * @param face the {@link Face} on which to make the request; call |
| 76 | * {@link Face#processEvents()} separately to complete the request |
| 77 | * @param name the {@link Name} to wrap inside a default {@link Interest} |
| 78 | * @return a {@link Data} packet |
| 79 | * @throws java.io.IOException if the request fails |
| 80 | */ |
Andrew Brown | 85234ea | 2016-09-07 13:41:29 -0700 | [diff] [blame^] | 81 | Data getSync(Face face, Name name) throws IOException; |
Andrew Brown | 3f2521a | 2015-01-17 22:10:15 -0800 | [diff] [blame] | 82 | } |