net.named_data.jndn.sync
public class ChronoSync2013 extends Object implements OnInterestCallback, OnData, OnTimeout
Modifier and Type | Class and Description |
---|---|
static interface |
ChronoSync2013.OnInitialized |
static interface |
ChronoSync2013.OnReceivedSyncState |
static class |
ChronoSync2013.SyncState
A SyncState holds the values of a sync state message which is passed to the
onReceivedSyncState callback which was given to the ChronoSyn2013
constructor.
|
Constructor and Description |
---|
ChronoSync2013(ChronoSync2013.OnReceivedSyncState onReceivedSyncState,
ChronoSync2013.OnInitialized onInitialized,
Name applicationDataPrefix,
Name applicationBroadcastPrefix,
long sessionNo,
Face face,
KeyChain keyChain,
Name certificateName,
double syncLifetime,
OnRegisterFailed onRegisterFailed)
Create a new ChronoSync2013 to communicate using the given face.
|
Modifier and Type | Method and Description |
---|---|
long |
getProducerSequenceNo(String dataPrefix,
long sessionNo)
Get the current sequence number in the digest tree for the given
producer dataPrefix and sessionNo.
|
long |
getSequenceNo()
Get the sequence number of the latest data published by this application
instance.
|
void |
onData(Interest interest,
Data data)
When a matching data packet is received, onData is called.
|
void |
onInterest(Name prefix,
Interest interest,
Face face,
long interestFilterId,
InterestFilter filter)
Process the sync interest from the applicationBroadcastPrefix.
|
void |
onTimeout(Interest interest)
If the interest times out according to the interest lifetime, onTimeout is
called.
|
void |
publishNextSequenceNo()
Increment the sequence number, create a sync message with the new
sequence number and publish a data packet where the name is
the applicationBroadcastPrefix + the root digest of the current digest
tree.
|
void |
shutdown()
Unregister callbacks so that this does not respond to interests anymore.
|
public ChronoSync2013(ChronoSync2013.OnReceivedSyncState onReceivedSyncState, ChronoSync2013.OnInitialized onInitialized, Name applicationDataPrefix, Name applicationBroadcastPrefix, long sessionNo, Face face, KeyChain keyChain, Name certificateName, double syncLifetime, OnRegisterFailed onRegisterFailed) throws IOException, SecurityException
onReceivedSyncState
- When ChronoSync receives a sync state message,
this calls onReceivedSyncState.onReceivedSyncState(syncStates, isRecovery)
where syncStates is the
list of SyncState messages and isRecovery is true if this is the initial
list of SyncState messages or from a recovery interest. (For example, if
isRecovery is true, a chat application would not want to re-display all
the associated chat messages.) The callback should send interests to fetch
the application data for the sequence numbers in the sync state.
NOTE: The library will log any exceptions thrown by this callback, but for
better error handling the callback should catch and properly handle any
exceptions.onInitialized
- This calls onInitialized.onInitialized() when the
first sync data is received (or the interest times out because there are no
other publishers yet).
NOTE: The library will log any exceptions thrown by this callback, but for
better error handling the callback should catch and properly handle any
exceptions.applicationDataPrefix
- The prefix used by this application instance
for application data. For example, "/my/local/prefix/ndnchat4/0K4wChff2v".
This is used when sending a sync message for a new sequence number.
In the sync message, this uses applicationDataPrefix.toUri().applicationBroadcastPrefix
- The broadcast name prefix including the
application name. For example, "/ndn/broadcast/ChronoChat-0.3/ndnchat1".
This makes a copy of the name.sessionNo
- The session number used with the applicationDataPrefix in
sync state messages.face
- The Face for calling registerPrefix and expressInterest. The
Face object must remain valid for the life of this ChronoSync2013 object.keyChain
- To sign a data packet containing a sync state message, this
calls keyChain.sign(data, certificateName).certificateName
- The certificate name of the key to use for signing a
data packet containing a sync state message.syncLifetime
- The interest lifetime in milliseconds for sending
sync interests.onRegisterFailed
- If failed to register the prefix to receive
interests for the applicationBroadcastPrefix, this calls
onRegisterFailed.onRegisterFailed(applicationBroadcastPrefix).
NOTE: The library will log any exceptions thrown by this callback, but for
better error handling the callback should catch and properly handle any
exceptions.IOException
SecurityException
public final long getProducerSequenceNo(String dataPrefix, long sessionNo)
dataPrefix
- The producer data prefix as a Name URI string.sessionNo
- The producer session number.public final void publishNextSequenceNo() throws IOException, SecurityException
IOException
SecurityException
public final long getSequenceNo()
public final void shutdown()
public final void onInterest(Name prefix, Interest interest, Face face, long interestFilterId, InterestFilter filter)
onInterest
in interface OnInterestCallback
prefix
- The Name prefix given to registerPrefix or setInterestFilter
(or directly to the InterestFilter constructor). NOTE: You must not change
the prefix object - if you need to change it then make a copy.interest
- The received interest.face
- You should call face.putData to supply a Data packet which
satisfies the Interest.interestFilterId
- The interest filter ID which can be used with
Face.unsetInterestFilter.filter
- The InterestFilter given to registerPrefix or
setInterestFilter, or the InterestFilter created from the Name prefix. The
first argument, prefix, is provided for convenience and is the same as
filter.getPrefix(). NOTE: You must not change the filter object - if you
need to change it then make a copy.public final void onData(Interest interest, Data data)
OnData
Copyright © 2016. All rights reserved.