edu.rit.chat2
Class Chat

java.lang.Object
  extended by edu.rit.chat2.Chat
All Implemented Interfaces:
ChatDiscoveryRef, ChatFrameListener, ChatRef, TimerTask

public class Chat
extends Object
implements ChatFrameListener, ChatRef, ChatDiscoveryRef, TimerTask

Class Chat is a rudimentary M2MI-based chat application. The program displays a simple chat UI (an instance of class ChatFrame), and the program exports a chat object (an instance of class Chat) that implements interface ChatRef. Each chat room is associated with its own multihandle for interface ChatRef, and the chat object is attached to the multihandle corresponding to the chat room the user joined. When the user sends a line of text in the UI, the line is broadcast to all the chat objects in the chat room by calling putLine() on the multihandle. When each chat object receives a putLine() invocation, it displays the line of text in the chat log in its UI.

To discover which chat rooms are out there, the chat object also implements interface ChatDiscoveryRef. Each chat object periodically broadcasts the name and multihandle of its chat room by calling reportChatRoom() on an omnihandle for interface ChatDiscoveryRef. When each chat object receives a reportChatRoom() invocation, it puts the chat room name and multihandle in a list. When the user selects a chat room, the chat object detaches itself from the previous chat room's multihandle and attaches itself to the new chat room's multihandle.

The chat demo is intended merely to demonstrate M2MI omnihandle and multihandle invocations and is not intended to be a full-featured chat application.

Usage: java edu.rit.chat2.Chat username

When running the chat demo application, M2MI and M2MP must be configured, and the M2MP Daemon must be running if necessary. See packages edu.rit.m2mi and edu.rit.m2mp for further information.

The chat demo application displays this UI:

Pick the chat room to join from the drop-down list, or click the "New..." button to create a new chat room. Type a line of text into any chat window on any machine and hit return or click the "Send" button. The line of text, prefixed by the user name, shows up in all the chat windows on all the machines that have joined the same chat room.


Method Summary
 void action(Timer theTimer)
          Upon timeout, broadcast the existence of this chat room.
static void main(String[] args)
          Main program.
 void newChatRoom()
          Report that the user wants to create a new chat room.
 void putMessage(String line)
          Display the given line of text in this chat object's chat log.
 void reportChatRoom(ChatRoom theChatRoom)
          Report that a chat room exists.
 void requestChatRooms()
          Request everyone to report the existence of their chat rooms.
 void run(String[] args)
          Run this chat application.
 void send(String line)
          Process the given line of text entered by the user.
 void setChatRoom(int i)
          Report that the user selected the given chat room.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

run

public void run(String[] args)
         throws Throwable
Run this chat application.

Parameters:
args - Command line arguments.
Throws:
Throwable

newChatRoom

public void newChatRoom()
Report that the user wants to create a new chat room.

Specified by:
newChatRoom in interface ChatFrameListener

setChatRoom

public void setChatRoom(int i)
Report that the user selected the given chat room.

Specified by:
setChatRoom in interface ChatFrameListener
Parameters:
i - Chat room index.

send

public void send(String line)
Process the given line of text entered by the user.

Specified by:
send in interface ChatFrameListener
Parameters:
line - Line of text.

putMessage

public void putMessage(String line)
Display the given line of text in this chat object's chat log.

Specified by:
putMessage in interface ChatRef
Parameters:
line - Line of text.

requestChatRooms

public void requestChatRooms()
Request everyone to report the existence of their chat rooms.

Specified by:
requestChatRooms in interface ChatDiscoveryRef

reportChatRoom

public void reportChatRoom(ChatRoom theChatRoom)
Report that a chat room exists.

Specified by:
reportChatRoom in interface ChatDiscoveryRef
Parameters:
theChatRoom - Chat room (name plus multihandle).

action

public void action(Timer theTimer)
Upon timeout, broadcast the existence of this chat room.

Specified by:
action in interface TimerTask
Parameters:
theTimer - Timer.

main

public static void main(String[] args)
                 throws Throwable
Main program.

Parameters:
args - Command line arguments.
Throws:
Throwable


Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.