Improve logging and documentation; also, SegmentedClient.getAsync() will always return a list.
diff --git a/src/main/java/com/intel/jndn/utils/Client.java b/src/main/java/com/intel/jndn/utils/Client.java
index 446ed63..cb90f6f 100644
--- a/src/main/java/com/intel/jndn/utils/Client.java
+++ b/src/main/java/com/intel/jndn/utils/Client.java
@@ -16,6 +16,7 @@
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
+import java.util.logging.Level;
import net.named_data.jndn.Data;
import net.named_data.jndn.Face;
import net.named_data.jndn.Interest;
@@ -74,7 +75,7 @@
}
});
} catch (IOException e) {
- logger.warning("IO failure while sending interest: " + e);
+ logger.log(Level.WARNING, "IO failure while sending interest: ", e);
futureData.reject(e);
}
@@ -115,7 +116,7 @@
logger.fine("Request time (ms): " + (System.currentTimeMillis() - startTime));
return data;
} catch (ExecutionException | InterruptedException e) {
- logger.warning("Failed to retrieve data: " + e);
+ logger.log(Level.WARNING, "Failed to retrieve data: ", e);
return null;
}
}
diff --git a/src/main/java/com/intel/jndn/utils/FutureData.java b/src/main/java/com/intel/jndn/utils/FutureData.java
index 52ee2c2..0b4e24d 100644
--- a/src/main/java/com/intel/jndn/utils/FutureData.java
+++ b/src/main/java/com/intel/jndn/utils/FutureData.java
@@ -179,7 +179,7 @@
}
// case: error
if (error != null) {
- throw new ExecutionException("Future rejected.", error);
+ throw new ExecutionException("Future rejected with error.", error);
}
// case: packet
return data;
diff --git a/src/main/java/com/intel/jndn/utils/SegmentedClient.java b/src/main/java/com/intel/jndn/utils/SegmentedClient.java
index 0234740..38524ef 100644
--- a/src/main/java/com/intel/jndn/utils/SegmentedClient.java
+++ b/src/main/java/com/intel/jndn/utils/SegmentedClient.java
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
+import java.util.logging.Level;
import java.util.logging.Logger;
import net.named_data.jndn.Data;
import net.named_data.jndn.Face;
@@ -63,7 +64,8 @@
* @param face
* @param interest should include either a ChildSelector or an initial segment
* number
- * @return
+ * @return a list of FutureData packets; if the first segment fails, the list
+ * will contain one FutureData with the failure exception
*/
public List<FutureData> getAsync(Face face, Interest interest) {
// get first segment; default 0 or use a specified start segment
@@ -75,7 +77,7 @@
} catch (EncodingException e) {
// check for interest selector if no initial segment found
if (interest.getChildSelector() == -1) {
- logger.warning("No child selector set for a segmented Interest; this may result in incorrect retrieval.");
+ logger.log(Level.WARNING, "No child selector set for a segmented Interest; this may result in incorrect retrieval.");
}
}
@@ -88,8 +90,8 @@
try {
lastSegment = segments.get(0).get().getMetaInfo().getFinalBlockId().toSegment();
} catch (ExecutionException | InterruptedException | EncodingException e) {
- logger.severe("Failed to retrieve first segment: " + e);
- return null;
+ logger.log(Level.SEVERE, "Failed to retrieve first segment: ", e);
+ return segments;
}
// cut interest segment off
@@ -111,7 +113,8 @@
/**
* Asynchronously send Interests for a segmented Data packet using a default
* interest (e.g. 2 second timeout); this will block until complete (i.e.
- * either data is received or the interest times out).
+ * either data is received or the interest times out). See getAsync(Face face)
+ * for more information.
*
* @param face
* @param name
@@ -128,7 +131,10 @@
* @param face
* @param interest should include either a ChildSelector or an initial segment
* number
- * @return
+ * @return a Data packet; the name will inherit from the sent Interest, not
+ * the returned packets (TODO or should we parse from returned Data? copy
+ * first Data?) and the content will be a concatenation of all of the packet
+ * contents.
*/
public Data getSync(Face face, Interest interest) {
List<FutureData> segments = getAsync(face, interest);
@@ -139,7 +145,7 @@
face.processEvents();
Thread.sleep(SLEEP_TIME_MS);
} catch (EncodingException | IOException e) {
- logger.warning("Failed to retrieve data: " + e);
+ logger.log(Level.WARNING, "Failed to retrieve data: ", e);
return null;
} catch (InterruptedException ex) {
// do nothing
@@ -152,7 +158,7 @@
try {
content.write(futureData.get().getContent().getImmutableArray());
} catch (ExecutionException | IOException | InterruptedException e) {
- logger.warning("Failed to parse retrieved data: " + e);
+ logger.log(Level.WARNING, "Failed to parse retrieved data: ", e);
return null;
}
}
@@ -165,7 +171,8 @@
/**
* Synchronously retrieve the Data for a Name using a default interest (e.g. 2
* second timeout); this will block until complete (i.e. either data is
- * received or the interest times out).
+ * received or the interest times out). See getSync(Face face) for more
+ * information.
*
* @param face
* @param name
diff --git a/src/main/java/com/intel/jndn/utils/Server.java b/src/main/java/com/intel/jndn/utils/Server.java
index 437d480..a5574a1 100644
--- a/src/main/java/com/intel/jndn/utils/Server.java
+++ b/src/main/java/com/intel/jndn/utils/Server.java
@@ -17,6 +17,7 @@
import com.intel.jndn.utils.event.NDNObservable;
import com.intel.jndn.utils.event.NDNObserver;
import java.io.IOException;
+import java.util.logging.Level;
import net.named_data.jndn.Data;
import net.named_data.jndn.Face;
import net.named_data.jndn.ForwardingFlags;
@@ -141,7 +142,7 @@
face.processEvents();
}
} catch (IOException | EncodingException e) {
- logger.warning("Failed to process events." + e);
+ logger.log(Level.WARNING, "Failed to process events.", e);
event.fromPacket(e);
}
sleep();
@@ -228,7 +229,7 @@
face.processEvents();
}
} catch (IOException | EncodingException e) {
- logger.warning("Failed to process events." + e);
+ logger.log(Level.WARNING, "Failed to process events.", e);
eventHandler.notify(e);
}
sleep();
@@ -326,7 +327,7 @@
face.processEvents();
}
} catch (IOException | EncodingException e) {
- logger.warning("Failed to process events." + e);
+ logger.log(Level.WARNING, "Failed to process events.", e);
eventHandler.notify(e);
}
sleep();