|
Rice Pastry API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mpisws.p2p.transport.wire.magicnumber.MagicNumberTransportLayer<Identity>
public class MagicNumberTransportLayer<Identity>
This class eliminates random connections by dropping all messages/sockets that don't correlate to a specific header. It is the simplest example of how to add a new layer into the mpisws transport layer system.
| Nested Class Summary | |
|---|---|
protected class |
MagicNumberTransportLayer.VerifyHeaderReceiver
|
| Field Summary | |
|---|---|
protected TransportLayerCallback<Identity,java.nio.ByteBuffer> |
callback
|
protected Environment |
environment
|
protected ErrorHandler<Identity> |
errorHandler
|
byte[] |
HEADER
|
protected Logger |
logger
|
int |
SOCKET_TIMEOUT
|
protected TransportLayer<Identity,java.nio.ByteBuffer> |
wire
|
| Constructor Summary | |
|---|---|
MagicNumberTransportLayer(TransportLayer<Identity,java.nio.ByteBuffer> wtl,
Environment env,
ErrorHandler<Identity> errorHandler,
byte[] header,
int timeOut)
|
|
| Method Summary | |
|---|---|
void |
acceptMessages(boolean b)
Toggle accepting incoming messages. |
void |
acceptSockets(boolean b)
Toggle accepting new sockets. |
void |
destroy()
|
Identity |
getLocalIdentifier()
The local node. |
void |
incomingSocket(P2PSocket<Identity> s)
Notification of a new socket. |
void |
messageReceived(Identity i,
java.nio.ByteBuffer m,
java.util.Map<java.lang.String,java.lang.Integer> options)
Called when a new message is received. |
SocketRequestHandle |
openSocket(Identity i,
SocketCallback<Identity> deliverSocketToMe,
java.util.Map<java.lang.String,java.lang.Integer> options)
Open a socket to the Identifier |
MessageRequestHandle<Identity,java.nio.ByteBuffer> |
sendMessage(Identity i,
java.nio.ByteBuffer m,
MessageCallback<Identity,java.nio.ByteBuffer> deliverAckToMe,
java.util.Map<java.lang.String,java.lang.Integer> options)
Send the message to the identifier |
void |
setCallback(TransportLayerCallback<Identity,java.nio.ByteBuffer> callback)
Set the callback for incoming sockets/messages |
void |
setErrorHandler(ErrorHandler<Identity> handler)
To be notified of problems not related to an outgoing messaage/socket. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Logger logger
protected Environment environment
protected TransportLayerCallback<Identity,java.nio.ByteBuffer> callback
protected ErrorHandler<Identity> errorHandler
protected TransportLayer<Identity,java.nio.ByteBuffer> wire
public byte[] HEADER
public int SOCKET_TIMEOUT
| Constructor Detail |
|---|
public MagicNumberTransportLayer(TransportLayer<Identity,java.nio.ByteBuffer> wtl,
Environment env,
ErrorHandler<Identity> errorHandler,
byte[] header,
int timeOut)
wtl - env - callback - notify me of new sockets/messageserrorHandler - call me when there is a problemheader - the header to expect from a socket/packettimeOut - how long to wait before killing a socket that is not sending (milliseconds)| Method Detail |
|---|
public void setCallback(TransportLayerCallback<Identity,java.nio.ByteBuffer> callback)
TransportLayer
setCallback in interface TransportLayer<Identity,java.nio.ByteBuffer>callback - the callback for incoming sockets/messagespublic void setErrorHandler(ErrorHandler<Identity> handler)
TransportLayer
setErrorHandler in interface TransportLayer<Identity,java.nio.ByteBuffer>handler - to be notified of problems not related to a specific messaage/socket.public void acceptMessages(boolean b)
TransportLayer
acceptMessages in interface TransportLayer<Identity,java.nio.ByteBuffer>public void acceptSockets(boolean b)
TransportLayer
acceptSockets in interface TransportLayer<Identity,java.nio.ByteBuffer>public Identity getLocalIdentifier()
TransportLayer
getLocalIdentifier in interface TransportLayer<Identity,java.nio.ByteBuffer>
public SocketRequestHandle openSocket(Identity i,
SocketCallback<Identity> deliverSocketToMe,
java.util.Map<java.lang.String,java.lang.Integer> options)
TransportLayer
openSocket in interface TransportLayer<Identity,java.nio.ByteBuffer>i - who to open the socket todeliverSocketToMe - the callback when the socket is openedoptions - options on how to open the socket (don't source route, encrypt etc) (may not be respected if layer cannot provide service)
public MessageRequestHandle<Identity,java.nio.ByteBuffer> sendMessage(Identity i,
java.nio.ByteBuffer m,
MessageCallback<Identity,java.nio.ByteBuffer> deliverAckToMe,
java.util.Map<java.lang.String,java.lang.Integer> options)
TransportLayer
sendMessage in interface TransportLayer<Identity,java.nio.ByteBuffer>i - the destinationm - the messagedeliverAckToMe - 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)
public void destroy()
destroy in interface Destructable
public void incomingSocket(P2PSocket<Identity> s)
throws java.io.IOException
TransportLayerCallback
incomingSocket in interface TransportLayerCallback<Identity,java.nio.ByteBuffer>s - the incoming socket
java.io.IOException
public void messageReceived(Identity i,
java.nio.ByteBuffer m,
java.util.Map<java.lang.String,java.lang.Integer> options)
throws java.io.IOException
TransportLayerCallback
messageReceived in interface TransportLayerCallback<Identity,java.nio.ByteBuffer>i - The node it is coming fromm - the messageoptions - describe how the message arrived (udp/tcp, encrypted etc)
java.io.IOException - if there is a problem decoding the message
|
Rice Pastry API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||