Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2015 Regents of the University of California.

Author(s):
Jeff Thompson <jefft0@remap.ucla.edu> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that 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. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. A copy of the GNU Lesser General Public License is in the file COPYING.
 
 
 package net.named_data.jndn;
 
An Interest holds a Name and other fields for an interest.
 
 public class Interest implements ChangeCountable {
  
Create a new Interest with the given name and interest lifetime and "none" for other values.

Parameters:
name The name for the interest.
interestLifetimeMilliseconds The interest lifetime in milliseconds, or -1 for none.
 
   public
   Interest(Name namedouble interestLifetimeMilliseconds)
   {
     if (name != null)
       .set(new Name(name));
      = interestLifetimeMilliseconds;
   }

  
Create a new Interest with the given name and "none" for other values.

Parameters:
name The name for the interest.
 
   public
   Interest(Name name)
   {
     if (name != null)
       .set(new Name(name));
   }

  
Create a new interest as a deep copy of the given interest.

Parameters:
interest The interest to copy.
 
   public
   Interest(Interest interest)
   {
     .set(new Name(interest.getName()));
      = interest.minSuffixComponents_;
      = interest.maxSuffixComponents_;
     .set(new KeyLocator(interest.getKeyLocator()));
     .set(new Exclude(interest.getExclude()));
      = interest.childSelector_;
      = interest.answerOriginKind_;
 
      = interest.interestLifetimeMilliseconds_;
      = interest.scope_;
      = interest.getNonce();
     setDefaultWireEncoding(interest.defaultWireEncoding_null);
   }

  
Create a new Interest with an empty name and "none" for all values.
 
   public
   Interest()
   {
   }
 
   public static final int CHILD_SELECTOR_LEFT = 0;
   public static final int CHILD_SELECTOR_RIGHT = 1;
 
   public static final int ANSWER_NO_CONTENT_STORE = 0;
   public static final int ANSWER_CONTENT_STORE = 1;
   public static final int ANSWER_GENERATED = 2;
   public static final int ANSWER_STALE = 4;    // Stale answer OK
   public static final int MARK_STALE = 16;     // Must have scope 0.
                                                // Michael calls this a "hack"
  public static final int DEFAULT_ANSWER_ORIGIN_KIND =
Encode this Interest for a particular wire format. If wireFormat is the default wire format, also set the defaultWireEncoding field to the encoded result.

Parameters:
wireFormat A WireFormat object used to encode this Interest.
Returns:
The encoded buffer.
  public final SignedBlob
  wireEncode(WireFormat wireFormat)
  {
    if (!getDefaultWireEncoding().isNull() &&
        getDefaultWireEncodingFormat() == wireFormat)
      // We already have an encoding in the desired format.
      return getDefaultWireEncoding();
    int[] signedPortionBeginOffset = new int[1];
    int[] signedPortionEndOffset = new int[1];
    Blob encoding = wireFormat.encodeInterest
      (thissignedPortionBeginOffsetsignedPortionEndOffset);
    SignedBlob wireEncoding = new SignedBlob
      (encodingsignedPortionBeginOffset[0], signedPortionEndOffset[0]);
    if (wireFormat == WireFormat.getDefaultWireFormat())
      // This is the default wire encoding.
      setDefaultWireEncoding(wireEncoding, WireFormat.getDefaultWireFormat());
    return wireEncoding;
  }

  
Encode this Interest for the default wire format WireFormat.getDefaultWireFormat().

Returns:
The encoded buffer.
  public final SignedBlob
  {
    return wireEncode(WireFormat.getDefaultWireFormat());
  }

  
Decode the input using a particular wire format and update this Interest.

Parameters:
input The input buffer to decode. This reads from position() to limit(), but does not change the position.
wireFormat A WireFormat object used to decode the input.
Throws:
net.named_data.jndn.encoding.EncodingException For invalid encoding.
  public final void
  wireDecode(ByteBuffer inputWireFormat wireFormatthrows EncodingException
  {
    int[] signedPortionBeginOffset = new int[1];
    int[] signedPortionEndOffset = new int[1];
    wireFormat.decodeInterest
      (thisinputsignedPortionBeginOffsetsignedPortionEndOffset);
    if (wireFormat == WireFormat.getDefaultWireFormat())
      // This is the default wire encoding.
        (new SignedBlob(inputtruesignedPortionBeginOffset[0],
         signedPortionEndOffset[0]), WireFormat.getDefaultWireFormat());
    else
      setDefaultWireEncoding(new SignedBlob(), null);
  }

  
Decode the input using the default wire format WireFormat.getDefaultWireFormat() and update this Interest.

Parameters:
input The input buffer to decode. This reads from position() to limit(), but does not change the position.
Throws:
net.named_data.jndn.encoding.EncodingException For invalid encoding.
  public final void
  {
    wireDecode(input, WireFormat.getDefaultWireFormat());
  }

  
Decode the input using a particular wire format and update this Interest. If wireFormat is the default wire format, also set the defaultWireEncoding field another pointer to the input Blob.

Parameters:
input The input blob to decode.
wireFormat A WireFormat object used to decode the input.
Throws:
net.named_data.jndn.encoding.EncodingException For invalid encoding.
  public final void
  wireDecode(Blob inputWireFormat wireFormatthrows EncodingException
  {
    int[] signedPortionBeginOffset = new int[1];
    int[] signedPortionEndOffset = new int[1];
    wireFormat.decodeInterest
      (thisinput.buf(), signedPortionBeginOffsetsignedPortionEndOffset);
    if (wireFormat == WireFormat.getDefaultWireFormat())
      // This is the default wire encoding.
        (new SignedBlob(inputsignedPortionBeginOffset[0],
         signedPortionEndOffset[0]), WireFormat.getDefaultWireFormat());
    else
      setDefaultWireEncoding(new SignedBlob(), null);
  }

  
Decode the input using the default wire format WireFormat.getDefaultWireFormat() and update this Interest.

Parameters:
input The input blob to decode.
Throws:
net.named_data.jndn.encoding.EncodingException For invalid encoding.
  public final void
  wireDecode(Blob inputthrows EncodingException
  {
    wireDecode(input, WireFormat.getDefaultWireFormat());
  }

  
Encode the name according to the "NDN URI Scheme". If there are interest selectors, append "?" and added the selectors as a query string. For example "/test/name?ndn.ChildSelector=1".

Returns:
The URI string.
Note:
This is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/interest.html#interest-touri-method .
  public final String
  toUri()
  {
    StringBuffer selectors = new StringBuffer();
    if ( >= 0)
      selectors.append("&ndn.MinSuffixComponents=").append();
    if ( >= 0)
      selectors.append("&ndn.MaxSuffixComponents=").append();
    if ( >= 0)
      selectors.append("&ndn.ChildSelector=").append();
    if ( >= 0)
      selectors.append("&ndn.AnswerOriginKind=").append();
    if ( >= 0)
      selectors.append("&ndn.Scope=").append();
      selectors.append("&ndn.InterestLifetime=").append
        ((long)Math.round());
      selectors.append("&ndn.PublisherPublicKeyDigest=");
      Name.toEscapedString
         selectors);
    }
    if (.size() > 0) {
      selectors.append("&ndn.Nonce=");
      Name.toEscapedString(.buf(), selectors);
    }
    if (getExclude().size() > 0)
      selectors.append("&ndn.Exclude=").append(getExclude().toUri());
    StringBuffer result = new StringBuffer();
    result.append(getName().toUri());
    String selectorsString = selectors.toString();
    if (selectorsString.length() > 0)
      // Replace the first & with ?.
      result.append("?").append(selectorsString.substring(1));
    return result.toString();
  }
  public final Name
  getName() { return (Name).get(); }
  public final int
  public final int

Deprecated:
The Interest publisherPublicKeyDigest is deprecated. If you need a publisher public key digest, set the keyLocator keyLocatorType to KEY_LOCATOR_DIGEST and set its key data to the digest.
  public final PublisherPublicKeyDigest
  {
  }
  public final KeyLocator
  getKeyLocator() { return (KeyLocator).get(); }
  public final Exclude
  getExclude() { return (Exclude).get(); }
  public final int
  getChildSelector() { return ; }

  

Deprecated:
Use getMustBeFresh.
  public final int
  {
    if (!.)
      throw new Error
        ("getAnswerOriginKind is for NDNx and is deprecated. To enable while you upgrade your code to use NFD's getMustBeFresh(), set WireFormat.ENABLE_NDNX = true");
    return ;
  }

  
Get the must be fresh flag. If not specified, the default is true.

Returns:
The must be fresh flag.
  public final boolean
  {
    if ( < 0)
      return true;
    else
      return ( & ) == 0;
  }
  public final int
  getScope() { return ; }
  public final double
Return the nonce value from the incoming interest. If you change any of the fields in this Interest object, then the nonce value is cleared.

Returns:
The nonce.
  public final Blob
  {
    if ( != getChangeCount()) {
      // The values have changed, so the existing nonce is invalidated.
       = new Blob();
    }
    return ;
  }

  
Get the incoming face ID of the local control header.

Returns:
The incoming face ID. If not specified, return -1.
Note:
This is an experimental feature. This API may change in the future.
  public final long
  {
  }

  
Get the next hop face ID.

Returns:
The next hop face ID. If not specified, return -1.
Note:
This is an experimental feature. This API may change in the future.
  public final long
  {
  }

  
Set the interest name.

Parameters:
name The interest name. This makes a copy of the name.
Returns:
This Interest so that you can chain calls to update values.
Note:
You can also call getName and change the name values directly.
  public final Interest
  setName(Name name)
  {
    .set(name == null ? new Name() : new Name(name));
    ++;
    return this;
  }

  
Set the min suffix components count.

Parameters:
minSuffixComponents The min suffix components count. If not specified, set to -1.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setMinSuffixComponents(int minSuffixComponents)
  {
     = minSuffixComponents;
    ++;
    return this;
  }

  
Set the max suffix components count.

Parameters:
maxSuffixComponents The max suffix components count. If not specified, set to -1.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setMaxSuffixComponents(int maxSuffixComponents)
  {
     = maxSuffixComponents;
    ++;
    return this;
  }

  
Set the child selector.

Parameters:
childSelector The child selector. If not specified, set to -1.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setChildSelector(int childSelector)
  {
     = childSelector;
    ++;
    return this;
  }

  

Deprecated:
Use setMustBeFresh.
  public final Interest
  setAnswerOriginKind(int answerOriginKind)
  {
    if (!.)
      throw new Error
        ("setAnswerOriginKind is for NDNx and is deprecated. To enable while you upgrade your code to use NFD's setMustBeFresh(), set WireFormat.ENABLE_NDNX = true");
     = answerOriginKind;
    ++;
    return this;
  }

  
Set the MustBeFresh flag.

Parameters:
mustBeFresh True if the content must be fresh, otherwise false. If you do not set this flag, the default value is true.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setMustBeFresh(boolean mustBeFresh)
  {
    if ( < 0) {
      // It is is already the default where MustBeFresh is true.
      if (!mustBeFresh) {
        // Set answerOriginKind_ so that getMustBeFresh returns false.
         = ;
        ++;
      }
    }
    else {
      if (mustBeFresh)
        // Clear the stale bit.
         &= ~;
      else
        // Set the stale bit.
         |= ;
      ++;
    }
    return this;
  }

  
Set the interest scope.

Parameters:
scope The interest scope. If not specified, set to -1.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setScope(int scope)
  {
     = scope;
    ++;
    return this;
  }

  
Set the interest lifetime.

Parameters:
interestLifetimeMilliseconds The interest lifetime in milliseconds. If not specified, set to -1.
Returns:
This Interest so that you can chain calls to update values.
  public final Interest
  setInterestLifetimeMilliseconds(double interestLifetimeMilliseconds)
  {
     = interestLifetimeMilliseconds;
    ++;
    return this;
  }

  

Deprecated:
You should let the wire encoder generate a random nonce internally before sending the interest.
  public final Interest
  setNonce(Blob nonce)
  {
     = (nonce == null ? new Blob() : nonce);
    // Set getNonceChangeCount_ so that the next call to getNonce() won't
    //   clear nonce_.
    ++;
    return this;
  }

  
Set this interest to use a copy of the given KeyLocator object.

Parameters:
keyLocator The KeyLocator object. This makes a copy of the object. If no key locator is specified, set to a new default KeyLocator(), or to a KeyLocator with an unspecified type.
Returns:
This Interest so that you can chain calls to update values.
Note:
ou can also call getKeyLocator and change the key locator directly.
  public final Interest
  setKeyLocator(KeyLocator keyLocator)
  {
    .set(keyLocator == null ? new KeyLocator() : new KeyLocator(keyLocator));
    ++;
    return this;
  }

  
Set this interest to use a copy of the given Exclude object.

Parameters:
exclude The Exclude object. This makes a copy of the object. If no exclude is specified, set to a new default Exclude(), or to an Exclude with size() 0.
Returns:
This Interest so that you can chain calls to update values.
Note:
You can also call getExclude and change the exclude entries directly.
  public final Interest
  setExclude(Exclude exclude)
  {
    .set(exclude == null ? new Exclude() : new Exclude(exclude));
    ++;
    return this;
  }

  
An internal library method to set localControlHeader to a copy of the given LocalControlHeader for an incoming packet. The application should not call this.

Parameters:
localControlHeader The LocalControlHeader which is copied.
Note:
This is an experimental feature. This API may change in the future.
  final void
  {
      (localControlHeader == null ?
       new LocalControlHeader() : new LocalControlHeader(localControlHeader));
    // Don't update changeCount_ since this doesn't affect the wire encoding.
  }

  
Check if this Interest's name matches the given name (using Name.match) and the given name also conforms to the interest selectors.

Parameters:
name The name to check.
Returns:
True if the name and interest selectors match, otherwise false.
  public final boolean
  matchesName(Name name)
  {
    if (!getName().match(name))
      return false;
    if ( >= 0 &&
        // Add 1 for the implicit digest.
        !(name.size() + 1 - getName().size() >= ))
      return false;
    if ( >= 0 &&
        // Add 1 for the implicit digest.
        !(name.size() + 1 - getName().size() <= ))
      return false;
    if (getExclude().size() > 0 && name.size() > getName().size() &&
        getExclude().matches(name.get(getName().size())))
      return false;
    return true;
  }

  
Return a pointer to the defaultWireEncoding, which was encoded with getDefaultWireEncodingFormat().

Returns:
The default wire encoding. Its pointer may be null.
  public final SignedBlob
  {
      // The values have changed, so the default wire encoding is invalidated.
       = new SignedBlob();
       = null;
    }
    return ;
  }

  
Get the WireFormat which is used by getDefaultWireEncoding().

Returns:
The WireFormat, which is only meaningful if the getDefaultWireEncoding() does not have a null pointer.
Get the change count, which is incremented each time this object (or a child object) is changed.

Returns:
The change count.
  public final long
  {
    // Make sure each of the checkChanged is called.
    boolean changed = .checkChanged();
    changed = .checkChanged() || changed;
    changed = .checkChanged() || changed;
    changed = .checkChanged() || changed;
    if (changed)
      // A child object has changed, so update the change count.
      ++;
    return ;
  }
  private void
    (SignedBlob defaultWireEncodingWireFormat defaultWireEncodingFormat)
  {
     = defaultWireEncoding;
     = defaultWireEncodingFormat;
    // Set getDefaultWireEncodingChangeCount_ so that the next call to
    //   getDefaultWireEncoding() won't clear defaultWireEncoding_.
  }
  private final ChangeCounter name_ = new ChangeCounter(new Name());
  private int minSuffixComponents_ = -1;
  private int maxSuffixComponents_ = -1;
  

Deprecated.:
The Interest publisherPublicKeyDigest is deprecated. If you need a publisher public key digest, set the keyLocator keyLocatorType to KEY_LOCATOR_DIGEST and set its key data to the digest.
  private final ChangeCounter keyLocator_ = new ChangeCounter(new KeyLocator());
  private final ChangeCounter exclude_ = new ChangeCounter(new Exclude());
  private int childSelector_ = -1;
  private int answerOriginKind_ = -1;
  private int scope_ = -1;
  private double interestLifetimeMilliseconds_ = -1;
  private Blob nonce_ = new Blob();
  private long getNonceChangeCount_ = 0;
  private long getDefaultWireEncodingChangeCount_ = 0;
  private long changeCount_ = 0;
New to GrepCode? Check out our FAQ X