swpchat.server
Class ClientConnection

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--swpchat.server.ClientConnection
All Implemented Interfaces:
ChannelListener, ChatTokens, ListenerBase, ProtocolTokens, java.lang.Runnable

public class ClientConnection
extends java.lang.Thread
implements ProtocolTokens, ChannelListener

This class embeds the protocol handling class into the server.

Author:
Ostwald, Woerzberger

Field Summary
protected  ChannelCollection channelCollection
           
(package private) static java.lang.String CLS
           
protected  ConnectedClientCollection connectedClientCollection
           
protected  ControlServer controlHandler
           
protected  ProtocolHandler handlerTmp
           
private  java.io.InputStream inputStream
           
protected  NickNameCollection nickCollection
           
protected  ReceiverServer receiverHandler
           
protected  SenderServer senderHandler
           
protected  java.net.Socket socket
           
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Fields inherited from interface swpchat.protocol.ProtocolTokens
STR_CONTROL, STR_CONTROL_PROTOCOL_ID, STR_FILE_SEND, STR_FILE_SEND_PROTOCOL_ID, STR_PROTOCOL, STR_PROTOCOL_ID_BEGIN, STR_RECEIVER, STR_RECEIVER_PROTOCOL_ID, STR_SENDER, STR_SENDER_PROTOCOL_ID
 
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
 
Constructor Summary
ClientConnection(ChannelCollection channelCollection, NickNameCollection nickCollection, ConnectedClientCollection connectedClientCollection, java.net.Socket socket)
          constructor maps the given parameters channelCollection to the local ChannelCollection and the tempsock to the socket we use in this context
 
Method Summary
 void disconnect()
           
 void emotion(java.lang.String channel, java.lang.String from, java.lang.String target, java.lang.String emo)
          method to send emotion
private  ProtocolHandler getCorrectHandler(java.net.Socket socket)
          get matching handler depending on what Protocol ID is sent
 java.lang.String getIdentifier()
          Implementation of the method declared in ListenerBase to support the interface ChannelListener.
 java.lang.String getNickName(boolean sender)
           
 void notify(java.lang.String nick, java.lang.String state, java.lang.String channels)
          Notify ClientConnection that 'nick' assumed 'state' concerning 'channels'.
 void play(java.lang.String channel, java.lang.String from, java.lang.String audioKey)
          method to invoke the playing procedure
 void receive(java.lang.String channel, java.lang.String from, java.lang.String message)
          method to invoke the receiving procedure
 void receiveUserInfo(java.lang.String nickName, java.lang.String strInfo)
          send back userInfo of the given nickName
 void run()
          overwrites run-method: open new ProtocolHandler for Client and call upon serve-method
 void sendControlMessage(java.lang.String control, java.lang.String message1, java.lang.String message2)
          sends a control message to ControlProtocolHandler
 void sendRequestMessage(java.lang.String request, java.lang.String info1, java.lang.String info2, java.lang.String info3)
          sends a request message to ControlProtocolHandler
 void ship(java.lang.String channel, java.lang.String from, java.lang.String receiver, boolean status)
          method ship is used for shiping
 void topicChanged(java.lang.String channel, java.lang.String from, java.lang.String topic)
          method to pass topicChanged
 void whispreceive(java.lang.String channel, java.lang.String from, java.lang.String message)
          method to invoke the whisper-receiving procedure
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLS

static final java.lang.String CLS

handlerTmp

protected ProtocolHandler handlerTmp

receiverHandler

protected ReceiverServer receiverHandler

senderHandler

protected SenderServer senderHandler

controlHandler

protected ControlServer controlHandler

socket

protected java.net.Socket socket

channelCollection

protected ChannelCollection channelCollection

nickCollection

protected NickNameCollection nickCollection

connectedClientCollection

protected ConnectedClientCollection connectedClientCollection

inputStream

private java.io.InputStream inputStream
Constructor Detail

ClientConnection

public ClientConnection(ChannelCollection channelCollection,
                        NickNameCollection nickCollection,
                        ConnectedClientCollection connectedClientCollection,
                        java.net.Socket socket)
constructor maps the given parameters channelCollection to the local ChannelCollection and the tempsock to the socket we use in this context
Parameters:
channelCollection, - nickCollection, connectedClientCollection, socket
Method Detail

run

public void run()
overwrites run-method: open new ProtocolHandler for Client and call upon serve-method
Overrides:
run in class java.lang.Thread

receive

public void receive(java.lang.String channel,
                    java.lang.String from,
                    java.lang.String message)
method to invoke the receiving procedure
Specified by:
receive in interface ChannelListener
Parameters:
channel - the Channel in which the message should be distributed
from - the client's nick, which is sending
message - the message to receive

whispreceive

public void whispreceive(java.lang.String channel,
                         java.lang.String from,
                         java.lang.String message)
method to invoke the whisper-receiving procedure
Specified by:
whispreceive in interface ChannelListener
Parameters:
channel - the Channel in which the message should be distributed
from - the client's nick, which is whispering
message - the message to receive

ship

public void ship(java.lang.String channel,
                 java.lang.String from,
                 java.lang.String receiver,
                 boolean status)
method ship is used for shiping
Specified by:
ship in interface ChannelListener
Parameters:
channel - the Channel in which the message should be distributed
from - the client's nick, which is sending
message - the message to receive
status - on/off

topicChanged

public void topicChanged(java.lang.String channel,
                         java.lang.String from,
                         java.lang.String topic)
method to pass topicChanged
Specified by:
topicChanged in interface ChannelListener
Parameters:
channel - the channel which distributes the topicChanged command
from - the client's nick, who changed the topic
audioKey - the topic

play

public void play(java.lang.String channel,
                 java.lang.String from,
                 java.lang.String audioKey)
method to invoke the playing procedure
Specified by:
play in interface ChannelListener
Parameters:
channel - the channel which distributes the play command
from - the client's nick, which is making noise
audioKey - the audio-file's associated audioKey

emotion

public void emotion(java.lang.String channel,
                    java.lang.String from,
                    java.lang.String target,
                    java.lang.String emo)
method to send emotion
Specified by:
emotion in interface ChannelListener
Parameters:
channel - the channel which distributes the play command
from - the client's nick
target - the target of the emotion
emo - the emotion to be send

receiveUserInfo

public void receiveUserInfo(java.lang.String nickName,
                            java.lang.String strInfo)
send back userInfo of the given nickName
Parameters:
nickName - the nickName
strInfo - the userInfo as a string

notify

public void notify(java.lang.String nick,
                   java.lang.String state,
                   java.lang.String channels)
Notify ClientConnection that 'nick' assumed 'state' concerning 'channels'. Example: 'nick' is NotificationTokens.STR_STATE_ONLINE and joined some channels, whereas channels contains a list of the channels simply divided by ';'s.
Parameters:
nick - String specifying the nickname of the concerning the message
state - String specifying the state 'nick' assumed. The valid states can be found in NotificationTokens.
channels - String specifying the channels joined or left devided by ';'s. Example: 'nick' joined 'test' and 'swp' up to now. Then channels can be "test;swp".

sendControlMessage

public void sendControlMessage(java.lang.String control,
                               java.lang.String message1,
                               java.lang.String message2)
sends a control message to ControlProtocolHandler
Parameters:
control - is the {@java.lang.String} that identifys the command to do in the ControlProtocolHandler
message1 - is a {@java.lang.String} specifying part1 of message
message2 - is a {@java.lang.String} specifying part2 of message

sendRequestMessage

public void sendRequestMessage(java.lang.String request,
                               java.lang.String info1,
                               java.lang.String info2,
                               java.lang.String info3)
sends a request message to ControlProtocolHandler
Parameters:
control - is the {@java.lang.String} that identifys the request to do in the ControlProtocolHandler
info1 - is a {@java.lang.String} specifying part1 of message
info2 - is a {@java.lang.String} specifying part2 of message
info3 - is a {@java.lang.String} specifying part3 of message

getCorrectHandler

private ProtocolHandler getCorrectHandler(java.net.Socket socket)
                                   throws java.net.ProtocolException
get matching handler depending on what Protocol ID is sent
Parameters:
socket - the socket that contains the input stream with the "protocolMsg"
Returns:
a handler

disconnect

public void disconnect()

getNickName

public java.lang.String getNickName(boolean sender)

getIdentifier

public java.lang.String getIdentifier()
Implementation of the method declared in ListenerBase to support the interface ChannelListener.
Specified by:
getIdentifier in interface ListenerBase
Following copied from interface: swpchat.server.ListenerBase
Returns:
a unique ID. So the sessionKey is a perfect candidate for this.