Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

The application in this Magercise is a simple message box, like a telephone answering machine. The MessageBox interface has an operation for leaving messages, another for the owner to get the messages, and an attribute for setting the reply that is sent out when a message is left. Here is the IDL file:

module MessageModule {

  typedef sequence<string> MessageSeq;

  interface MessageBox {
    attribute string reply;

    string leaveMessage(in string msg)
      raises (boxFull);

    MessageSeq getMessages();
  };

};

Your task is to create a MessageBoxImpl class to implement this interface. You will also add methods to the MBClient class to test your MessageBoxImpl.

Prerequisites

Skeleton Code

Tasks


  1. First generate the IDL file.

  2. Examine the generated Java interface in MessageModule/MessageBox.java. Using the given skeleton file, MessageBoxImpl.java, implement the necessary methods.

    Don't forget to add a constructor. It should take a string argument as a name, and call the superclass constructor to set the name of the object.

    Notice how the sequence is generated. No MessageSeq class is created; instead you use the Java type String[]. There are, however, helper and holder classes generated for MessageSeq.

  3. Modify the MBServer class to instantiate a MessageBoxImpl with a name of your choosing. Remember, you want this name to be unique to avoid conflicts with other ORBs on your network.

  4. Look at the MBClient source code provided for you. Make sure you understand how the command-line parameters are parsed. The usage of MBClient is:

    vbj MBClient servername command param
    vbj MBClient servername leave message
    vbj MBClient servername reply reply-messsage
    vbj MBClient servername get
    
  5. Finish the skeleton version of MBClient by adding code as specified by the comments. You should call the reply setter to set an appropriate reply, call leaveMessage to leave some messages, and retrieve your messages using getMessages so they can be printed out.

  6. Now compile the program, using vbjc.

  7. Run the server: start vbj MBServer. Check that it is running ok.

  8. Run the client: vbj MBClient servername command param. Check the output of your program.

    See the expected behavior section for more detail on the correct output for your program.

  9. If you happen to have multiple machines, run the program on each and leave and retrieve messages on the other message boxes.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

The client part of your program should run something like this:

C:\> vbj MBClient myMessages leave "Meet me tonight"
C:\> vbj MBClient myMessages leave 
"Hey,where's that $100 you owe me?"
C:\> vbj MBClient myMessages get
Here are your messages:
  Meet me tonight
  Hey,where's that $100 you owe me?

If you leave too many messages, then leaving another message should produce an infomative message (like "BEEEEEEEEEP").

Next Magercise

Magercises

Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 3-Dec-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.