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.14
Committed: Wed Feb 5 16:43:47 2003 UTC (21 years, 4 months ago) by tdb
Branch: MAIN
Changes since 1.13: +3 -3 lines
Log Message:
Changed the server to use the external util package. Quite a minor change,
but does affect a lot of files.

File Contents

# User Rev Content
1 tdb 1.12 /*
2     * i-scream central monitoring system
3 tdb 1.13 * http://www.i-scream.org.uk
4 tdb 1.12 * Copyright (C) 2000-2002 i-scream
5     *
6     * This program is free software; you can redistribute it and/or
7     * modify it under the terms of the GNU General Public License
8     * as published by the Free Software Foundation; either version 2
9     * of the License, or (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19     */
20    
21 tdb 1.1 //---PACKAGE DECLARATION---
22 tdb 1.10 package uk.org.iscream.cms.server.rootfilter;
23 tdb 1.1
24     //---IMPORTS---
25 tdb 1.10 import uk.org.iscream.cms.server.core.*;
26     import uk.org.iscream.cms.server.componentmanager.*;
27     import uk.org.iscream.cms.server.clientinterface.*;
28 tdb 1.14 import uk.org.iscream.cms.util.*;
29 tdb 1.1
30     /**
31     * A ClientInterface wrapper - the CI objects are pushed data,
32     * yet data is pulled from the queue. This will sit inbetween
33     * for now, until the CI design is changed.
34     *
35 tdb 1.12 * @author $Author: tdb $
36 tdb 1.1 * @version $Id $
37     */
38     public class CIWrapper extends Thread {
39    
40     //---FINAL ATTRIBUTES---
41    
42     /**
43     * The current CVS revision of this class
44     */
45 tdb 1.14 public final String REVISION = "$Revision: 1.13 $";
46 tdb 1.1
47     //---STATIC METHODS---
48    
49     //---CONSTRUCTORS---
50    
51     /**
52     * Sets up the wrapper, with a single destination and a queue.
53     *
54     * @param destination the client interface to send the xml to
55     * @param queue a reference to a queue to use
56     */
57     public CIWrapper(ClientInterface destination, Queue queue){
58 tdb 1.7 // set the Thread name
59     setName("rootfilter.CIWrapper");
60    
61 tdb 1.1 _destination = destination;
62     _queue = queue;
63 tdb 1.5 _queueID = queue.getQueue();
64 tdb 1.1 }
65    
66     //---PUBLIC METHODS---
67    
68     /**
69     * start the thread and thus gets and sends data
70     */
71     public void run() {
72 tdb 1.3 String xml = null;
73 tdb 1.11 boolean run = true;
74     while(run) {
75     // get a line of XML from the queue
76 tdb 1.1 try {
77 tdb 1.6 xml = (String) _queue.get(_queueID);
78 tdb 1.1 }
79     catch (InvalidQueueException e) {
80     _logger.write(toString(), Logger.ERROR, "Queue error: "+e);
81     }
82 tdb 1.11 // pass it on to the destination
83     try {
84     _destination.receiveXML(xml);
85     }
86     catch (org.omg.CORBA.COMM_FAILURE e) {
87     run = false;
88     _logger.write(toString(), Logger.ERROR, "Connection failure (COMM_FAILURE), client interface shutdown? : "+e);
89     }
90     catch (org.omg.CORBA.TRANSIENT e) {
91     run = false;
92     _logger.write(toString(), Logger.ERROR, "Connection failure (TRANSIENT), client interface shutdown? : "+e);
93     }
94 tdb 1.1 }
95 tdb 1.11 // looks like something when wrong in communication
96     // rather than fall over in a heap, lets just stop
97     // cleanly and shutdown our queue...
98     _logger.write(toString(), Logger.SYSMSG, "Shutting Down...");
99     _queue.removeQueue(_queueID);
100 tdb 1.1 }
101    
102     /**
103     * Overrides the {@link java.lang.Object#toString() Object.toString()}
104     * method to provide clean logging (every class should have this).
105     *
106 tdb 1.14 * This uses the uk.org.iscream.cms.util.NameFormat class
107 tdb 1.8 * to format the toString()
108     *
109 tdb 1.1 * @return the name of this class and its CVS revision
110     */
111     public String toString() {
112 tdb 1.8 return FormatName.getName(
113     _name,
114     getClass().getName(),
115     REVISION);
116 tdb 1.1 }
117    
118     //---PRIVATE METHODS---
119    
120     //---ACCESSOR/MUTATOR METHODS---
121    
122     //---ATTRIBUTES---
123    
124     /**
125     * A reference to a Queue object.
126     */
127     private Queue _queue;
128 tdb 1.5
129     /**
130     * Our Queue id.
131     */
132     private int _queueID;
133 tdb 1.1
134     /**
135     * the interface this thread is sending data to
136     */
137     private ClientInterface _destination;
138    
139     /**
140     * This is the friendly identifier of the
141     * component this class is running in.
142     * eg, a Filter may be called "filter1",
143     * If this class does not have an owning
144     * component, a name from the configuration
145     * can be placed here. This name could also
146     * be changed to null for utility classes.
147     */
148     private String _name = RootFilter.NAME;
149    
150     /**
151     * This holds a reference to the
152     * system logger that is being used.
153     */
154     private Logger _logger = ReferenceManager.getInstance().getLogger();
155    
156     //---STATIC ATTRIBUTES---
157    
158     }