KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > server > named > NamedServerImpl


1 /*
2  * MessageTest: This is a test message service library.
3  * Copyright (C) 2007 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
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 /**
34  * The named server implementation of the named server.
35  *
36  * @author Brett Chaldecott
37  */

38 public class NamedServerImpl implements NamedServer, BeanRunnable {
39
40     // private member variables
41
private ThreadStateMonitor state = new ThreadStateMonitor();
42     
43     /**
44      * Creates a new instance of NamedServer1
45      */

46     public NamedServerImpl() {
47     }
48     
49     
50     /**
51      * This method is called to perform the processing.
52      */

53     public void process() {
54         NamedQueueClient client = null;
55         try {
56             client = NamedQueueClient.create("test");
57         } catch (Exception JavaDoc 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 JavaDoc ex) {
69                 System.out.println("Failed to retrieve text message:"
70                         + ex.toString());
71             }
72         }
73     }
74     
75     
76     /**
77      * This method is called to terminate the processing.
78      */

79     public void terminate() {
80         state.terminate(true);
81     }
82 }
83
Popular Tags