uk.ac.rdg.resc.jstyx.messages
Class RreadMessage

java.lang.Object
  extended by uk.ac.rdg.resc.jstyx.messages.StyxMessage
      extended by uk.ac.rdg.resc.jstyx.messages.RreadMessage

public class RreadMessage
extends StyxMessage

Message returned by the server in response to a TreadMessage

Author:
Jon Blower $Revision: 507 $ $Date: 2005-12-01 08:21:56 +0000 (Thu, 01 Dec 2005) $ $Log$ Revision 1.18 2005/12/01 08:21:56 jonblower Fixed javadoc comments Revision 1.17 2005/11/03 21:47:17 jonblower getElements() and toFriendlyString() now use getData() Revision 1.16 2005/11/03 17:09:27 jonblower Created more efficient RreadMessage that involves less copying of buffers (still reliable) Revision 1.15 2005/11/03 16:02:54 jonblower Created simplified version (less efficient, more reliable) Revision 1.13 2005/09/02 16:52:38 jonblower Fixed bugs that caused message payload to be printed as empty string Revision 1.11 2005/05/10 19:17:54 jonblower Added dispose() method Revision 1.10 2005/05/10 08:02:06 jonblower Changes related to implementing MonitoredFileOnDisk Revision 1.9 2005/03/22 17:48:27 jonblower Removed debug code that tracked ByteBuffer allocation Revision 1.8 2005/03/21 17:57:10 jonblower Trying to fix ByteBuffer leak in SGS server Revision 1.7 2005/03/18 13:56:00 jonblower Improved freeing of ByteBuffers, and bug fixes Revision 1.6 2005/03/16 22:16:43 jonblower Added Styx Grid Service classes to core module Revision 1.5 2005/03/16 17:56:22 jonblower Replaced use of java.nio.ByteBuffer with MINA's ByteBuffer to minimise copying of buffers Revision 1.4 2005/03/15 09:01:48 jonblower Message type now stored as short, not int Revision 1.3 2005/03/11 14:02:15 jonblower Merged MINA-Test_20059309 into main line of development Revision 1.2.2.2 2005/03/11 12:30:45 jonblower Changed so that message payloads are always ints, not longs Revision 1.2.2.1 2005/03/10 11:50:59 jonblower Changed to fit with MINA framework Revision 1.2 2005/02/24 07:44:43 jonblower Added getFriendlyString() Revision 1.1.1.1 2005/02/16 18:58:27 jonblower Initial import

Field Summary
 
Fields inherited from class uk.ac.rdg.resc.jstyx.messages.StyxMessage
buf, length, lock, name, tag, type
 
Constructor Summary
RreadMessage(byte[] bytes)
          Creates an RreadMessage from the given byte array
RreadMessage(byte[] bytes, int pos, int count)
          Creates an RreadMessage from the given byte array.
RreadMessage(org.apache.mina.common.ByteBuffer data)
          Creates an RreadMessage from the given org.apache.mina.common.ByteBuffer.
RreadMessage(int length, short type, int tag)
          Creates a new RversionMessage
 
Method Summary
protected  void decodeBody(StyxBuffer buf)
          Called when a complete message has arrived; signals that we are ready to interpret the raw bytes in the buffer and turn them into meaningful information.
 void dispose()
          This is called after the message has been sent (in StyxServerProtocolHandler.messageSent().
protected  void encodeBody(StyxBuffer buf)
          Writes the message into the given StyxBuffer.
 int getCount()
           
 org.apache.mina.common.ByteBuffer getData()
           
protected  java.lang.String getElements()
           
 java.lang.String toFriendlyString()
           
 
Methods inherited from class uk.ac.rdg.resc.jstyx.messages.StyxMessage
createStyxMessage, encode, getBuffer, getFid, getLength, getName, getTag, getType, readBytesFrom, setTag, toString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RreadMessage

public RreadMessage(int length,
                    short type,
                    int tag)
Creates a new RversionMessage

Parameters:
length - The total length of the message (including all header info)
type - The type of the message (a number between 100 and 127)
tag - The tag that identifies this message

RreadMessage

public RreadMessage(byte[] bytes)
Creates an RreadMessage from the given byte array


RreadMessage

public RreadMessage(byte[] bytes,
                    int pos,
                    int count)
Creates an RreadMessage from the given byte array. This will return count bytes, starting at position pos in the given array

Throws:
java.lang.IllegalArgumentException - if pos + count > bytes.length

RreadMessage

public RreadMessage(org.apache.mina.common.ByteBuffer data)
Creates an RreadMessage from the given org.apache.mina.common.ByteBuffer. The position and limit of the buffer must be set correctly. This method will not acquire() or release() the buffer: the buffer will be released automatically when the data are written to the network. Users of this constructor therefore should not release the buffer after using this constructor otherwise the data will no longer be valid.

Method Detail

decodeBody

protected final void decodeBody(StyxBuffer buf)
                         throws org.apache.mina.protocol.ProtocolViolationException
Description copied from class: StyxMessage
Called when a complete message has arrived; signals that we are ready to interpret the raw bytes in the buffer and turn them into meaningful information. Subclasses should make sure that the buffer is no longer needed once this method has finished, as the underlying buffer will be reused.

Specified by:
decodeBody in class StyxMessage
Throws:
org.apache.mina.protocol.ProtocolViolationException - if the payload of the message is more than Integer.MAX_VALUE

encodeBody

protected final void encodeBody(StyxBuffer buf)
Writes the message into the given StyxBuffer.

Specified by:
encodeBody in class StyxMessage

getData

public org.apache.mina.common.ByteBuffer getData()
Returns:
the data contained in this message as a MINA ByteBuffer. Makes sure that the position and limit of the buffer are set correctly

getCount

public int getCount()
Returns:
the number of bytes returned in the message (i.e. the payload size)

dispose

public void dispose()
This is called after the message has been sent (in StyxServerProtocolHandler.messageSent(). This releases the ByteBuffer holding the payload of the message.

Overrides:
dispose in class StyxMessage

getElements

protected java.lang.String getElements()
Specified by:
getElements in class StyxMessage
Returns:
the body elements of this message as a string

toFriendlyString

public java.lang.String toFriendlyString()
Overrides:
toFriendlyString in class StyxMessage
Returns:
a human-readable string that displays the contents of the message, without the header info. This default implementation simply calls this.getElements(): subclasses should override this behaviour


Copyright © 2004-2006 Reading e-Science Centre. All Rights Reserved.