aigames.soccer.application
Class MessageSender

java.lang.Object
  extended byaigames.soccer.application.MessageSender

public class MessageSender
extends java.lang.Object

This is a helper class used to send messages to users. It maintains confirmation mechanism and unique message ids.

Version:
$Id: MessageSender.java,v 1.19 2004/05/08 21:55:26 mwerla Exp $

Constructor Summary
MessageSender(Server server)
          Constructo which sets server that will be used to send messages.
 
Method Summary
 boolean areUnconfirmedMessages()
          Checks if there are unconfirmed messages.
 void checkConfirmationTimeouts()
          Checks message confirmation timeouts, and resend messages if needed.
 void clearUnconfirmedMessages()
          Clears all unconfirmed messages.
 void forwardIncoming(org.dom4j.Document message, UserId userId)
          Forwards incoming message to other user.
 int getCounter()
          Returns message id counter.
 void sendAccepted(Message message)
          Sends accepted message.
 void sendGameOver(java.lang.String winner, UserId userId)
          Sends game over message.
 void sendGameParameters(UserId userId, int width, int height, int goal, int side, boolean begin)
          Sends game parameters to given user.
 void sendLogGameOver(java.lang.String winner, UserId id)
          Sends game over message as log message.
 void sendLogMove(Move move, UserId id, java.util.Date date)
          Sends move message as log message.
 void sendRefused(Message message, java.lang.String reason)
          Sends refused message to given user.
 void sendWithConfirmation(UserId userId, org.dom4j.Document messageToSend)
          Sends message and recods it to await for its confirmation.
 void setMessageConfirmation(Message confirmationMessage)
          Confirms message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageSender

public MessageSender(Server server)
Constructo which sets server that will be used to send messages.

Parameters:
server - Server to set.
Method Detail

getCounter

public int getCounter()
Returns message id counter.

Returns:
Message id counter.

sendGameParameters

public void sendGameParameters(UserId userId,
                               int width,
                               int height,
                               int goal,
                               int side,
                               boolean begin)
Sends game parameters to given user.

Parameters:
userId - User id.
width - Field width.
height - Field height.
goal - Goal height.
side - Attack side.
begin - True if user starts the game.

sendRefused

public void sendRefused(Message message,
                        java.lang.String reason)
Sends refused message to given user.

Parameters:
message - Message that is refused.
reason - Refuesd reason.

sendAccepted

public void sendAccepted(Message message)
Sends accepted message.

Parameters:
message - Message that is accepted.

sendGameOver

public void sendGameOver(java.lang.String winner,
                         UserId userId)
Sends game over message.

Parameters:
winner - Name of the winner.
userId - User that should receive this message.

checkConfirmationTimeouts

public void checkConfirmationTimeouts()
Checks message confirmation timeouts, and resend messages if needed.


setMessageConfirmation

public void setMessageConfirmation(Message confirmationMessage)
Confirms message.

Parameters:
confirmationMessage - Message confirmation.

forwardIncoming

public void forwardIncoming(org.dom4j.Document message,
                            UserId userId)
Forwards incoming message to other user.

Parameters:
message - Message that should be forwarded.
userId - User that shoud recieve the message.

sendWithConfirmation

public void sendWithConfirmation(UserId userId,
                                 org.dom4j.Document messageToSend)
Sends message and recods it to await for its confirmation.

Parameters:
userId - User that shoud recieve the message.
messageToSend - Message that should be sent.

areUnconfirmedMessages

public boolean areUnconfirmedMessages()
Checks if there are unconfirmed messages.

Returns:
True if there are unconfirmed messages, otherwise false.

clearUnconfirmedMessages

public void clearUnconfirmedMessages()
Clears all unconfirmed messages.


sendLogGameOver

public void sendLogGameOver(java.lang.String winner,
                            UserId id)
Sends game over message as log message.

Parameters:
winner - Winner name.
id - User that shoud recieve the message.

sendLogMove

public void sendLogMove(Move move,
                        UserId id,
                        java.util.Date date)
Sends move message as log message.

Parameters:
move - Move to be sent.
id - User that shoud recieve the message.
date - Date at which move was made.


Copyright © 2001-2004 MoMaT & MWe Team. All Rights Reserved.