1 2 3 package Jt; 4 import java.util.*; 5 import java.lang.reflect.*; 6 import java.beans.*; 7 import java.io.*; 8 9 12 13 public class JtQueue extends JtList { 14 15 public JtQueue() { 16 } 17 18 19 20 private Object test () { 21 22 JtMessage msg; 23 Object obj; 24 25 26 28 msg = new JtMessage ("JtENQUEUE"); 29 msg.setMsgContent (new Integer (1)); 30 System.out.println ("Enqueue object ... " + new Integer (1)); 31 sendMessage (this, msg); 32 33 34 msg = new JtMessage ("JtENQUEUE"); 35 msg.setMsgContent (new Integer (2)); 36 System.out.println ("Enqueue object ... " + new Integer (2)); 37 sendMessage (this, msg); 38 39 40 42 for (;;) { 43 obj = (Object ) sendMessage (this, new JtMessage ("JtDEQUEUE")); 44 if (obj == null) 45 break; 46 System.out.println ("Dequeue object ... " + obj); 47 } 48 return (this); 49 50 } 51 52 60 61 public Object processMessage (Object message) { 62 63 String msgid = null; 64 JtMessage e = (JtMessage) message; 65 Object content; 66 Object data; 67 JtMessage tmp; 68 69 70 if (e == null) 71 return null; 72 73 msgid = (String ) e.getMsgId (); 74 75 if (msgid == null) 76 return null; 77 78 content = e.getMsgContent(); 79 80 81 if (msgid.equals ("JtREMOVE")) { 83 84 return (null); 85 } 86 87 if (msgid.equals ("JtENQUEUE")) { 89 91 tmp = new JtMessage ("JtADD"); 92 tmp.setMsgContent (content); 93 return (super.processMessage (tmp)); 94 } 95 96 97 99 if (msgid.equals ("JtDEQUEUE")) { 100 101 102 return (super.processMessage (new JtMessage ("JtREMOVE_FIRST"))); 103 } 104 105 106 107 if (msgid.equals ("JtTEST")) { 109 110 return (test ()); 111 } 112 113 handleError ("JtQueue.processMessage: invalid message id:" + msgid); 114 return (null); 115 116 } 117 118 119 122 123 public static void main(String [] args) { 124 125 JtObject main = new JtObject (); 126 JtQueue queue; 127 128 Object obj; 129 130 131 132 134 queue = (JtQueue) main.createObject ("Jt.JtQueue", "queue"); 135 136 main.sendMessage (queue, new JtMessage ("JtTEST")); 137 138 main.removeObject (queue); 139 } 140 141 } 142 143 144
| Popular Tags
|