Exercise

To extend your knowledge of the subjects covered today, try the following exercises.

  1. Create a chat room application. Participants provide their name and can send messages to any topic (hint: use a JMS property to define the topic). Participants may read messages posted by all other participants or filter by topic. You may use predefined topic names.

To assist you in this task, three Java files have been provided in the exercise sub-directory for Day 9 on the accompanying CD-ROM.

The Chat.java and ChatDisplay.java files are complete and need not be edited. These files provide the Swing code to enter and display the chat room messages onscreen.

The TopicServer.java is a starting point for you to further develop the chat server. The initial code simply uses the callback method addMessage to bounce the message back to the screen. The addMessage method uses the interface defined in ChatDisplay.java.

You will need to edit this file to replace this callback with code to publish the message to a topic. You then need to add a subscriber that consumes messages from this topic and displays them onscreen.

Add a property called From to the message and set it to the from parameter passed in. This will then be displayed in the chat room window.

A completed TopicServer is included in the solutions sub-directory of Day 9 of the case study.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.30.19