com.web_visage.ichat
Class IChatServiceBot

java.lang.Object
  extended by com.web_visage.ichat.IChatServiceBot
All Implemented Interfaces:
ConnectMessageListener, DisconnectMessageListener, RefreshMessageListener, RenameMessageListener, StatusMessageListener

public class IChatServiceBot
extends java.lang.Object
implements RefreshMessageListener, DisconnectMessageListener, ConnectMessageListener, RenameMessageListener, StatusMessageListener

iChat service bot framework.

Implements basic iChat bot operations (such as connect, disconnect, refresh etc.) and provides subscription-based possibility to handle all kind of messages received during the session.

The general iChat client lifecycle looks like this:

TODO add lines tracking

Author:
K.Baturytski

Constructor Summary
IChatServiceBot(IChatBotProperties aProperties, IChatMessageFactory messageFactory)
          Constructor.
 
Method Summary
 void addAlertMessageListener(AlertMessageListener aListener)
          Registers the "alert" message listener.
 void addBoardMessageListener(BoardMessageListener aListener)
          Registers the "board" message listener.
 void addBroadcastMessageListener(BroadcastMessageListener aListener)
          Registers the private broadcast message listener.
 void addConnectListener(ConnectListener aListener)
          Registers connect event listener.
 void addConnectMessageListener(ConnectMessageListener aListener)
          Registers connect message listener.
 void addCreateLineMessageListener(CreateLineMessageListener aListener)
          Registers the "create line" message listener.
 void addCreateMessageListener(CreateMessageListener aListener)
          Registers create message listener.
 void addDisconnectListener(DisconnectListener aListener)
          Registers disconnect event listener.
 void addDisconnectMessageListener(DisconnectMessageListener aListener)
          Registers disconnect message listener.
 void addMeMessageListener(MeMessageListener aListener)
          Registers the "me" message listener.
 void addPrivateMessageListener(PrivateMessageListener aListener)
          Registers the private message listener.
 void addPublicMessageListener(PublicMessageListener aListener)
          Registers public message listener.
 void addReceivedMessageListener(ReceivedMessageListener aListener)
          Registers the "received" message listener.
 void addRefreshBoardMessageListener(RefreshBoardMessageListener aListener)
          Registers the "refresh board" message listener.
 void addRefreshMessageListener(RefreshMessageListener aListener)
          Registers refresh message listener.
 void addRenameMessageListener(RenameMessageListener aListener)
          Registers disconnect message listener.
 void addShutdownListener(ShutdownListener aListener)
          Registers disconnect event listener.
 void addStatusMessageListener(StatusMessageListener aListener)
          Registers the "status" message listener.
 void addStatusReqMesageListener(StatusReqMessageListener aListener)
          Registers STATUS message listener.
 void connect()
          Connects to the iChat server specified in the properties.
 void disconnect()
          Disconnects the bot from a server.
 java.util.List getAlertMessageListeners()
          Returns the alertMessageListeners.
 java.util.List getBoardMessageListeners()
          Returns the boardMessageListeners.
 java.util.List getBroadcastMessageListeners()
          Returns the private broadcast message listeners.
 java.util.List getCreateLineMessageListeners()
          Returns the createLineMessageListeners.
 java.util.List getCreateMessageListeners()
          Returns the createMessageListeners.
 java.util.List getMeMessageListeners()
          Returns the meMessageListeners.
 int getMessageId()
          Generates message id.
 IChatBotProperties getProperties()
           
 java.util.List getReceivedMessageListeners()
          Returns the receivedMessageListeners.
 java.util.List getRefreshBoardMessageListeners()
          Returns the refreshBoardMessageListeners.
 IChatSender getSender()
          Returns sender object based on a properties values.
 java.util.List getStatusMessageListeners()
          Returns the statusMessageListeners.
 IChatUserList getUserList()
          Returns the userList.
 java.util.Map getUsers()
          Returns the current user list map.
 boolean isConnected()
          Checks whether the bot is connected to a server.
 boolean isConnecting()
          Checks whether the bot is being connecting.
 boolean isDisconnected()
          Checks whether the bot is disconnected.
 boolean isDisconnecting()
          Checks whether the bot is being disconnected.
 boolean isOnline()
          Checks whether the bot is online.
 boolean isShuttingDown()
          Checks whether the bot is being shut down.
 void processConnectMessage(IChatConnectMessage aMessage)
          Adds a user to the user list and sends him a refresh message.
 void processDisconnectMessage(IChatDisconnectMessage aMessage, IChatUserInfo aUserInfo)
          Handles the DISCONNECT message.
 void processRefreshMessage(IChatRefreshMessage aMessage)
          Handle REFRESH message
 void processRenameMessage(IChatRenameMessage aMessage, java.lang.String anOldNickname)
          Handles rename message.
 void processStatusMessage(IChatStatusMessage aMessage)
          Handles the iChat "status" message.
 void removeAlertMessageListener(AlertMessageListener aListener)
          Unregisters the "alert" message listener.
 void removeBoardMessageListener(BoardMessageListener aListener)
          Unregisters the "board" message listener.
 void removeBroadcastMessageListener(BroadcastMessageListener aListener)
          Unregisters the private broadcast message listener.
 void removeConnectListener(ConnectListener aListener)
          Unregisters given connect event listener.
 void removeConnectMessageListener(ConnectMessageListener aListener)
          Unregisters connect message listener.
 void removeCreateLineMessageListener(CreateLineMessageListener aListener)
          Unregisters the "create line" message listener.
 void removeCreateMessageListener(CreateMessageListener aListener)
          Unregisters create message listener.
 void removeDisconnectListener(DisconnectListener aListener)
          Unregisters given disconnect event listener.
 void removeDisconnectMessageListener(DisconnectMessageListener aListener)
          Unregisters disconnect message listener.
 void removeMeMessageListener(MeMessageListener aListener)
          Unregisters the "me" message listener.
 void removePrivateMessageListener(PrivateMessageListener aListener)
          Unregisters the private message listener.
 void removePublicMessageListener(PublicMessageListener aListener)
          Unregisters public message listener.
 void removeReceivedMessageListener(ReceivedMessageListener aListener)
          Unregisters the "received" message listener.
 void removeRefreshBoardMessageListener(RefreshBoardMessageListener aListener)
          Unregisters the "refresh board" message listener.
 void removeRefreshMessageListener(RefreshMessageListener aListener)
          Unregisters refresh message listener.
 void removeRenameMessageListener(RenameMessageListener aListener)
          Unregisters disconnect message listener.
 void removeShutdownListener(ShutdownListener aListener)
          Unregisters given shutdown event listener.
 void removeStatusMessageListener(StatusMessageListener aListener)
          Unregisters the "status" message listener.
 void removeStatusReqMesageListener(StatusReqMessageListener aListener)
          Unregisters STATUS message listener.
 void sendMessage(IChatMessage aMessage, java.lang.String aReceiver)
          Sends a message to the server.
 void shutdown()
          Attepts to perform smooth shutdown, infoming all other clients about our disconnection.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IChatServiceBot

public IChatServiceBot(IChatBotProperties aProperties,
                       IChatMessageFactory messageFactory)
Constructor.

Parameters:
aProperties - - bot's properties
messageFactory -
Method Detail

addAlertMessageListener

public void addAlertMessageListener(AlertMessageListener aListener)
Registers the "alert" message listener.

Parameters:
aListener -

addBoardMessageListener

public void addBoardMessageListener(BoardMessageListener aListener)
Registers the "board" message listener.

Parameters:
aListener -

addBroadcastMessageListener

public void addBroadcastMessageListener(BroadcastMessageListener aListener)
Registers the private broadcast message listener.

Parameters:
aListener -

addConnectListener

public void addConnectListener(ConnectListener aListener)
Registers connect event listener.

Parameters:
aListener -

addConnectMessageListener

public void addConnectMessageListener(ConnectMessageListener aListener)
Registers connect message listener.

Parameters:
aListener -

addCreateLineMessageListener

public void addCreateLineMessageListener(CreateLineMessageListener aListener)
Registers the "create line" message listener.

Parameters:
aListener -

addCreateMessageListener

public void addCreateMessageListener(CreateMessageListener aListener)
Registers create message listener.

Parameters:
aListener -

addDisconnectListener

public void addDisconnectListener(DisconnectListener aListener)
Registers disconnect event listener.

Parameters:
aListener -

addShutdownListener

public void addShutdownListener(ShutdownListener aListener)
Registers disconnect event listener.

Parameters:
aListener -

addDisconnectMessageListener

public void addDisconnectMessageListener(DisconnectMessageListener aListener)
Registers disconnect message listener.

Parameters:
aListener -

addMeMessageListener

public void addMeMessageListener(MeMessageListener aListener)
Registers the "me" message listener.

Parameters:
aListener -

addPrivateMessageListener

public void addPrivateMessageListener(PrivateMessageListener aListener)
Registers the private message listener.

Parameters:
aListener -

addPublicMessageListener

public void addPublicMessageListener(PublicMessageListener aListener)
Registers public message listener.

Parameters:
aListener -

addReceivedMessageListener

public void addReceivedMessageListener(ReceivedMessageListener aListener)
Registers the "received" message listener.

Parameters:
aListener -

addRefreshBoardMessageListener

public void addRefreshBoardMessageListener(RefreshBoardMessageListener aListener)
Registers the "refresh board" message listener.

Parameters:
aListener -

addRefreshMessageListener

public void addRefreshMessageListener(RefreshMessageListener aListener)
Registers refresh message listener.

Parameters:
aListener -

addRenameMessageListener

public void addRenameMessageListener(RenameMessageListener aListener)
Registers disconnect message listener.

Parameters:
aListener -

addStatusMessageListener

public void addStatusMessageListener(StatusMessageListener aListener)
Registers the "status" message listener.

Parameters:
aListener -

addStatusReqMesageListener

public void addStatusReqMesageListener(StatusReqMessageListener aListener)
Registers STATUS message listener.

Parameters:
aListener -

connect

public void connect()
             throws java.net.UnknownHostException,
                    java.io.IOException,
                    java.security.NoSuchAlgorithmException,
                    javax.crypto.NoSuchPaddingException,
                    java.security.InvalidKeyException,
                    IChatException
Connects to the iChat server specified in the properties.

Throws:
java.net.UnknownHostException
java.io.IOException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
IChatException

isOnline

public final boolean isOnline()
Checks whether the bot is online.

Returns:

isDisconnecting

public final boolean isDisconnecting()
Checks whether the bot is being disconnected.

Returns:

isConnecting

public final boolean isConnecting()
Checks whether the bot is being connecting.

Returns:

isDisconnected

public final boolean isDisconnected()
Checks whether the bot is disconnected.

Returns:

isShuttingDown

public final boolean isShuttingDown()
Checks whether the bot is being shut down.

Returns:

shutdown

public void shutdown()
Attepts to perform smooth shutdown, infoming all other clients about our disconnection.


disconnect

public void disconnect()
Disconnects the bot from a server.

Throws:
java.io.IOException

getAlertMessageListeners

public java.util.List getAlertMessageListeners()
Returns the alertMessageListeners.

Returns:

getBoardMessageListeners

public java.util.List getBoardMessageListeners()
Returns the boardMessageListeners.

Returns:

getBroadcastMessageListeners

public java.util.List getBroadcastMessageListeners()
Returns the private broadcast message listeners.

Returns:

getCreateLineMessageListeners

public java.util.List getCreateLineMessageListeners()
Returns the createLineMessageListeners.

Returns:

getCreateMessageListeners

public java.util.List getCreateMessageListeners()
Returns the createMessageListeners.

Returns:

getMeMessageListeners

public java.util.List getMeMessageListeners()
Returns the meMessageListeners.

Returns:

getMessageId

public int getMessageId()
Generates message id.

Returns:
Returns the messageId.

getProperties

public IChatBotProperties getProperties()
Returns:
Returns the properties.

getReceivedMessageListeners

public java.util.List getReceivedMessageListeners()
Returns the receivedMessageListeners.

Returns:

getRefreshBoardMessageListeners

public java.util.List getRefreshBoardMessageListeners()
Returns the refreshBoardMessageListeners.

Returns:

getSender

public IChatSender getSender()
Returns sender object based on a properties values.

Returns:

getStatusMessageListeners

public java.util.List getStatusMessageListeners()
Returns the statusMessageListeners.

Returns:

getUserList

public IChatUserList getUserList()
Returns the userList.

Returns:

getUsers

public java.util.Map getUsers()
Returns the current user list map.

Returns:

isConnected

public boolean isConnected()
Checks whether the bot is connected to a server.

Returns:

processConnectMessage

public void processConnectMessage(IChatConnectMessage aMessage)
Adds a user to the user list and sends him a refresh message.

Specified by:
processConnectMessage in interface ConnectMessageListener
See Also:
ConnectMessageListener.processConnectMessage(IChatConnectMessage)

processDisconnectMessage

public void processDisconnectMessage(IChatDisconnectMessage aMessage,
                                     IChatUserInfo aUserInfo)
Description copied from interface: DisconnectMessageListener
Handles the DISCONNECT message.

Specified by:
processDisconnectMessage in interface DisconnectMessageListener
aUserInfo - - an information about the user being disconnected. Can be null in case of "precautios" disconnect messages.
See Also:
DisconnectMessageListener.processDisconnectMessage(IChatDisconnectMessage, com.web_visage.ichat.IChatUserInfo)

processRefreshMessage

public void processRefreshMessage(IChatRefreshMessage aMessage)
Description copied from interface: RefreshMessageListener
Handle REFRESH message

Specified by:
processRefreshMessage in interface RefreshMessageListener
See Also:
RefreshMessageListener.processRefreshMessage(IChatRefreshMessage)

processRenameMessage

public void processRenameMessage(IChatRenameMessage aMessage,
                                 java.lang.String anOldNickname)
Description copied from interface: RenameMessageListener
Handles rename message.

Specified by:
processRenameMessage in interface RenameMessageListener
anOldNickname - - the old user's nickname
See Also:
RenameMessageListener.processRenameMessage(IChatRenameMessage, java.lang.String)

processStatusMessage

public void processStatusMessage(IChatStatusMessage aMessage)
Description copied from interface: StatusMessageListener
Handles the iChat "status" message.

Specified by:
processStatusMessage in interface StatusMessageListener
See Also:
StatusMessageListener.processStatusMessage(IChatStatusMessage)

removeAlertMessageListener

public void removeAlertMessageListener(AlertMessageListener aListener)
Unregisters the "alert" message listener.

Parameters:
aListener -

removeBoardMessageListener

public void removeBoardMessageListener(BoardMessageListener aListener)
Unregisters the "board" message listener.

Parameters:
aListener -

removeBroadcastMessageListener

public void removeBroadcastMessageListener(BroadcastMessageListener aListener)
Unregisters the private broadcast message listener.

Parameters:
aListener -

removeConnectListener

public void removeConnectListener(ConnectListener aListener)
Unregisters given connect event listener.

Parameters:
aListener -

removeConnectMessageListener

public void removeConnectMessageListener(ConnectMessageListener aListener)
Unregisters connect message listener.

Parameters:
aListener -

removeCreateLineMessageListener

public void removeCreateLineMessageListener(CreateLineMessageListener aListener)
Unregisters the "create line" message listener.

Parameters:
aListener -

removeCreateMessageListener

public void removeCreateMessageListener(CreateMessageListener aListener)
Unregisters create message listener.

Parameters:
aListener -

removeDisconnectListener

public void removeDisconnectListener(DisconnectListener aListener)
Unregisters given disconnect event listener.

Parameters:
aListener -

removeShutdownListener

public void removeShutdownListener(ShutdownListener aListener)
Unregisters given shutdown event listener.

Parameters:
aListener -

removeDisconnectMessageListener

public void removeDisconnectMessageListener(DisconnectMessageListener aListener)
Unregisters disconnect message listener.

Parameters:
aListener -

removeMeMessageListener

public void removeMeMessageListener(MeMessageListener aListener)
Unregisters the "me" message listener.

Parameters:
aListener -

removePrivateMessageListener

public void removePrivateMessageListener(PrivateMessageListener aListener)
Unregisters the private message listener.

Parameters:
aListener -

removePublicMessageListener

public void removePublicMessageListener(PublicMessageListener aListener)
Unregisters public message listener.

Parameters:
aListener -

removeReceivedMessageListener

public void removeReceivedMessageListener(ReceivedMessageListener aListener)
Unregisters the "received" message listener.

Parameters:
aListener -

removeRefreshBoardMessageListener

public void removeRefreshBoardMessageListener(RefreshBoardMessageListener aListener)
Unregisters the "refresh board" message listener.

Parameters:
aListener -

removeRefreshMessageListener

public void removeRefreshMessageListener(RefreshMessageListener aListener)
Unregisters refresh message listener.

Parameters:
aListener -

removeRenameMessageListener

public void removeRenameMessageListener(RenameMessageListener aListener)
Unregisters disconnect message listener.

Parameters:
aListener -

removeStatusMessageListener

public void removeStatusMessageListener(StatusMessageListener aListener)
Unregisters the "status" message listener.

Parameters:
aListener -

removeStatusReqMesageListener

public void removeStatusReqMesageListener(StatusReqMessageListener aListener)
Unregisters STATUS message listener.

Parameters:
aListener -

sendMessage

public void sendMessage(IChatMessage aMessage,
                        java.lang.String aReceiver)
Sends a message to the server.

Parameters:
aMessage -
aReceiver -
Throws:
java.io.IOException