import org.omg.CORBA.ORB;
import java.io.*;
import casino.*;
public class Gambler {
public static void main(String[] argv) {
try {
System.out.println("Gambler\n");
System.out.println("Looking up RouletteWheel home");
RouletteWheelHome wheelHome =
(RouletteWheelHome)
EJBUtils.jndi_lookup("cics/ejbs/RouletteWheel",
RouletteWheelHome.class);
//
// See Note 1.
//
System.out.println("Creating a new roulette wheel");
RouletteWheel wheel = wheelHome.create();
System.out.println("");
System.out.println("Gambling $50 on red !");
System.out.println(wheel.bet("red",50));
System.out.println("");
System.out.println("Gambling $20 on black !");
System.out.println(wheel.bet("black",20));
System.out.println("");
System.out.println("Gambling $20 on red !");
System.out.println(wheel.bet("red",20));
System.out.println("");
System.out.print("Collecting winnings:$");
System.out.println(wheel.collectWinnings());
System.out.println("");
System.out.print("Removing the roulette wheel");
wheel.remove();
} catch (Exception e) {
System.err.println("Error whilst gambling:");
e.printStackTrace();
}
}
}
Note: - The client program Gambler.java looks up the RouletteWheel at "cics/ejbs"
in the namespace. This means the CORBASERVER in CICS into which you have
installed the RouletteWheel bean must have a JNDI prefix of cics/ejbs. Once
installed and published the RouletteWheel will then be accessible by the
client program.
- There is a remove call at the end of this client program.
The roulette wheel bean is stateful and CICS manages the state of every instance.
Unless remove is called when you finish operating with that bean
instance then CICS will continue to store it. Bean timeout can be controlled
using the SESSBEANTIME parameter of the CORBASERVER resource definition. This
indicates to CICS how long it should manage instance state if no requests
are coming in to utilize that instance, implementing a kind of garbage collection.
However, it is good programming practice to call remove when you
have finished working with an instance so that you do not depend on this type
of garbage collection.