com.intel.jndn.utils.client.impl.SegmentedDataStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jndn-utils Show documentation
Show all versions of jndn-utils Show documentation
Collection of tools to simplify synchronous and asynchronous data transfer over the NDN network
/*
* jndn-utils
* Copyright (c) 2015, Intel Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 3, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*/
package com.intel.jndn.utils.client.impl;
import com.intel.jndn.utils.client.OnComplete;
import com.intel.jndn.utils.client.OnException;
import com.intel.jndn.utils.client.DataStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import net.named_data.jndn.Data;
import net.named_data.jndn.Interest;
import net.named_data.jndn.Name;
import net.named_data.jndn.OnData;
import net.named_data.jndn.OnTimeout;
import net.named_data.jndn.encoding.EncodingException;
/**
* As packets are received, they are mapped by their last component's segment
* marker; if the last component is not parseable, an exception is thrown and
* processing completes. The exception to this is if the first packet returned
* does not have a segment marker as the last component; in this case, the
* packet is assumed to be the only packet returned and is placed as the first
* and only packet to assemble. Observers may register callbacks to watch when
* data is received; if data is received out of order, the callbacks will not be
* fired until adjoining packets are received.
*
* @author Andrew Brown
*/
public class SegmentedDataStream implements DataStream {
private static final Logger logger = Logger.getLogger(SegmentedDataStream.class.getName());
private final byte PARTITION_MARKER = 0x00;
private volatile long current = -1;
private volatile long end = Long.MAX_VALUE;
private Map packets = new HashMap<>();
private List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy