1 22 package org.objectweb.petals.engine.sampleclient; 23 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 27 import javax.jbi.messaging.DeliveryChannel; 28 import javax.jbi.messaging.ExchangeStatus; 29 import javax.jbi.messaging.MessageExchange; 30 import javax.jbi.messaging.MessagingException; 31 32 import org.objectweb.petals.component.common.util.SourceHelper; 33 import org.objectweb.petals.engine.sampleclient.gui.Console; 34 35 40 public class SampleClientListener implements Runnable { 41 42 private DeliveryChannel channel; 43 44 private MessageExchange messageExchange; 45 46 private boolean running = true; 47 48 private Console console; 49 50 private Logger logger; 51 52 public SampleClientListener(DeliveryChannel channel, Console c, Logger log) { 53 super(); 54 this.channel = channel; 55 console = c; 56 logger = log; 57 } 58 59 public void run() { 60 61 mainLoop: while (running) { 62 try { 63 messageExchange = channel.accept(); 64 if (messageExchange != null) { 65 process(messageExchange); 66 } 67 } catch (MessagingException e) { 68 logger.severe(this + " run()" + e.getMessage()); 69 continue mainLoop; 70 } 71 } 72 73 } 74 75 public void process(MessageExchange msg) { 76 logger.log(Level.INFO, "process(" + msg + ")"); 77 78 String response = null; 79 80 if (ExchangeStatus.DONE.equals(msg.getStatus())) { 81 response = "receive a DONE status."; 82 } else if (ExchangeStatus.ERROR.equals(msg.getStatus())) { 83 response = "receive an ERROR status :" 84 + msg.getError().getMessage(); 85 } else { 86 try { 87 if (msg.getMessage("OUT") != null) 88 response = SourceHelper.createString(msg.getMessage("OUT") 89 .getContent()); 90 else if (msg.getFault() != null) 91 response = "FAULT : " 92 + SourceHelper 93 .createString(msg.getFault().getContent()); 94 95 msg.setStatus(ExchangeStatus.DONE); 96 97 channel.send(msg); 98 } catch (Exception e) { 99 logger.log(Level.SEVERE, e.getClass() + ":" + e.getMessage()); 100 response = e.getMessage(); 101 } 102 } 103 console.setResponse(response); 104 } 105 106 public void stopProcessing() { 107 this.running = false; 108 } 109 110 } 111 | Popular Tags |