01: /*
02: * MessageTest: This is a test message service library.
03: * Copyright (C) 2007 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * NamedServer1.java
20: */
21:
22: // package path
23: package test.server.named;
24:
25: // imports
26: 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: * The named server implementation of the named server.
34: *
35: * @author Brett Chaldecott
36: */
37: public class NamedServerImpl implements NamedServer, BeanRunnable {
38:
39: // private member variables
40: private ThreadStateMonitor state = new ThreadStateMonitor();
41:
42: /**
43: * Creates a new instance of NamedServer1
44: */
45: public NamedServerImpl() {
46: }
47:
48: /**
49: * This method is called to perform the processing.
50: */
51: public void process() {
52: NamedQueueClient client = null;
53: try {
54: client = NamedQueueClient.create("test");
55: } catch (Exception ex) {
56: System.out.println("Failed to create named queue");
57: return;
58: }
59: while (!state.isTerminated()) {
60: try {
61: Message message = client.receive(1000);
62: if (message == null) {
63: continue;
64: }
65: TextMessage textMessage = (TextMessage) message;
66: } catch (Exception ex) {
67: System.out.println("Failed to retrieve text message:"
68: + ex.toString());
69: }
70: }
71: }
72:
73: /**
74: * This method is called to terminate the processing.
75: */
76: public void terminate() {
77: state.terminate(true);
78: }
79: }
|