ePOST API

rice.post.delivery
Class DeliveryService

java.lang.Object
  extended by rice.post.delivery.DeliveryService
All Implemented Interfaces:
ScribeClient

public class DeliveryService
extends java.lang.Object
implements ScribeClient

This class encapsulates the logic for the delivery of notification messages to users in the Post system.

Version:
$Id: DeliveryService.java 2962 2006-01-25 19:20:17Z jstewart $

Field Summary
protected  java.util.HashSet cache
          A cache of recently-received delivery message ids
protected  Past delivered
          The PAST service used for storing delivery receipts
protected  Environment environment
           
protected  IdFactory factory
          The factory used for creating ids
protected  Logger logger
           
protected  DeliveryPast pending
          The PAST service used for storing pending notifications
protected  PostImpl post
          The address of the user running this storage service.
protected  Scribe scribe
          The Scribe used for subscribing to pending groups
protected  long timeoutInterval
          The default timeout for delivery requests and receipts
 
Constructor Summary
DeliveryService(PostImpl post, DeliveryPast pending, Past delivered, Scribe scribe, IdFactory factory, long timeoutInterval)
          Contructs a StorageService given a PAST to run on top of.
 
Method Summary
 boolean anycast(Topic topic, ScribeContent content)
          This method is invoked when an anycast is received for a topic which this client is interested in.
 void check(Id id, Continuation command)
          Determines whether or not the given ENM has been delivered before
 void childAdded(Topic topic, NodeHandle child)
          Informs this client that a child was added to a topic in which it was interested in.
 void childRemoved(Topic topic, NodeHandle child)
          Informs this client that a child was removed from a topic in which it was interested in.
 void deliver(SignedPostMessage message, Continuation command)
          Requests delivery of the given EncryptedNotificationMessage, which internally contains the destination user.
 void deliver(Topic topic, ScribeContent content)
          Method by which Scribe delivers a message to this client.
 void delivered(SignedPostMessage message, Id id, byte[] signature, Continuation command)
          Records delivery of the given message to the user.
 Id getIdForMessage(SignedPostMessage message)
           
protected  long getTimeout()
          Internal method which returns what the timeout should be for an object inserted now.
 void presence(PresenceMessage message, Continuation command)
          Is called when a presence message is received.
 void subscribeFailed(Topic topic)
          Informs the client that a subscribe on the given topic failed - the client should retry the subscribe or take appropriate action.
 void synchronize()
          Method which periodically checks to see if we've got receipts for any outstanding messages.
 void undeliverable(SignedPostMessage message, Id id, Continuation command)
          Records a message as being undeliverable, which will ensure that delivery won't be attempted again, but does not provide a receipt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timeoutInterval

protected long timeoutInterval
The default timeout for delivery requests and receipts


post

protected PostImpl post
The address of the user running this storage service.


pending

protected DeliveryPast pending
The PAST service used for storing pending notifications


delivered

protected Past delivered
The PAST service used for storing delivery receipts


scribe

protected Scribe scribe
The Scribe used for subscribing to pending groups


factory

protected IdFactory factory
The factory used for creating ids


cache

protected java.util.HashSet cache
A cache of recently-received delivery message ids


environment

protected Environment environment

logger

protected Logger logger
Constructor Detail

DeliveryService

public DeliveryService(PostImpl post,
                       DeliveryPast pending,
                       Past delivered,
                       Scribe scribe,
                       IdFactory factory,
                       long timeoutInterval)
Contructs a StorageService given a PAST to run on top of.

Parameters:
past - The PAST service to use.
credentials - Credentials to use to store data.
keyPair - The keypair to sign/verify data with
Method Detail

getTimeout

protected long getTimeout()
Internal method which returns what the timeout should be for an object inserted now. Basically, does Systemm.currentTimeMillis() + timeoutInterval.

Returns:
The default timeout period for an object inserted now

deliver

public void deliver(SignedPostMessage message,
                    Continuation command)
Requests delivery of the given EncryptedNotificationMessage, which internally contains the destination user. This method inserts the object into Past, and the replicas will automatically pick up the message.

Parameters:
message - The message to deliver
command - The command to run once finished

presence

public void presence(PresenceMessage message,
                     Continuation command)
Is called when a presence message is received. This method causes the delivery service to send the first ENM to the assoicated user.

Parameters:
message - The presence message that was received
command - The command to call with the message to send, if there is one

getIdForMessage

public Id getIdForMessage(SignedPostMessage message)

check

public void check(Id id,
                  Continuation command)
Determines whether or not the given ENM has been delivered before

Parameters:
id - The Id of the message in question
command - The command to run once finished

delivered

public void delivered(SignedPostMessage message,
                      Id id,
                      byte[] signature,
                      Continuation command)
Records delivery of the given message to the user. THis method inserts the receipt and the replicas holding the corresponding delivery request will notice the receipt and disregard the request.

Parameters:
message - The message that was delivered
signature - The signature
command - The command to run once finished

undeliverable

public void undeliverable(SignedPostMessage message,
                          Id id,
                          Continuation command)
Records a message as being undeliverable, which will ensure that delivery won't be attempted again, but does not provide a receipt.

Parameters:
message - The message that was delivered
command - The command to run once finished

synchronize

public void synchronize()
Method which periodically checks to see if we've got receipts for any outstanding messages. If so, then we remove the outstanding message from our pending list. Also, this method makes sure we are subscribed for the correct Scribe groups by looking at the messages we are responsible for.


deliver

public void deliver(Topic topic,
                    ScribeContent content)
Method by which Scribe delivers a message to this client.

Specified by:
deliver in interface ScribeClient
Parameters:
msg - The incoming message.

anycast

public boolean anycast(Topic topic,
                       ScribeContent content)
This method is invoked when an anycast is received for a topic which this client is interested in. The client should return whether or not the anycast should continue.

Specified by:
anycast in interface ScribeClient
Parameters:
topic - The topic the message was anycasted to
content - The content which was anycasted
Returns:
Whether or not the anycast should continue

childAdded

public void childAdded(Topic topic,
                       NodeHandle child)
Informs this client that a child was added to a topic in which it was interested in.

Specified by:
childAdded in interface ScribeClient
Parameters:
topic - The topic to unsubscribe from
child - The child that was added

childRemoved

public void childRemoved(Topic topic,
                         NodeHandle child)
Informs this client that a child was removed from a topic in which it was interested in.

Specified by:
childRemoved in interface ScribeClient
Parameters:
topic - The topic to unsubscribe from
child - The child that was removed

subscribeFailed

public void subscribeFailed(Topic topic)
Informs the client that a subscribe on the given topic failed - the client should retry the subscribe or take appropriate action.

Specified by:
subscribeFailed in interface ScribeClient
Parameters:
topic - The topic which the subscribe failed on

ePOST API

Copyright © 2001-2005 - Rice Pastry.