J2EE Messaging
903
// Send the purchase order
queueSender.send(message);
}
public void start() throws NamingException, JMSException, IOException
{
// First get a list of stocks that the customer is interested in receiving
boolean noQuotesYetEntered = true;
System.out.print("First, enter the symbols of stock quotes you wish to
receive.\n");
while(true){
System.out.print("Enter a stock symbol to receive quotes for that
stock\nd)one entering symbols\n:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String symbol = in.readLine();
System.out.println();
if(symbol.equalsIgnoreCase("d")){
break; // done entering symbols
}
else{
if(noQuotesYetEntered){
// This stock selector is a message selector which we use to filter the
stocks
// to receive only those quotes that we specify
stockSelector = new String("symbol IN ('" + symbol + "')");
noQuotesYetEntered = false;
}
else{
stockSelector += " OR (" + symbol + ")";
}
}
}
setup();
topicConnection.start();
queueConnection.start();
synchronized(this)
{
while (!quit)
{
try
{
this.wait();
}
catch (InterruptedException ie)
{}
}
}
// Close connections
topicConnection.close();
queueConnection.close();
}
public static void main(String[] args) throws Exception{
PurchaserGuy purchaser = new PurchaserGuy();
purchaser.start();
}
}