swpchat.server
Class ReceiverProtocolHandler

java.lang.Object
  |
  +--swpchat.server.ProtocolHandler
        |
        +--swpchat.server.ReceiverProtocolHandler
All Implemented Interfaces:
ChatTokens, ControlTokens, NotificationTokens, ReceiverServer, ReceiverTokens, SenderReceiverTokens

public class ReceiverProtocolHandler
extends ProtocolHandler
implements ReceiverServer, ReceiverTokens, NotificationTokens

Used for the Receiver to pass on Messages to the Client

Author:
Buchholz Kespe

Field Summary
private  ChannelCollection channelCollection
           
private  java.net.Socket clientSocket
           
(package private)  java.lang.String CLS
           
private  boolean connected
           
private  ConnectedClientCollection connectedClientCollection
           
private  java.lang.String nick
           
private  NickNameCollection nickCollection
           
private  java.io.BufferedWriter ostream
           
private  java.lang.String sessionKey
           
 
Fields inherited from interface swpchat.protocol.ReceiverTokens
STR_LOGIN, STR_LOGIN_BEGIN, STR_LOGIN_RE_BEGIN, STR_LOGOUT, STR_LOGOUT_BEGIN, STR_LOGOUT_RE_BEGIN, STR_PLAY, STR_PLAY_BEGIN, STR_RECEIVE, STR_RECEIVE_BEGIN, STR_RECEIVE_USERINFO, STR_TOPICCHANGED, STR_WHISPRECEIVE
 
Fields inherited from interface swpchat.protocol.ChatTokens
CHAR_ARG_SEP, CHAR_MSG_END, CHAR_MSG_EOL, CHAR_QUOTE, CHAR_STRING_DELIMITER, STR_ARG_SEP, STR_AUTHORIZE, STR_MSG_END, STR_MSG_EOL, STR_NEG_ARG, STR_NEGATIVE, STR_POS_ARG, STR_POSITIVE, STR_QUOTE, STR_REPLY, STR_STRING_DELIMITER, STR_WAIT
 
Fields inherited from interface swpchat.protocol.NotificationTokens
STR_STATE_JOINED, STR_STATE_LEFT, STR_STATE_OFFLINE, STR_STATE_ONLINE
 
Fields inherited from interface swpchat.protocol.SenderReceiverTokens
STR_JOIN, STR_JOINPASSWD, STR_LEAVE, STR_OFF, STR_ON, STR_PLAY, STR_PLAY_BEGIN, STR_PLAY_RE_BEGIN, STR_RECEIVE, STR_RECEIVE_BEGIN, STR_RECEIVE_USERINFO, STR_REQUEST_USERINFO, STR_SEND, STR_SEND_BEGIN, STR_SEND_RE_BEGIN, STR_SETTOPIC, STR_SETTOPIC_BEGIN, STR_SHIP, STR_SHIP_BEGIN, STR_TOPICCHANGED, STR_WHISPER, STR_WHISPRECEIVE
 
Fields inherited from interface swpchat.protocol.ControlTokens
STR_EMOTION, STR_LOGIN, STR_LOGIN_BEGIN, STR_LOGIN_RE_BEGIN, STR_LOGOUT, STR_LOGOUT_BEGIN, STR_LOGOUT_RE_BEGIN, STR_MEMBER, STR_MEMBER_BEGIN, STR_MEMBER_INFO, STR_MEMBER_JOIN, STR_MEMBER_LEAVE, STR_MEMBER_SHIP, STR_NEW_CHANNEL, STR_NOTIFICATION, STR_NOTIFICATION_BEGIN, STR_NOTIFY_REQUEST, STR_REMOVE_CHANNEL, STR_RENAME_CHANNEL, STR_REQUEST_IP, STR_REQUST_IP_RE_BEGIN, STR_SEND_USERINFO, STR_SET_NICK, STR_SET_NICK_BEGIN, STR_SET_NICK_RE_BEGIN, STR_SET_SESSIONKEY, STR_STOP_NOTIFICATION, STR_TELEPHONE_REQUEST
 
Constructor Summary
ReceiverProtocolHandler(ChannelCollection channelCollection, NickNameCollection nickCollection, ConnectedClientCollection connectedClientCollection)
          Constructor
 
Method Summary
 void disconnect()
           
 void emotion(java.lang.String channel, java.lang.String from, java.lang.String target, java.lang.String emo)
          emotion-method invoked by ClientConnection, responsible for transferring emotion-message
 java.lang.String getNick()
           
 void play(java.lang.String channel, java.lang.String from, java.lang.String audiokey)
          play-method invoked by ClientConnection, responsible for transferring play:: - message
 void receive(java.lang.String channel, java.lang.String from, java.lang.String message)
          receive-method invoked by ClientConnection, responsible for transferring messages to this listening client
 void receiveUserInfo(java.lang.String nickName, java.lang.String strInfo)
          receiveUserInfo invoked by ClientConnection, responsible for sending back receiveUserInfo:::: - message
 void serve(java.net.Socket clientSocket, ClientConnection clientConnection, java.io.InputStream inputStream)
          serves the client: passes on Messages from the server to the client
 void shipReceive(java.lang.String channel, java.lang.String from, java.lang.String receiver, boolean status)
          shipReceive-method invoked by ClientConnection, responsible for transferring messages to this listening client
 void topicChanged(java.lang.String channel, java.lang.String from, java.lang.String topic)
          topicChanged-method invoked by ClientConnection, sends topicchanged:channel:from:topic.
 void whispreceive(java.lang.String channel, java.lang.String from, java.lang.String message)
          whispreceive-method invoked by ClientConnection, responsible for transferring whispered messages to this listening client
 
Methods inherited from class swpchat.server.ProtocolHandler
isEmotion, isJoin, isJoinPasswd, isLeave, isLogin, isLogout, isMemberRequest, isNewChannel, isNewChannelReply, isNotificationRequest, isPlay, isPutShip, isRemoveChannel, isRemoveChannelReply, isRenameChannel, isRenameChannelReply, isRequestIPAddress, isRequestIPAddressReply, isRequestUserInfo, isSend, isSendTelephoneRequest, isSendTelephoneRequestReply, isSendUserInfo, isSetNick, isSetSessionKey, isSetTopic, isStopNotification, isWhisper, readCommand, reply, send, send, send, send, send, writeLine
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CLS

final java.lang.String CLS

ostream

private java.io.BufferedWriter ostream

channelCollection

private ChannelCollection channelCollection

nickCollection

private NickNameCollection nickCollection

connectedClientCollection

private ConnectedClientCollection connectedClientCollection

sessionKey

private java.lang.String sessionKey

nick

private java.lang.String nick

clientSocket

private java.net.Socket clientSocket

connected

private boolean connected
Constructor Detail

ReceiverProtocolHandler

public ReceiverProtocolHandler(ChannelCollection channelCollection,
                               NickNameCollection nickCollection,
                               ConnectedClientCollection connectedClientCollection)
Constructor
Parameters:
channelCollection, - Collection of all possible Channels
nickCollection, - Collection of all Nicknames
connectedClientCollection, - Collection of all connected Clients
Method Detail

serve

public void serve(java.net.Socket clientSocket,
                  ClientConnection clientConnection,
                  java.io.InputStream inputStream)
           throws TimeoutException,
                  java.io.IOException,
                  java.security.InvalidParameterException
serves the client: passes on Messages from the server to the client
Specified by:
serve in interface ReceiverServer
Overrides:
serve in class ProtocolHandler
Parameters:
clientSocket - Socket used for communication between client and server .
Throws:
TimeoutException - thrown if connection to the client is lost or too slow.
java.io.IOException - thrown for any I/O error.
java.security.InvalidParameterException - possibly useful

receive

public void receive(java.lang.String channel,
                    java.lang.String from,
                    java.lang.String message)
             throws java.io.IOException,
                    java.security.InvalidParameterException
receive-method invoked by ClientConnection, responsible for transferring messages to this listening client
Specified by:
receive in interface ReceiverServer
Following copied from interface: swpchat.protocol.ReceiverServer
Parameters:
from - The nickname of the sender.
message - The actual message to be sent. //X<
Throws:
java.io.IOException - General I/O-Exceptions that may have been raised by lower levels.
java.security.InvalidParameterException - Thrown if any parameter is null. //X>

whispreceive

public void whispreceive(java.lang.String channel,
                         java.lang.String from,
                         java.lang.String message)
                  throws java.io.IOException,
                         java.security.InvalidParameterException
whispreceive-method invoked by ClientConnection, responsible for transferring whispered messages to this listening client
Specified by:
whispreceive in interface ReceiverServer
Following copied from interface: swpchat.protocol.ReceiverServer
Parameters:
from - The nickname of the sender.
message - The actual message to be sent. //X<
Throws:
java.io.IOException - General I/O-Exceptions that may have been raised by lower levels.
java.security.InvalidParameterException - Thrown if any parameter is null. //X>

shipReceive

public void shipReceive(java.lang.String channel,
                        java.lang.String from,
                        java.lang.String receiver,
                        boolean status)
                 throws java.io.IOException,
                        java.security.InvalidParameterException
shipReceive-method invoked by ClientConnection, responsible for transferring messages to this listening client
Specified by:
shipReceive in interface ReceiverServer

topicChanged

public void topicChanged(java.lang.String channel,
                         java.lang.String from,
                         java.lang.String topic)
                  throws java.io.IOException,
                         java.security.InvalidParameterException
topicChanged-method invoked by ClientConnection, sends topicchanged:channel:from:topic. to client.
Specified by:
topicChanged in interface ReceiverServer
Parameters:
from - the sender nickname
topic - the new topic

play

public void play(java.lang.String channel,
                 java.lang.String from,
                 java.lang.String audiokey)
          throws java.io.IOException,
                 java.security.InvalidParameterException
play-method invoked by ClientConnection, responsible for transferring play:: - message
Specified by:
play in interface ReceiverServer
Parameters:
from - the sender nickname
audiokey - the associated audiokey

emotion

public void emotion(java.lang.String channel,
                    java.lang.String from,
                    java.lang.String target,
                    java.lang.String emo)
             throws java.io.IOException,
                    java.security.InvalidParameterException
emotion-method invoked by ClientConnection, responsible for transferring emotion-message
Specified by:
emotion in interface ReceiverServer
Parameters:
channel - the channel
from - the sender nickname
target - the target of the emotion
emo - the emotion

receiveUserInfo

public void receiveUserInfo(java.lang.String nickName,
                            java.lang.String strInfo)
receiveUserInfo invoked by ClientConnection, responsible for sending back receiveUserInfo:::: - message
Specified by:
receiveUserInfo in interface ReceiverServer
Parameters:
nickName - the nickName of the user the information is wanted from
strInfo - the userInfo

disconnect

public void disconnect()
Overrides:
disconnect in class ProtocolHandler

getNick

public java.lang.String getNick()
Specified by:
getNick in interface ReceiverServer