Java Reference
In-Depth Information
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error Registering MBeans");
}
}
public void close()
{
client.disconnect();
}
public static void main(String[] args)
{
System.out.println("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
System.out.println("\n>>> START of JMS MBean example");
JMSSetup agent = new JMSSetup ();
agent.createMBeans();
agent.close();
System.exit(0);
}
}
By this chapter, you have seen similar code many times. This class registers the
JMSController MBean in the agent by providing an ObjectName and the class-
name of the MBean.
Writing the MOVIELIGHTSOn and MOVIELIGHTSOff publisher
Now that you have written the MBean and subscriber code, you need a way to
publish the control commands to the JMS bus. The class in listing 13.5 publishes
three messages: MOVIELIGHTSOn , MOVIELIGHTSOff , and doNOTHING . This class repre-
sents the IR signal process receiving commands from a remote control.
Listing 13.5
JMSPublisher.java
package jmxbook.ch13;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import javax.jms.TopicPublisher;
import javax.jms.Topic;
import javax.jms.TextMessage;
Search WWH ::




Custom Search