ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/rootfilter/CIWrapper.java
Revision: 1.11
Committed: Mon Nov 26 19:21:40 2001 UTC (22 years, 6 months ago) by tdb
Branch: MAIN
Branch point for: SERVER_PIRCBOT
Changes since 1.10: +21 -3 lines
Log Message:
Some error checking to handle client interfaces disconnecting without any
warning. In fact, this shouldn't happen, but it'd be nice if it was cleanly
dealt with :)

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 tdb 1.10 package uk.org.iscream.cms.server.rootfilter;
3 tdb 1.1
4     //---IMPORTS---
5 tdb 1.10 import uk.org.iscream.cms.server.core.*;
6     import uk.org.iscream.cms.server.componentmanager.*;
7     import uk.org.iscream.cms.server.clientinterface.*;
8     import uk.org.iscream.cms.server.util.*;
9 tdb 1.1
10     /**
11     * A ClientInterface wrapper - the CI objects are pushed data,
12     * yet data is pulled from the queue. This will sit inbetween
13     * for now, until the CI design is changed.
14     *
15 tdb 1.2 * @author $Author: tdb1 $
16 tdb 1.1 * @version $Id $
17     */
18     public class CIWrapper extends Thread {
19    
20     //---FINAL ATTRIBUTES---
21    
22     /**
23     * The current CVS revision of this class
24     */
25 tdb 1.11 public final String REVISION = "$Revision: 1.10 $";
26 tdb 1.1
27     //---STATIC METHODS---
28    
29     //---CONSTRUCTORS---
30    
31     /**
32     * Sets up the wrapper, with a single destination and a queue.
33     *
34     * @param destination the client interface to send the xml to
35     * @param queue a reference to a queue to use
36     */
37     public CIWrapper(ClientInterface destination, Queue queue){
38 tdb 1.7 // set the Thread name
39     setName("rootfilter.CIWrapper");
40    
41 tdb 1.1 _destination = destination;
42     _queue = queue;
43 tdb 1.5 _queueID = queue.getQueue();
44 tdb 1.1 }
45    
46     //---PUBLIC METHODS---
47    
48     /**
49     * start the thread and thus gets and sends data
50     */
51     public void run() {
52 tdb 1.3 String xml = null;
53 tdb 1.11 boolean run = true;
54     while(run) {
55     // get a line of XML from the queue
56 tdb 1.1 try {
57 tdb 1.6 xml = (String) _queue.get(_queueID);
58 tdb 1.1 }
59     catch (InvalidQueueException e) {
60     _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
61     }
62 tdb 1.11 // pass it on to the destination
63     try {
64     _destination.receiveXML(xml);
65     }
66     catch (org.omg.CORBA.COMM_FAILURE e) {
67     run = false;
68     _logger.write(toString(), Logger.ERROR, "Connection failure (COMM_FAILURE), client interface shutdown? : "+e);
69     }
70     catch (org.omg.CORBA.TRANSIENT e) {
71     run = false;
72     _logger.write(toString(), Logger.ERROR, "Connection failure (TRANSIENT), client interface shutdown? : "+e);
73     }
74 tdb 1.1 }
75 tdb 1.11 // looks like something when wrong in communication
76     // rather than fall over in a heap, lets just stop
77     // cleanly and shutdown our queue...
78     _logger.write(toString(), Logger.SYSMSG, "Shutting Down...");
79     _queue.removeQueue(_queueID);
80 tdb 1.1 }
81    
82     /**
83     * Overrides the {@link java.lang.Object#toString() Object.toString()}
84     * method to provide clean logging (every class should have this).
85     *
86 tdb 1.10 * This uses the uk.org.iscream.cms.server.util.NameFormat class
87 tdb 1.8 * to format the toString()
88     *
89 tdb 1.1 * @return the name of this class and its CVS revision
90     */
91     public String toString() {
92 tdb 1.8 return FormatName.getName(
93     _name,
94     getClass().getName(),
95     REVISION);
96 tdb 1.1 }
97    
98     //---PRIVATE METHODS---
99    
100     //---ACCESSOR/MUTATOR METHODS---
101    
102     //---ATTRIBUTES---
103    
104     /**
105     * A reference to a Queue object.
106     */
107     private Queue _queue;
108 tdb 1.5
109     /**
110     * Our Queue id.
111     */
112     private int _queueID;
113 tdb 1.1
114     /**
115     * the interface this thread is sending data to
116     */
117     private ClientInterface _destination;
118    
119     /**
120     * This is the friendly identifier of the
121     * component this class is running in.
122     * eg, a Filter may be called "filter1",
123     * If this class does not have an owning
124     * component, a name from the configuration
125     * can be placed here. This name could also
126     * be changed to null for utility classes.
127     */
128     private String _name = RootFilter.NAME;
129    
130     /**
131     * This holds a reference to the
132     * system logger that is being used.
133     */
134     private Logger _logger = ReferenceManager.getInstance().getLogger();
135    
136     //---STATIC ATTRIBUTES---
137    
138     }