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.socket
Class SocketBuffer

    java.lang.Object
      rice.pastry.socket.SocketBuffer

All Implemented Interfaces:
  RawMessageDelivery

    public class SocketBuffer

extends java.lang.Object
implements RawMessageDelivery

Holds 1 serialized message for receiving or sending. Has a growable buffer. Has specialized code for RouteMessage, Liveness Message, and byte arrays. This code is ugly and does too many things. However right now this is what we have. There are Several Different Constructors. Depending which one you use, different other methods will work. Look at the docs on the individual constructors for more info.

Author:
  Jeff Hoye

Field Summary
`static int` | `DEFAULT_BUFFER_SIZE` The initial buffer size (it is growable)

Constructor Summary
`SocketBuffer(byte[] output)` Just bytes (no real concept of a message.) This is for a) sourcerouting bytes b) for a usually a stream header for getResponse().
`SocketBuffer(byte[] input, SocketPastryNode spn)` When you expect to read a message.
`SocketBuffer(EpochInetSocketAddress address, SourceRoute path, PRawMessage msg)` This serializes UDP messages with the appropriate source route header.
`SocketBuffer(MessageDeserializer defaultDeserializer, SocketPastryNode spn)` Main Constructor for writing an object.
`SocketBuffer(PRawMessage rm)` Serializes a SourceRoute (don't know why this isn't done in the stream header serializer.
`SocketBuffer(SourceRoute path, int appId)` Used to initialize a TCP stream header.

Method Summary
`Message` | `deserialize(MessageDeserializer md)`
`int` | `getAddress()`
`java.nio.ByteBuffer` | `getBuffer()`
`byte[]` | `getBytes()`
`int` | `getInnermostAddress()`
`short` | `getInnermostType()`
`SendOptions` | `getOptions()`
`RouteMessage` | `getRouteMessage()`
`short` | `getType()`
`protected void` | `initialize(int size)`
`boolean` | `isRouteMessage()`
`void` | `serialize(PRawMessage msg, boolean reset)` Will grow the buffer as needed
`void` | `setType(short type)`
`java.lang.String` | `toString()`

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

Field Detail

### DEFAULT_BUFFER_SIZE

    public static final int DEFAULT_BUFFER_SIZE

  The initial buffer size (it is growable)

  See Also:
    Constant Field Values

Constructor Detail

### SocketBuffer

    public SocketBuffer(MessageDeserializer defaultDeserializer,
                        SocketPastryNode spn)

  Main Constructor for writing an object. The purpose of the defaultDeserializer is to handle reverse compatibility with JavaSerialization and the old method calls. If the code calls RouteMessage.unpack() instead of RouteMessage.unpack(Deserializer) then the defaultDeserializer is used.

  Parameters:
    `defaultDeserializer` -

### SocketBuffer

    public SocketBuffer(byte[] input,
                        SocketPastryNode spn)
                 throws java.io.IOException

  When you expect to read a message. This will deserialize the message header. Then you can call deserialize with an appropriate deserializer.

  Throws:
    `java.io.IOException`

### SocketBuffer

    public SocketBuffer(EpochInetSocketAddress address,
                        SourceRoute path,
                        PRawMessage msg)
                 throws java.io.IOException

  This serializes UDP messages with the appropriate source route header.

  Parameters:
    `address` - the local address
    `path` - the path to the destination
    `msg` - the message
  Throws:
    `java.io.IOException`

### SocketBuffer

    public SocketBuffer(SourceRoute path,
                        int appId)
                 throws java.io.IOException

  Used to initialize a TCP stream header. The counterpart reading of the header is found in SocketChannelRepeater.read()

  Parameters:
    `path` -
    `appId` -
  Throws:
    `java.io.IOException`

### SocketBuffer

    public SocketBuffer(byte[] output)

  Just bytes (no real concept of a message.) This is for a) sourcerouting bytes b) for a usually a stream header for getResponse(). TODO: The stream header version should probably use the one that is designed to initialize a TCP stream.

  Parameters:
    `output` -

### SocketBuffer

    public SocketBuffer(PRawMessage rm)
                 throws java.io.IOException

  Serializes a SourceRoute (don't know why this isn't done in the stream header serializer. Serializes a Message for getResponse() should probably use normal constructor.

  Parameters:
    `rm` -
    `logger` -
  Throws:
    `java.io.IOException`

Method Detail

### initialize

    protected void initialize(int size)

### isRouteMessage

    public boolean isRouteMessage()

### getOptions

    public SendOptions getOptions()

### getRouteMessage

    public RouteMessage getRouteMessage()

### serialize

    public void serialize(PRawMessage msg,
                          boolean reset)
                   throws java.io.IOException

  Will grow the buffer as needed

  Parameters:
    `msg` -
  Throws:
    `java.io.IOException`

### getBuffer

    public java.nio.ByteBuffer getBuffer()

### getBytes

    public byte[] getBytes()

### getAddress

    public int getAddress()

  Specified by:
    `getAddress` in interface `RawMessageDelivery`

### deserialize

    public Message deserialize(MessageDeserializer md)
                        throws java.io.IOException

  Specified by:
    `deserialize` in interface `RawMessageDelivery`
  Throws:
    `java.io.IOException`

### getInnermostType

    public short getInnermostType()

### getInnermostAddress

    public int getInnermostAddress()

### getType

    public short getType()

### setType

    public void setType(short type)

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

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.