1 24 package dotcom; 25 26 import javax.jms.*; 27 import javax.naming.*; 28 29 40 public class DeliveryServer { 41 42 public static void main (String argv[]) throws Exception { 43 44 try { 45 javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); 48 49 DeliveryTreatment deliveryTreatment = new DeliveryTreatment() ; 51 java.lang.Thread deliveryThread = new java.lang.Thread (deliveryTreatment) ; 52 deliveryThread.start() ; 53 54 } catch (Exception exc) { 55 System.out.println("Exception caught in DeliveryServer: " + exc) ; 56 exc.printStackTrace(); 57 } 58 } 59 } 60 61 62 73 class DeliveryTreatment implements Runnable , Servers { 74 static Context ictx = null; 75 76 GUI deliveryGUI ; 77 78 81 public void run() { 82 deliveryGUI = new GUI("Delivery Server", "To be delivered", this, 300, 600); 84 85 try { 86 ictx = new InitialContext(); 88 QueueConnectionFactory qcf; 90 qcf = (QueueConnectionFactory) ictx.lookup("qcf"); 91 Queue queueDelivery ; 93 queueDelivery = (Queue) ictx.lookup("qDelivery"); 94 ictx.close(); 95 96 QueueConnection qc = qcf.createQueueConnection("delivery", "delivery"); 98 QueueSession qsession ; 100 qsession = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE); 101 QueueReceiver qr = qsession.createReceiver(queueDelivery); 103 qc.start() ; 105 106 System.out.println("DeliveryServer is ready.") ; 107 108 while (true) { 109 ObjectMessage msg = (ObjectMessage) qr.receive() ; 111 112 if (msg.getObject() instanceof QuitMessage) { 114 qsession.commit() ; 116 117 qsession.close() ; 119 qc.close() ; 120 121 System.out.println("Session and connection closed by DeliveryServer."); 122 System.exit(0) ; 123 } 124 125 else if (msg.getObject() instanceof OrderMessage) { 127 qsession.commit() ; 129 130 OrderMessage orderMsg = (OrderMessage) msg.getObject() ; 132 133 System.out.println("Message received by DeliveryServer from CustomerServer: " + orderMsg.id) ; 134 135 deliveryGUI.updateId(orderMsg.id) ; 137 deliveryGUI.updateItem(orderMsg.item) ; 138 deliveryGUI.setVisible(true) ; 139 } 140 } 141 } catch (Exception exc) { 142 System.out.println("Exception caught in DeliveryServer thread: " + exc) ; 143 exc.printStackTrace() ; 144 } 145 } 146 147 150 public void closeMethod() { 151 deliveryGUI.setVisible(false) ; 152 } 153 154 157 public void choiceMethod(String choice) {} 158 161 public void otherMethod() {} 162 165 public void sendMethod() {} 166 169 public void cancelMethod() {} 170 173 public void quitMethod() {} 174 177 public void okMethod() {} 178 181 public void noMethod() {} 182 } 183 | Popular Tags |