networking.protocol
Class Message

java.lang.Object
  extended by networking.protocol.Message
All Implemented Interfaces:
java.io.Serializable

public class Message
extends java.lang.Object
implements java.io.Serializable

Message - this class represents a message, which can be sent and received through IO streams

See Also:
Serialized Form

Field Summary
static int ACCEPT
          ACCEPT message type constant - server accepts client connection
static int ACCEPT_FILE
          ACCEPT_FILE message type constant - new file was accepted by some client
static int ACCEPT_FILE_SENT
          ACCEPT_FILE_SENT message type constant - new file was accepted by client sent by clients
static int BROADCAST_SENT
          BROADCAST_SENT message type constant - broadcast message sent
static int BYE
          BYE message type constant - server or client has disconnected
static int CLIENT_LIST_CHANGED
          CLIENT_LIST_CHANGED message type constant - new client has connected or a client has disconnected
static int DEBAR
          DEBAR message type constant - leader debars enlisted clients sent to clients
static int DEBAR_SENT
          DEBAR_SENT message type constant - leader debars enlisted clients sent from leader
static int DISCONNECT
          DISCONNECT message type constant - master asks client or server to disconnect
static int FILE_DOWNLOAD_ERROR
          FILE_DOWNLOAD_ERROR message type constant - FileDownloadServer informs client about error
static int FILE_DOWNLOAD_OK
          FILE_DOWNLOAD_OK message type constant - client has succefully completed file download
static int FILE_DOWNLOAD_START
          FILE_DOWNLOAD_START message type constant - FileDownloadServer informs client about starting the file transfer
static int FILE_RECV
          FILE_RECV message type constant - client want to recieve file from server
static int FILE_SENT
          FILE_SENT message type constant - client want to send file to a list of clients
static int FILE_UPLOAD_OK
          FILE_UPLOAD_OK message type constant - client has succefully completed file upload
static int FILE_WAIT
          FILE_WAIT message type constant - FileDownloadServer waits while source file is being uploaded
static int HI_FILE
          HI_FILE message type constant - client request for connection with FileServer
static int HI_TALK
          HI message type constant - client request for connection
private  long m_code
          Code part of the message, the meaning of code depends on message's type
private  java.util.List m_list
          List of concerned objects or null
private  long m_long
          Long value part of the message, the meaning depends on message's type
private  java.lang.String m_str
          String part of the message, the meaning of string depends on message's type.
private  int m_type
          Type of the message
static int MESSAGE_SENT
          NEW_MESSAGE_SENT message type constant - a client sends new message to the list of recipients
static int NEW_FILE
          NEW_FILE message type constant - new file is sent by somebody sent to clients
static int NEW_MESSAGE
          NEW_MESSAGE message type constant - new message has arrived from other client
static int NONE
          NONE message type constant - no contents
static int REJECT
          REJECT message type constant - server rejects client connection
static int REJECT_FILE
          REJECT_FILE message type constant - new file was rejected by all clients
static int REJECT_FILE_SENT
          REJECT_FILE_SENT message type constant - new file was rejected by client sent by clients
static int TIMEOUT
          TIMEOUT message type constant - server or client time-out has elapsed
 
Constructor Summary
Message(int type)
          Construct new Message object
Message(int type, Client client, java.lang.String str)
          Construct new Message object
Message(int type, Client client, java.lang.String str, long code)
          Construct new Message object
Message(int type, java.util.List list, java.lang.String str)
          Construct new Message object
Message(int type, java.util.List list, java.lang.String str, long code)
          Construct new Message object
Message(int type, java.lang.String str)
          Construct new Message object
 
Method Summary
 Client getClient()
          Get client object from message - first object in clients list
 long getCode()
          Get code part of the message
 java.util.List getList()
          Get a list of concerned objects
 long getLong()
          Get long value part of the message
 java.lang.String getText()
          Get the text part of the message
 int getType()
          Get type of the message
static Message recv(java.io.InputStream in)
          Receive the message from an input stream
 void send(java.io.OutputStream out)
          Send the message to an output stream
 Message setCode(long code)
          Set code part of the message
 Message setLong(long longval)
          Set long value part of the message
 Message setType(int type)
          Set type of the message
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
NONE message type constant - no contents

See Also:
Constant Field Values

HI_TALK

public static final int HI_TALK
HI message type constant - client request for connection

See Also:
Constant Field Values

BYE

public static final int BYE
BYE message type constant - server or client has disconnected

See Also:
Constant Field Values

TIMEOUT

public static final int TIMEOUT
TIMEOUT message type constant - server or client time-out has elapsed

See Also:
Constant Field Values

CLIENT_LIST_CHANGED

public static final int CLIENT_LIST_CHANGED
CLIENT_LIST_CHANGED message type constant - new client has connected or a client has disconnected

See Also:
Constant Field Values

NEW_MESSAGE

public static final int NEW_MESSAGE
NEW_MESSAGE message type constant - new message has arrived from other client

See Also:
Constant Field Values

MESSAGE_SENT

public static final int MESSAGE_SENT
NEW_MESSAGE_SENT message type constant - a client sends new message to the list of recipients

See Also:
Constant Field Values

DISCONNECT

public static final int DISCONNECT
DISCONNECT message type constant - master asks client or server to disconnect

See Also:
Constant Field Values

REJECT

public static final int REJECT
REJECT message type constant - server rejects client connection

See Also:
Constant Field Values

ACCEPT

public static final int ACCEPT
ACCEPT message type constant - server accepts client connection

See Also:
Constant Field Values

DEBAR

public static final int DEBAR
DEBAR message type constant - leader debars enlisted clients sent to clients

See Also:
Constant Field Values

DEBAR_SENT

public static final int DEBAR_SENT
DEBAR_SENT message type constant - leader debars enlisted clients sent from leader

See Also:
Constant Field Values

BROADCAST_SENT

public static final int BROADCAST_SENT
BROADCAST_SENT message type constant - broadcast message sent

See Also:
Constant Field Values

HI_FILE

public static final int HI_FILE
HI_FILE message type constant - client request for connection with FileServer

See Also:
Constant Field Values

FILE_SENT

public static final int FILE_SENT
FILE_SENT message type constant - client want to send file to a list of clients

See Also:
Constant Field Values

NEW_FILE

public static final int NEW_FILE
NEW_FILE message type constant - new file is sent by somebody sent to clients

See Also:
Constant Field Values

ACCEPT_FILE

public static final int ACCEPT_FILE
ACCEPT_FILE message type constant - new file was accepted by some client

See Also:
Constant Field Values

REJECT_FILE

public static final int REJECT_FILE
REJECT_FILE message type constant - new file was rejected by all clients

See Also:
Constant Field Values

ACCEPT_FILE_SENT

public static final int ACCEPT_FILE_SENT
ACCEPT_FILE_SENT message type constant - new file was accepted by client sent by clients

See Also:
Constant Field Values

REJECT_FILE_SENT

public static final int REJECT_FILE_SENT
REJECT_FILE_SENT message type constant - new file was rejected by client sent by clients

See Also:
Constant Field Values

FILE_RECV

public static final int FILE_RECV
FILE_RECV message type constant - client want to recieve file from server

See Also:
Constant Field Values

FILE_UPLOAD_OK

public static final int FILE_UPLOAD_OK
FILE_UPLOAD_OK message type constant - client has succefully completed file upload

See Also:
Constant Field Values

FILE_DOWNLOAD_OK

public static final int FILE_DOWNLOAD_OK
FILE_DOWNLOAD_OK message type constant - client has succefully completed file download

See Also:
Constant Field Values

FILE_WAIT

public static final int FILE_WAIT
FILE_WAIT message type constant - FileDownloadServer waits while source file is being uploaded

See Also:
Constant Field Values

FILE_DOWNLOAD_START

public static final int FILE_DOWNLOAD_START
FILE_DOWNLOAD_START message type constant - FileDownloadServer informs client about starting the file transfer

See Also:
Constant Field Values

FILE_DOWNLOAD_ERROR

public static final int FILE_DOWNLOAD_ERROR
FILE_DOWNLOAD_ERROR message type constant - FileDownloadServer informs client about error

See Also:
Constant Field Values

m_type

private int m_type
Type of the message


m_list

private java.util.List m_list
List of concerned objects or null


m_str

private java.lang.String m_str
String part of the message, the meaning of string depends on message's type. Can be null


m_code

private long m_code
Code part of the message, the meaning of code depends on message's type


m_long

private long m_long
Long value part of the message, the meaning depends on message's type

Constructor Detail

Message

public Message(int type)
Construct new Message object

Parameters:
type - type

Message

public Message(int type,
               java.lang.String str)
Construct new Message object

Parameters:
type - type
str - text part of the message

Message

public Message(int type,
               Client client,
               java.lang.String str)
Construct new Message object

Parameters:
type - type
client - message's list of clients, containing only one element
str - text part of the message

Message

public Message(int type,
               java.util.List list,
               java.lang.String str)
Construct new Message object

Parameters:
type - type
list - list of clients
str - text part of the message

Message

public Message(int type,
               Client client,
               java.lang.String str,
               long code)
Construct new Message object

Parameters:
type - type
client - message's list of clients, containing only one element
str - text part of the message
code - code part of the message

Message

public Message(int type,
               java.util.List list,
               java.lang.String str,
               long code)
Construct new Message object

Parameters:
type - type
list - list of clients
str - text part of the message
code - code part of the message
Method Detail

recv

public static Message recv(java.io.InputStream in)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Receive the message from an input stream

Parameters:
in - input stream
Returns:
Message object
Throws:
java.io.IOException
java.lang.ClassNotFoundException

send

public void send(java.io.OutputStream out)
          throws java.io.IOException,
                 java.lang.ClassNotFoundException
Send the message to an output stream

Parameters:
out - output stream
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getClient

public final Client getClient()
Get client object from message - first object in clients list

Returns:
client object

getText

public final java.lang.String getText()
Get the text part of the message

Returns:
text part of the message

getList

public final java.util.List getList()
Get a list of concerned objects

Returns:
list of Client objects

getType

public final int getType()
Get type of the message

Returns:
type of the message

getCode

public final long getCode()
Get code part of the message

Returns:
code value

getLong

public final long getLong()
Get long value part of the message

Returns:
long value

setType

public final Message setType(int type)
Set type of the message

Parameters:
type - type of the message
Returns:
this message

setCode

public final Message setCode(long code)
Set code part of the message

Parameters:
code - code value
Returns:
this message

setLong

public final Message setLong(long longval)
Set long value part of the message

Parameters:
longval - long value
Returns:
this message

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2009 Alexey Veremenko. All rights reserved.