/* * @(#)java_demo.java 1.0 97/11/17 * * Copyright (c) 1997 Volker Weber, Univerity of Hamburg. All Rights Reserved. * * This software is the confidential and proprietary information of Volker * Weber ("Confidential Information"). You shall not disclose such Confidential * Information and shall use it only in accordance with the terms of the * license agreement you entered into with the Author(s). * * THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR * NON-INFRINGEMENT. THE AUTHORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR * ITS DERIVATIVES. * */ import Ice.*; /** * * The class java_demo shows the abilities of the ICE-Java interface * * @author Volker Weber * @version 1.0, 26 Nov 1997 */ class java_demo { public static void main(String[] args) { if ( args.length != 1 ) { System.err.println("Usage: java java_demo [send | receive]"); System.exit(1); } System.out.println(ICE.Release()); System.out.println(ICE.JavaRelease()); System.out.println("ICE-server Information:"); System.out.println(" IDL.INTEGER: MIN: " + IDL.MIN_INTEGER); System.out.println(" MAX: +" + IDL.MAX_INTEGER); System.out.println(" SEND UNSINGNED > +" + IDL.SIGNED); System.out.println(" IDL.REAL: MIN: " + IDL.MIN_REAL); System.out.println(" MAX: " + IDL.MAX_REAL); System.out.println(" IEEE 754: " + (IDL.HAS_IEEE754 ? "YES" : "NO")); ICE.Init(); if ( args[0].equals("send") ) { Demo_Sender(); } else if ( args[0].equals("receive") ) Demo_Receiver(); else { System.err.println("Usage: java java_demo [send | receive]"); System.exit(1); } } public static void Demo_Sender() { // Initialization System.out.println("Initializing and attaching..."); Component me = Component.Attach("demo-sender"); // create other component System.out.println("Creating other component..."); Channel dest = me.AddCompo("demo-receiver"); // send messages to destination task System.out.println("Preparing messages and sending it to receiver..."); me.SetTurnId(1); ICE.Configure(ICE.NoBlockSend, 0, ""); if ( ! dest.Send('A') ) System.out.println("Configuration not complete"); ICE.Configure(ICE.BlockSend, 0, ""); dest.Send("Howdy"); dest.Send(-4711); dest.Send(4711); dest.Send(-123456); dest.Send(123456); dest.Send(3.4); dest.Send(1./3.); me.SetTurnId(2); dest.Send('A'); dest.Send("Howdy"); dest.Send(-4711); dest.Send(4711); dest.Send(-123456); dest.Send(123456); dest.Send(3.4); dest.Send(1./3.); // This were just the test values of c++demo dest.Send(IDL.MAX_INTEGER); // try IDL.UNSIGNED dest.Send((byte)127); // try a byte dest.Send((short)32767); // try a short dest.Send((Float.MAX_VALUE > IDL.MAX_REAL ? IDL.MAX_REAL : Float.MAX_VALUE)); // try a float dest.Send(IDL.HAS_IEEE754); // try a boolean // dest.Send(new Object()); // try object dest.Send(ICE.NOTAG, 999, "concern999", 0, 0, 50, "End-demo"); // receive messages from destination task System.out.println("Receive only turns >= 2"); me.SetMinTurnId(2); System.out.println("Wait for replies from receiver..."); Ice.Msg msg; boolean endall = false; while ( ! endall ) { msg = me.Receive(ICE.ANY); if ( msg == null ) { System.out.println("Received null msg!"); dest.Send(ICE.NOTAG, 2, "null Received", 0, 0, 50, "End-demo"); endall = true; } else { System.out.println("Received from " + dest.Name() + " (turn " + msg.TurnId() + ", module Id " + msg.ModuleId() + ", concern " + msg.Concern() + ". Got " + msg.M_Type() + " " + msg.M_Data() + ")"); if ( msg.M_Data().equals("End-demo") ) endall = true; } msg = null; // don't worry about finalization, it's done for you } // Set up a special channel for communication System.out.println("Communication over a special channel"); Channel control = dest.AddChan("controller", ICE.NORMAL); // Communicate over that channel control.Send("Special Channel"); if ( control.Receive(ICE.NOTAG, 99999L) == null ) System.out.println("Oops, timeout while receiving over \"" + control.Name() + "\""); // Check timeout System.out.println("Checking timeout for receive"); if ( me.Receive(ICE.ANY, 500L) == null ) System.out.println("Ok"); else System.out.println("Oops, is there something?"); // clean up System.out.println("Cleaning up and exiting"); control.Remove(); // NOT needed dest.Remove(); // NOT needed me.Detach(); // not needed, but recommendend } public static void Demo_Receiver() { // initialization System.out.println("Initializing IDL..."); Component me = Component.Attach("demo-receiver"); // create other component System.out.println("Creating other component..."); Channel dest = me.AddCompo("demo-sender"); // Receive messages from Sender Ice.Msg msg; boolean endall = false; while ( ! endall ) { msg = me.Receive(ICE.ANY); if ( msg == null ) { System.out.println("Received null msg!"); me.SetTurnId(2); dest.Send(ICE.NOTAG, 2, "null Received", 0, 0, 50, "End-demo"); endall = true; } else { System.out.println("Got message from " + dest.Name() + " (turn " + msg.TurnId() + ", module Id " + msg.ModuleId() + ", concern " + msg.Concern() + ". Got " + msg.M_Type() + " " + msg.M_Data() + ")"); if ( msg.M_Data().equals("End-demo") ) endall = true; me.SetTurnId(msg.TurnId()); dest.Send(ICE.NOTAG, msg.TurnId(), msg.Concern(), 0, 0, 50, msg.M_Data()); } msg = null; // don't worry about finalization, it's done for you } // Set up a special channel for communication System.out.println("Communication over a special channel"); Channel control = dest.AddChan("controller", ICE.NORMAL); // Communicate over that channel msg = control.Receive(ICE.NOTAG); if ( msg == null ) { System.out.println("Received null msg over controller channel!"); control.Send(ICE.NOTAG, 0, "null Received", 0, 0, 50, "Shit!"); } else { System.out.println("Got message over controller channel, content is" + " " + msg.M_Data()); control.Send(ICE.NOTAG, 0, "", 0, 0, 50, msg.M_Data()); } msg = null; // don't worry about finalization, it's done for you // Check timeout System.out.println("Checking timeout for receive"); if ( me.Receive(ICE.ANY, 500L) == null ) System.out.println("Ok"); else System.out.println("Oops, is there something?"); // clean up System.out.println("Cleaning up and exiting"); me.Detach(); // The channel remove requests are done by Detach } } // End of java_demo - Class /* EOF */