1 package net.walend.somnifugi.example; 2 3 import javax.swing.SwingUtilities ; 4 5 import javax.jms.QueueConnection ; 6 import javax.jms.QueueSender ; 7 import javax.jms.Queue ; 8 import javax.jms.QueueSession ; 9 import javax.jms.Session ; 10 import javax.jms.Message ; 11 import javax.jms.JMSException ; 12 import javax.jms.QueueReceiver ; 13 14 import net.walend.somnifugi.SomniJNDIBypass; 15 16 19 20 public class CommandQueueExample 21 extends SearchUI 22 { 23 public static final String QUEUENAME = "CommandQueueExample"; 24 25 private QueueConnection connection; 26 27 private QueueSender sender; 28 private QueueSession session; 29 30 public CommandQueueExample() 31 { 32 super(); 33 setUpSender(); 34 setUpListener(); 35 } 36 37 private void setUpSender() 38 { 39 try 40 { 41 connection = SomniJNDIBypass.IT.getQueueConnectionFactory().createQueueConnection(); 42 43 connection.start(); 44 45 SwingUtilities.invokeLater(new Runnable () 47 { 48 public void run() 49 { 50 try 51 { 52 Queue queue = SomniJNDIBypass.IT.getQueue(QUEUENAME); 53 session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); 54 sender = session.createSender(queue); 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 QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE); 75 Queue queue = SomniJNDIBypass.IT.getQueue(QUEUENAME); 76 QueueReceiver receiver = session.createReceiver(queue); 77 receiver.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 sender.send(message); 98 } 99 catch(JMSException jmse) 100 { 101 handleThrowable(jmse); 102 } 103 } 104 105 public static void main(String [] args) 106 { 107 CommandQueueExample example = new CommandQueueExample(); 108 109 example.showFrame(); 110 } 111 112 } 113 | Popular Tags |