Java Reference
In-Depth Information
System.out.println("Publishing message: "+msg);
publisher.publish(msg);
try{Thread.sleep(2000);}catch(InterruptedException e){}
msg = "MOVIELIGHTSOff";
System.out.println("Publishing message: "+msg);
publisher.publish(msg);
try{Thread.sleep(2000);}catch(InterruptedException e){}
msg = "doNothing";
System.out.println("Publishing message: "+msg);
publisher.publish(msg);
// Close down your publisher
publisher.close();
}
catch(Exception ex) {
System.err.println("An exception occurred "
+ "while testing Publisher: " + ex);
ex.printStackTrace();
}
}
}
You will use this class to publish the control messages in which the MBean is
interested, allowing you to test the system. This class simulates the sending of
messages from the remote control of the home theater system. Looking at its
main() method, you can see that it publishes three messages. The first message is
MOVIELIGHTSOn ; after sleeping for two seconds, the class publishes the MOVIE-
LIGHTSOff message. The third message it publishes is doNothing ; the subscriber
MBean should print out a message indicating that it contains no macro for this
type of message.
13.4 Running the example
Now that you have built the MBean and other necessary classes, let's run the
example. You will need to have the JBoss J2EE container running to provide the
JMS message bus. Additionally, you must start an instance of the JMXBookAgent
class. After running the agent, execute the setup class to register the MBean.
The following list shows the tasks you must perform to run the example:
Start and configure the JBoss server.
Start the agent and register the MBean.
Run the debugger ( IR signal transmitter).
Publish the control messages (the IR signal processor).
Search WWH ::




Custom Search