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
 

Help is available for each task.



    Task 1

    First generate the IDL file.



    Use idl2java messageBox.idl, as in the previous Magercise.

    Task 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.



    The methods you will implement are:
    
    public MessageBoxImpl(String name, int max);
    public void reply(java.lang.String reply);
    public java.lang.String reply();
    public java.lang.String leaveMessage(
                           java.lang.String 
    msg) throws ;
    public java.lang.String[] getMessages();
    

    You will also need local variables to hold the value of the reply, and a vector for the messages. For example:

      protected String _reply;
      protected int _max;
      protected Vector _messages = 
                       new Vector(5);
    

    Task 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.



    You might want to enter the object instance name on the command-line, using code like the following:
        if (args.length > 0)
    	name = args[0];
    

    Task 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
    

    Task 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.



    Here is an example of code you can add:
    // set the reply
    mb.reply(param);
    
    // leave a message
    try {
     System.out.println(mb.leaveMessage(param));
    }
    catch (
     MessageModule.MessageBoxPackage.boxFull e)
    {
     System.out.println(
         "Box full, message not left");
    }
    
    // get messages
    String[] messages = mb.getMessages();
    for(int i = 0; i < messages.length; i++)
      System.out.println("  " + messages[i]);
    

    Task 6

    Now compile the program, using vbjc.



    Use the command: vjbc *.java

    Task 7

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


    Task 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.


    Task 9

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


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.