public class NdnChronoSynchronizerClient extends Object
For proper operation with NDN, the passed broadcastPrefix
must broadcast to all intended recipients; e.g.
nfdc set-strategy /broadcast /localhost/nfd/strategy/broadcast
TODO interest suppression TODO interest exclude filters TODO interest freshness
Modifier and Type | Class and Description |
---|---|
static interface |
NdnChronoSynchronizerClient.Callback<T>
API for callbacks exposed by this class; this is very similar to Java 8's Consumer class but Java 7 compatibility
is preserved
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DIGEST_ALGORITHM |
static int |
DEFAULT_MAX_HISTORICAL_RECORDS |
static long |
DEFAULT_SYNC_REQUEST_LIFETIME_MS |
Constructor and Description |
---|
NdnChronoSynchronizerClient(ChronoSynchronizer<NdnChronoState> synchronizer,
net.named_data.jndn.Face face,
net.named_data.jndn.Name broadcastPrefix,
long clientId,
long syncRequestLifetimeMs)
Build a synchronizer client
|
NdnChronoSynchronizerClient(net.named_data.jndn.Face face,
net.named_data.jndn.Name broadcastPrefix)
Build a synchronizer client using sane defaults, see DEFAULT_* constants
|
NdnChronoSynchronizerClient(net.named_data.jndn.Face face,
net.named_data.jndn.Name broadcastPrefix,
long clientId)
Build a synchronizer client using sane defaults, see DEFAULT_* constants
|
Modifier and Type | Method and Description |
---|---|
long |
clientId() |
Set<NdnChronoState> |
currentState() |
protected void |
handleSyncRequest(net.named_data.jndn.Face face,
net.named_data.jndn.Interest interest)
Handle sync requests by parsing and passing on to the
ChronoSynchronizer instance |
void |
publish(long id)
Publish the ID of the latest thing available on this client; note that IDs must grow sequentially for
NdnChronoState to understand what the latest state is.
|
protected void |
sendSyncRequest(net.named_data.jndn.Face face,
Digest digest)
Send a sync request by appending the digest to the broadcast prefix: e.g.
|
void |
start(NdnChronoSynchronizerClient.Callback<Long> onSuccess,
NdnChronoSynchronizerClient.Callback<Exception> onError)
Starts network transmissions; since events on the face are asynchronous, failure is returned through a callback.
|
void |
stop()
Helper method for
stop(Callback) ; |
void |
stop(NdnChronoSynchronizerClient.Callback<Long> callback)
Stop the network transmissions for this client; TODO in the future, this should might send a delete action to
other clients
|
void |
subscribe(NdnChronoSynchronizerClient.Callback<Set<NdnChronoState>> callback)
Subscribe to synchronization events, e.g.
|
public static final long DEFAULT_SYNC_REQUEST_LIFETIME_MS
public static final int DEFAULT_MAX_HISTORICAL_RECORDS
public static final String DEFAULT_DIGEST_ALGORITHM
public NdnChronoSynchronizerClient(ChronoSynchronizer<NdnChronoState> synchronizer, net.named_data.jndn.Face face, net.named_data.jndn.Name broadcastPrefix, long clientId, long syncRequestLifetimeMs)
synchronizer
- the ChronoSync implementation to useface
- the NDN face on which to transmit sync requestsbroadcastPrefix
- the NDN prefix on which to transmit sync requests; note that this should be configured
with a broadcast strategy (see http://named-data.net/doc/NFD/0.1.0/manpages/nfdc.html) for correct operationclientId
- the unique identifier for this client; should be large enough (and random enough) to avoid any
collisionssyncRequestLifetimeMs
- the amount of time (in ms) between refreshing the sync request sent to remote
clientspublic NdnChronoSynchronizerClient(net.named_data.jndn.Face face, net.named_data.jndn.Name broadcastPrefix, long clientId)
face
- broadcastPrefix
- clientId
- public NdnChronoSynchronizerClient(net.named_data.jndn.Face face, net.named_data.jndn.Name broadcastPrefix)
face
- the NDN face on which to transmit sync requestsbroadcastPrefix
- the NDN prefix on which to transmit sync requests; note that this should be configured
with a broadcast strategy (see http://named-data.net/doc/NFD/0.1.0/manpages/nfdc.html) for correct operationpublic long clientId()
public Set<NdnChronoState> currentState()
public void start(NdnChronoSynchronizerClient.Callback<Long> onSuccess, NdnChronoSynchronizerClient.Callback<Exception> onError)
onSuccess
- fired with the client ID when this client is started successfullyonError
- fired with the exception thrown when this client fails to startprotected void handleSyncRequest(net.named_data.jndn.Face face, net.named_data.jndn.Interest interest)
ChronoSynchronizer
instanceface
- the incoming faceinterest
- the incoming interestprotected void sendSyncRequest(net.named_data.jndn.Face face, Digest digest) throws IOException
face
- the incoming facedigest
- the current digestIOException
public void publish(long id)
client.publish(0);
client.publish(1);
client.publish(9);
client.publish(3); // will have no effect
id
- the ID of the latest thing available on this clientpublic void subscribe(NdnChronoSynchronizerClient.Callback<Set<NdnChronoState>> callback)
callback
- the callback fired when the synchronization occurspublic void stop(NdnChronoSynchronizerClient.Callback<Long> callback)
callback
- fired when this client successfully stopspublic void stop()
stop(Callback)
;Copyright © 2017. All rights reserved.