Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rice.pastry.client
Class PastryAppl

    java.lang.Object
      rice.pastry.client.PastryAppl

Direct Known Subclasses:
  CommonAPIAppl, FetchLeafsetApp, HelloWorldApp, PastryEndpoint, PeriodicLeafSetProtocol, Ping, PingClient, PNSApplication, ProbeApp, RendezvousApp, StandardJoinProtocol, StandardLeafSetProtocol, StandardRouter, StandardRouteSetProtocol

    public abstract class PastryAppl

extends java.lang.Object

A PastryAppl is an abstract class that every Pastry application extends. This is the external Pastry API.

Version:
  $Id: PastryAppl.java 4226 2008-05-28 14:56:19Z jeffh $
Author:
  Peter Druschel

Field Summary
`protected int` | `address`
`protected MessageDeserializer` | `deserializer`
`protected java.lang.String` | `instance`
`protected Logger` | `logger`
`protected java.util.Map<java.lang.String,java.lang.Object>` | `options`
`protected AppSocketReceiver` | `receiver` holds the receiverSocket
`protected PastryNode` | `thePastryNode`

Constructor Summary
`PastryAppl(PastryNode pn)` Constructor.
`PastryAppl(PastryNode pn, int port)` Constructor.
`PastryAppl(PastryNode pn, java.lang.String instance)` Constructor.
`PastryAppl(PastryNode pn, java.lang.String instance, int address, MessageDeserializer md)`
`PastryAppl(PastryNode pn, java.lang.String instance, int address, MessageDeserializer md, Logger logger)`

Method Summary
`void` | `accept(AppSocketReceiver receiver)` Sets an AppSocketReceiver to be called when the next socket arrives.
`boolean` | `canReceiveSocket()` Calls receiver.receiveSocket(), then sets receiver to null.
`void` | `connect(NodeHandle handle, AppSocketReceiver receiver, int timeout)` Called to open an ApplicationLevelSocket
`boolean` | `deliverWhenNotReady()` Instructs the MessageDispatch how to behave when the PastryNode is not ready.
`void` | `destroy()` Called when PastryNode is destroyed.
`boolean` | `enrouteMessage(Message msg, Id key, NodeHandle nextHop, SendOptions opt)` Called by pastry when a message is enroute and is passing through this node.
`void` | `finishReceiveSocket(AppSocket socket)`
`int` | `getAddress()` Returns the address of this application.
`MessageDeserializer` | `getDeserializer()`
`LeafSet` | `getLeafSet()` Called by a layered Pastry application to obtain a copy of the leaf set.
`NodeHandle` | `getNodeHandle()` Gets the handle of the Pastry node associated with this client
`Id` | `getNodeId()` Gets the node id associated with this client.
`RoutingTable` | `getRoutingTable()` Called by a layered Pastry application to obtain a copy of the routing table.
`boolean` | `isClosest(Id key)` Called by the layered Pastry application to check if the local pastry node is the one that is currently closest to the object key id.
`void` | `leafSetChange(NodeHandle nh, boolean wasAdded)` Called by pastry when the leaf set changes.
`abstract void` | `messageForAppl(Message msg)` Called by pastry when a message arrives for this application.
`void` | `notifyReady()` Invoked when the Pastry node has joined the overlay network and is ready to send and receive messages As of FreePastry 1.4.1, replaced by PastryNode Observer pattern.
`void` | `receiveMessage(Message msg)` Called by pastry to deliver a message to this client.
`void` | `receiveMessageInternal(RawMessageDelivery msg)`
`void` | `register()`
`void` | `routeMsg(Id key, Message msg, SendOptions opt)` Routes a message to the live node D with nodeId numerically closest to key (at the time of delivery).
`MessageReceipt` | `routeMsg(Id key, Message msg, SendOptions opt, DeliveryNotification deliverAckToMe)`
`boolean` | `routeMsgDirect(NodeHandle dest, Message msg, SendOptions opt)` Sends a message to the Pastry node identified by dest.
`void` | `routeSetChange(NodeHandle nh, boolean wasAdded)` Called by pastry when the route set changes.
`protected void` | `setDeserializer(MessageDeserializer deserializer)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### deserializer

    protected MessageDeserializer deserializer

### instance

    protected java.lang.String instance

### thePastryNode

    protected PastryNode thePastryNode

### address

    protected int address

### logger

    protected Logger logger

### options

    protected java.util.Map<java.lang.String,java.lang.Object> options

### receiver

    protected AppSocketReceiver receiver

  holds the receiverSocket

Constructor Detail

### PastryAppl

    public PastryAppl(PastryNode pn)

  Constructor.

  Parameters:
    `pn` - the pastry node that client will attach to.

### PastryAppl

    public PastryAppl(PastryNode pn,
                      java.lang.String instance)

  Constructor. This constructor will perform the same tasks as the above constructor, but will also create a Pastry address for this application, which is dependent upon the given instance name and the class name.

  Parameters:
    `pn` - the pastry node that client will attach to.
    `instance` - The instance name of this appl.

### PastryAppl

    public PastryAppl(PastryNode pn,
                      java.lang.String instance,
                      int address,
                      MessageDeserializer md)

### PastryAppl

    public PastryAppl(PastryNode pn,
                      java.lang.String instance,
                      int address,
                      MessageDeserializer md,
                      Logger logger)

### PastryAppl

    public PastryAppl(PastryNode pn,
                      int port)

  Constructor. This constructor will perform the same tasks as the above constructor, but will also create a Pastry address for this application, using the specified port. Need to call register on this.

  Parameters:
    `pn` - the pastry node that client will attach to.
    `instance` - The instance name of this appl.

Method Detail

### register

    public void register()

### getAddress

    public int getAddress()

  Returns the address of this application.

  Returns:
    the address.

### receiveMessageInternal

    public void receiveMessageInternal(RawMessageDelivery msg)

### setDeserializer

    protected void setDeserializer(MessageDeserializer deserializer)

### getDeserializer

    public MessageDeserializer getDeserializer()

### receiveMessage

    public void receiveMessage(Message msg)

  Called by pastry to deliver a message to this client.

  Parameters:
    `msg` - the message that is arriving.

### getNodeId

    public final Id getNodeId()

  Gets the node id associated with this client.

  Returns:
    the node id.

### getNodeHandle

    public NodeHandle getNodeHandle()

  Gets the handle of the Pastry node associated with this client

  Returns:
    the node handle

### routeMsgDirect

    public boolean routeMsgDirect(NodeHandle dest,
                                  Message msg,
                                  SendOptions opt)

  Sends a message to the Pastry node identified by dest. If that node has failed or no point-to-point connection can be established to the node from the local node in the Internet, the operation fails. Note that in this case, it may still be possible to send the message to that node using routeMsg.

  Parameters:
    `dest` - the destination node
    `msg` - the message to deliver.
    `cred` - credentials that verify the authenticity of the message.
    `opt` - send options that describe how the message is to be routed.

### routeMsg

    public void routeMsg(Id key,
                         Message msg,
                         SendOptions opt)

  Routes a message to the live node D with nodeId numerically closest to key (at the time of delivery). The message is delivered to the application with address addr at D, and at each Pastry node encountered along the route to D.

  Parameters:
    `key` - the key
    `msg` - the message to deliver.
    `cred` - credentials that verify the authenticity of the message.
    `opt` - send options that describe how the message is to be routed.

### routeMsg

    public MessageReceipt routeMsg(Id key,
                                   Message msg,
                                   SendOptions opt,
                                   DeliveryNotification deliverAckToMe)

### getLeafSet

    public LeafSet getLeafSet()

  Called by a layered Pastry application to obtain a copy of the leaf set. The leaf set contains the nodeId to IP address binding of the l/2 nodes with numerically closest counterclockwise and the l/2 nodes with numerically closest clockwise nodeIds, relatively to the local node's id.

  Returns:
    the local node's leaf set

### getRoutingTable

    public RoutingTable getRoutingTable()

  Called by a layered Pastry application to obtain a copy of the routing table. The routing table contains the nodeId to IP address bindings of R nodes that share the local node's id in the first n digits, and differ in the n+1th digit, for 0 <= n <= ceiling(log_2^b N), where N is the total number of currently live nodes in the Pastry network. The routing table may be incomplete, may contain nodes that cannot be reached from the local node or have failed, and the table may change at any time.

### isClosest

    public boolean isClosest(Id key)

  Called by the layered Pastry application to check if the local pastry node is the one that is currently closest to the object key id.

  Parameters:
    `key` - the object key id
  Returns:
    true if the local node is currently the closest to the key.

### messageForAppl

    public abstract void messageForAppl(Message msg)

  Called by pastry when a message arrives for this application.

  Parameters:
    `msg` - the message that is arriving.

### enrouteMessage

    public boolean enrouteMessage(Message msg,
                                  Id key,
                                  NodeHandle nextHop,
                                  SendOptions opt)

  Called by pastry when a message is enroute and is passing through this node. If this method is not overridden, the default behaviour is to let the message pass through.

  Parameters:
    `msg` - the message that is passing through.
    `key` - the key
    `nextHop` - the default next hop for the message.
    `opt` - the send options the message was sent with.
  Returns:
    true if the message should be routed, false if the message should be cancelled.

### leafSetChange

    public void leafSetChange(NodeHandle nh,
                              boolean wasAdded)

  Called by pastry when the leaf set changes.

  Parameters:
    `nh` - the handle of the node that was added or removed.
    `wasAdded` - true if the node was added, false if the node was removed.

### routeSetChange

    public void routeSetChange(NodeHandle nh,
                               boolean wasAdded)

  Called by pastry when the route set changes.

  Parameters:
    `nh` - the handle of the node that was added or removed.
    `wasAdded` - true if the node was added, false if the node was removed.

### notifyReady

    public void notifyReady()

  Invoked when the Pastry node has joined the overlay network and is ready to send and receive messages As of FreePastry 1.4.1, replaced by PastryNode Observer pattern.

### deliverWhenNotReady

    public boolean deliverWhenNotReady()

  Instructs the MessageDispatch how to behave when the PastryNode is not ready. An application can override this method to return true if it wishes to receive messages before Pastry is ready(). Most applications should leave this as false, so that their application does not have inconsistent routing. However Pastry's protocols (such as the join protocol) need to receive messages before pastry is ready(). This is because they are attempting to make pastry ready().

  Returns:
    false unless the node is a service

### destroy

    public void destroy()

  Called when PastryNode is destroyed. Can be overloaded by applications.

### connect

    public void connect(NodeHandle handle,
                        AppSocketReceiver receiver,
                        int timeout)

  Called to open an ApplicationLevelSocket

### accept

    public void accept(AppSocketReceiver receiver)

  Sets an AppSocketReceiver to be called when the next socket arrives.

  Parameters:
    `receiver` -

### canReceiveSocket

    public boolean canReceiveSocket()

  Calls receiver.receiveSocket(), then sets receiver to null. It sets it to null to allow the application to provide SocketInitiationBackpressure

  Parameters:
    `socket` - the new socket from the network
  Returns:
    false if receiver was null, true receiveSocket() was called

### finishReceiveSocket

    public void finishReceiveSocket(AppSocket socket)
                             throws java.io.IOException

  Throws:
    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Rice Pastry API
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2005 - Rice Pastry.