Java Reference
In-Depth Information
// Get the initial context
System.out.println("Getting Initial Context:");
context = new InitialContext();
System.out.println("Got Initial Context:"+context);
// Get the connection factory
System.out.println("Getting Topic Factory:");
topicFactory = (TopicConnectionFactory)
context.lookup(factoryJNDI);
System.out.println("Got Topic Factory:"+topicFactory);
// Create the connection
topicConnection = topicFactory.createTopicConnection();
// Create the session
topicSession=topicConnection.createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
// Look up the destination
topic = (Topic)context.lookup(topicJNDI);
Create a
subscriber
B
// Create a subscriber
topicSubscriber =
topicSession.createSubscriber(topic);
// Set the message listener,
// which is this class since we implement
// the MessageListener interface
topicSubscriber.setMessageListener(this);
topicConnection.start();
}
public void onMessage( Message m )
{
Topic topic=null;
TopicPublisher topicPublisher=null;
TopicSession sendTopicSession=null;
TextMessage message=null;
String msg=null;
String msg2=null;
try
{
msg = ((TextMessage)m).getText();
if( msg.equals("MOVIELIGHTSOn") )
{
msg="SurroundOn";
msg2="ScreenDown";
publishMessages(msg,msg2);
}
else if( msg.equals("MOVIELIGHTSOff") )
{
msg="SurroundOff";
msg2="ScreenUp";
C
Process
message
Search WWH ::




Custom Search