1 package net.walend.somnifugi.example; 2 3 import javax.swing.SwingUtilities ; 4 5 import javax.jms.TopicConnection ; 6 import javax.jms.TopicPublisher ; 7 import javax.jms.Topic ; 8 import javax.jms.TopicSession ; 9 import javax.jms.Session ; 10 import javax.jms.Message ; 11 import javax.jms.JMSException ; 12 import javax.jms.TopicSubscriber ; 13 14 import net.walend.somnifugi.SomniJNDIBypass; 15 16 19 20 public class EventTopicExample 21 extends SearchUI 22 { 23 public static final String TOPICNAME = "EventTopicExample"; 24 25 private TopicConnection connection; 26 27 private TopicPublisher publisher; 28 private TopicSession session; 29 30 public EventTopicExample() 31 { 32 super(); 33 setUpPublisher(); 34 setUpListener(); 35 } 36 37 private void setUpPublisher() 38 { 39 try 40 { 41 connection = SomniJNDIBypass.IT.getTopicConnectionFactory().createTopicConnection(); 42 43 connection.start(); 44 45 SwingUtilities.invokeLater(new Runnable () 47 { 48 public void run() 49 { 50 try 51 { 52 Topic topic = SomniJNDIBypass.IT.getTopic(TOPICNAME); 53 session = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); 54 publisher = session.createPublisher(topic); 55 } 56 catch(JMSException jmse) 57 { 58 handleThrowable(jmse); 59 } 60 } 61 }); 62 } 63 catch(JMSException jmse) 64 { 65 handleThrowable(jmse); 66 } 67 } 68 69 private void setUpListener() 70 { 71 try 72 { 73 LookupMessageListener listener = new LookupMessageListener(this); 74 TopicSession session = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); 75 Topic topic = SomniJNDIBypass.IT.getTopic(TOPICNAME); 76 TopicSubscriber subscriber = session.createSubscriber(topic); 77 subscriber.setMessageListener(listener); 78 } 79 catch(JMSException jmse) 80 { 81 handleThrowable(jmse); 82 } 83 } 84 85 88 protected void searchButtonActionPerformed() 89 { 90 try 91 { 92 LookupRequest request = new LookupRequest(searchTF.getText()); 94 95 Message message = session.createObjectMessage(request); 97 publisher.publish(message); 98 } 99 catch(JMSException jmse) 100 { 101 handleThrowable(jmse); 102 } 103 } 104 105 public static void main(String [] args) 106 { 107 EventTopicExample example = new EventTopicExample(); 108 109 example.showFrame(); 110 } 111 112 } 113 | Popular Tags |