Rice Pastry API

org.mpisws.p2p.transport.multiaddress
Class MultiInetAddressTransportLayerImpl

java.lang.Object
  extended by org.mpisws.p2p.transport.multiaddress.MultiInetAddressTransportLayerImpl
All Implemented Interfaces:
MultiInetAddressTransportLayer, TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>, TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>, Destructable

public class MultiInetAddressTransportLayerImpl
extends java.lang.Object
implements MultiInetAddressTransportLayer, TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>

This class adds an epoch and a list of InetSocketAddresses, and also disambiguates between them for the lower layer. This is useful in situations where the node is behind a NAT and is addressed differently for nodes outside the NAT as inside. Optimization: Pre-serialize localAddress in the ctor, then just mem-copy it to the buffer

Author:
Jeff Hoye

Constructor Summary
MultiInetAddressTransportLayerImpl(MultiInetSocketAddress localAddress, TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> wire, Environment env, ErrorHandler<MultiInetSocketAddress> handler, AddressStrategy strategy)
           
 
Method Summary
 void acceptMessages(boolean b)
          Toggle accepting incoming messages.
 void acceptSockets(boolean b)
          Toggle accepting new sockets.
 void destroy()
           
 MultiInetSocketAddress getLocalIdentifier()
          The local node.
 void incomingSocket(P2PSocket<java.net.InetSocketAddress> s)
          Notification of a new socket.
 boolean isSendIdentifier()
           
 void messageReceived(java.net.InetSocketAddress i, java.nio.ByteBuffer m, java.util.Map<java.lang.String,java.lang.Integer> options)
          Called when a new message is received.
 SocketRequestHandle<MultiInetSocketAddress> openSocket(MultiInetSocketAddress i, SocketCallback<MultiInetSocketAddress> deliverSocketToMe, java.util.Map<java.lang.String,java.lang.Integer> options)
          Open a socket to the Identifier
 MessageRequestHandle<MultiInetSocketAddress,java.nio.ByteBuffer> sendMessage(MultiInetSocketAddress i, java.nio.ByteBuffer m, MessageCallback<MultiInetSocketAddress,java.nio.ByteBuffer> deliverAckToMe, java.util.Map<java.lang.String,java.lang.Integer> options)
          Send the message to the identifier
 void setCallback(TransportLayerCallback<MultiInetSocketAddress,java.nio.ByteBuffer> callback)
          Set the callback for incoming sockets/messages
 void setErrorHandler(ErrorHandler<MultiInetSocketAddress> handler)
          To be notified of problems not related to an outgoing messaage/socket.
 void setSendIdentifier(boolean sendIdentifier)
          Set this to false to prevent sending/receiving the identifier at this layer for the message/socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiInetAddressTransportLayerImpl

public MultiInetAddressTransportLayerImpl(MultiInetSocketAddress localAddress,
                                          TransportLayer<java.net.InetSocketAddress,java.nio.ByteBuffer> wire,
                                          Environment env,
                                          ErrorHandler<MultiInetSocketAddress> handler,
                                          AddressStrategy strategy)
Method Detail

openSocket

public SocketRequestHandle<MultiInetSocketAddress> openSocket(MultiInetSocketAddress i,
                                                              SocketCallback<MultiInetSocketAddress> deliverSocketToMe,
                                                              java.util.Map<java.lang.String,java.lang.Integer> options)
Description copied from interface: TransportLayer
Open a socket to the Identifier

Specified by:
openSocket in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - who to open the socket to
deliverSocketToMe - the callback when the socket is opened
options - options on how to open the socket (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
an object to cancel opening the socket if it takes to long, or is no longer relevent

incomingSocket

public void incomingSocket(P2PSocket<java.net.InetSocketAddress> s)
                    throws java.io.IOException
Description copied from interface: TransportLayerCallback
Notification of a new socket.

Specified by:
incomingSocket in interface TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
s - the incoming socket
Throws:
java.io.IOException

sendMessage

public MessageRequestHandle<MultiInetSocketAddress,java.nio.ByteBuffer> sendMessage(MultiInetSocketAddress i,
                                                                                    java.nio.ByteBuffer m,
                                                                                    MessageCallback<MultiInetSocketAddress,java.nio.ByteBuffer> deliverAckToMe,
                                                                                    java.util.Map<java.lang.String,java.lang.Integer> options)
Description copied from interface: TransportLayer
Send the message to the identifier

Specified by:
sendMessage in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - the destination
m - the message
deliverAckToMe - layer dependent notification when the message is sent (can indicate placed on the wire, point-to-point acknowledgement, or end-to-end acknowledgement)
options - delivery options (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
Returns:
ability to cancel the message if no longer relevent

messageReceived

public void messageReceived(java.net.InetSocketAddress i,
                            java.nio.ByteBuffer m,
                            java.util.Map<java.lang.String,java.lang.Integer> options)
                     throws java.io.IOException
Description copied from interface: TransportLayerCallback
Called when a new message is received.

Specified by:
messageReceived in interface TransportLayerCallback<java.net.InetSocketAddress,java.nio.ByteBuffer>
Parameters:
i - The node it is coming from
m - the message
options - describe how the message arrived (udp/tcp, encrypted etc)
Throws:
java.io.IOException - if there is a problem decoding the message

getLocalIdentifier

public MultiInetSocketAddress getLocalIdentifier()
Description copied from interface: TransportLayer
The local node.

Specified by:
getLocalIdentifier in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>
Returns:
The local node.

acceptMessages

public void acceptMessages(boolean b)
Description copied from interface: TransportLayer
Toggle accepting incoming messages. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptMessages in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>

acceptSockets

public void acceptSockets(boolean b)
Description copied from interface: TransportLayer
Toggle accepting new sockets. Useful in flow control if overwhelmed by incoming sockets. Default: true

Specified by:
acceptSockets in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>

destroy

public void destroy()
Specified by:
destroy in interface Destructable

setCallback

public void setCallback(TransportLayerCallback<MultiInetSocketAddress,java.nio.ByteBuffer> callback)
Description copied from interface: TransportLayer
Set the callback for incoming sockets/messages

Specified by:
setCallback in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>
Parameters:
callback - the callback for incoming sockets/messages

setErrorHandler

public void setErrorHandler(ErrorHandler<MultiInetSocketAddress> handler)
Description copied from interface: TransportLayer
To be notified of problems not related to an outgoing messaage/socket. Or to be notified if a callback isn't provided.

Specified by:
setErrorHandler in interface TransportLayer<MultiInetSocketAddress,java.nio.ByteBuffer>
Parameters:
handler - to be notified of problems not related to a specific messaage/socket.

setSendIdentifier

public void setSendIdentifier(boolean sendIdentifier)
Set this to false to prevent sending/receiving the identifier at this layer for the message/socket. Note that identity will return a guess based on the ipaddress of the message/socket, and the epoch will be UNKNOWN Only use this if a higher layer will do the work of identification.

Parameters:
sendIdentifier -

isSendIdentifier

public boolean isSendIdentifier()

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection