1 21 22 package test.server.named; 24 25 import com.rift.coad.lib.bean.BeanRunnable; 27 import com.rift.coad.lib.thread.ThreadStateMonitor; 28 import com.rift.coad.daemon.messageservice.Message; 29 import com.rift.coad.daemon.messageservice.TextMessage; 30 import com.rift.coad.daemon.messageservice.named.NamedQueueClient; 31 32 33 38 public class NamedServerImpl implements NamedServer, BeanRunnable { 39 40 private ThreadStateMonitor state = new ThreadStateMonitor(); 42 43 46 public NamedServerImpl() { 47 } 48 49 50 53 public void process() { 54 NamedQueueClient client = null; 55 try { 56 client = NamedQueueClient.create("test"); 57 } catch (Exception ex) { 58 System.out.println("Failed to create named queue"); 59 return; 60 } 61 while(!state.isTerminated()) { 62 try { 63 Message message = client.receive(1000); 64 if (message == null) { 65 continue; 66 } 67 TextMessage textMessage = (TextMessage)message; 68 } catch (Exception ex) { 69 System.out.println("Failed to retrieve text message:" 70 + ex.toString()); 71 } 72 } 73 } 74 75 76 79 public void terminate() { 80 state.terminate(true); 81 } 82 } 83 | Popular Tags |