net.sf.juoserver.protocol
Class AbstractMessage

java.lang.Object
  extended by net.sf.juoserver.protocol.AbstractMessage
All Implemented Interfaces:
Serializable, Message
Direct Known Subclasses:
CharacterDraw, CharacterList, CharacterSelect, CharacterWarmode, ClientFeatures, ClientVersion, ClilocMessage, DeleteItem, DoubleClick, DragItem, DrawContainer, DrawGamePlayer, DropItem, GeneralInformation, GetPlayerStatus, LoginComplete, LoginConfirm, LoginReject, LoginRequest, LoginSeed, LookRequest, MegaClilocRequest, MegaClilocResponse, MovementAck, MovementReject, MoveRequest, ObjectInfo, ObjectRevision, OverallLightLevel, Paperdoll, PersonalLightLevel, PickUpItem, PingPong, SeasonalInformation, SelectServer, ServerConnect, ServerList, ServerLoginRequest, SkillLock, SkillUpdate, SpyOnClient, StatusBarInfo, UnicodeSpeech, UnicodeSpeechRequest, UpdatePlayer, WearItem

public abstract class AbstractMessage
extends Object
implements Message, Serializable

Base class for messages.

Messages can be sent by the client or the server, or both (e.g. ClientVersion).

Messages sent by clients (e.g. CharacterSelect) should:

Messages sent by the server (e.g. CharacterList) should: By creating a client message by following the above steps, the server is already able to receive that message.

It is however also necessary to provide the ability to process that client message, by adding a handler to the ControllerImpl class and thus letting it reply to the client message with a server message.

See Also:
Serialized Form

Field Summary
protected static int NO_CODE
           
static String UTF8
           
 
Constructor Summary
protected AbstractMessage(int code, int length)
          Builds a message from the code that identifies it.
 
Method Summary
 ByteBuffer encode()
          Encodes this message into a byte array packet.
abstract  boolean equals(Object obj)
           
 int getCode()
           
 int getLength()
           
 String getName()
           
abstract  int hashCode()
           
 boolean isCompressed()
          

Default value is true.

protected  ByteBuffer wrapContents(byte[] contents)
          Returns a new ByteBuffer wrapping the packet contents, excluding the first byte (the packet code).
protected  ByteBuffer wrapContents(int fromIndexInclusive, byte[] contents)
          Returns a new ByteBuffer wrapping the packet contents, starting from the specified index, inclusive.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8

public static final String UTF8
See Also:
Constant Field Values

NO_CODE

protected static final int NO_CODE
See Also:
Constant Field Values
Constructor Detail

AbstractMessage

protected AbstractMessage(int code,
                          int length)
Builds a message from the code that identifies it. This code is the first byte in the message packet.

Parameters:
code - message's identification code
Method Detail

encode

public ByteBuffer encode()
Description copied from interface: Message
Encodes this message into a byte array packet.

The array is wrapped in a byte buffer in order to let subclasses append their contents.

Specified by:
encode in interface Message
Returns:
the byte array representation (a.k.a. packet) of this message

isCompressed

public boolean isCompressed()

Default value is true.

Specified by:
isCompressed in interface Message
Returns:
true if and only if this message should be compressed when sent by the server

getCode

public final int getCode()
Specified by:
getCode in interface Message
Returns:
this message's code

getLength

public final int getLength()
Specified by:
getLength in interface Message
Returns:
this message's length in bytes

hashCode

public abstract int hashCode()
Overrides:
hashCode in class Object

equals

public abstract boolean equals(Object obj)
Overrides:
equals in class Object

getName

public final String getName()
Returns:
this message's name

wrapContents

protected final ByteBuffer wrapContents(byte[] contents)
Returns a new ByteBuffer wrapping the packet contents, excluding the first byte (the packet code).

Note that the returned buffer will be backed up by the provided array, therefore modifications to the buffer will change the array and vice versa.

Parameters:
contents - packet contents
Returns:
a new ByteBuffer wrapping the packet contents, excluding the first byte (the packet code)
See Also:
wrapContents(int, byte[])

wrapContents

protected final ByteBuffer wrapContents(int fromIndexInclusive,
                                        byte[] contents)
Returns a new ByteBuffer wrapping the packet contents, starting from the specified index, inclusive.

Note that the returned buffer will be backed up by the provided array, therefore modifications to the buffer will change the array and vice versa.

Parameters:
fromIndexInclusive - starting index where to start reading the contents, inclusive
contents - packet contents
Returns:
a new ByteBuffer wrapping the packet contents, excluding the first byte (the packet code)
See Also:
ByteBuffer.wrap(byte[], int, int)


Copyright © 2010-2012. All Rights Reserved.