1 package net.walend.somnifugi.example; 2 3 import java.util.Collection ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 7 import javax.jms.MessageListener ; 8 import javax.jms.Message ; 9 import javax.jms.ObjectMessage ; 10 import javax.jms.JMSException ; 11 12 15 16 public class LookupMessageListener 17 implements MessageListener 18 { 19 private LookupListener listener; 20 21 public LookupMessageListener(LookupListener listener) 22 { 23 this.listener = listener; 24 } 25 26 public void onMessage(Message message) 27 { 28 try 29 { 30 ObjectMessage om = (ObjectMessage )message; 31 32 LookupRequest request = (LookupRequest)om.getObject(); 33 34 fireLookupStarted(request); 35 Thread.sleep(1000); 37 38 String [] resultArray = new String []{"Book one", "Book two", "Book three"}; 40 LookupResults results = new LookupResults(request,resultArray); 41 42 fireLookupCompleted(results); 43 } 44 catch(JMSException jmse) 45 { 46 throw new RuntimeException (jmse); 47 } 48 catch (InterruptedException e) 49 { 50 Thread.currentThread().interrupt(); 51 } 52 } 53 54 private void fireLookupStarted(LookupRequest request) 55 { 56 listener.lookupStarted(request); 57 } 58 59 private void fireLookupCompleted(LookupResults results) 60 { 61 listener.lookupCompleted(results); 62 } 63 64 } 65 | Popular Tags |