| 1 |
/* |
| 2 |
* i-scream central monitoring system |
| 3 |
* http://www.i-scream.org.uk |
| 4 |
* 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 |
//---PACKAGE DECLARATION--- |
| 22 |
package uk.org.iscream.cms.server.rootfilter; |
| 23 |
|
| 24 |
//---IMPORTS--- |
| 25 |
import uk.org.iscream.cms.server.core.*; |
| 26 |
import uk.org.iscream.cms.server.componentmanager.*; |
| 27 |
import uk.org.iscream.cms.server.clientinterface.*; |
| 28 |
import uk.org.iscream.cms.util.*; |
| 29 |
|
| 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 |
* @author $Author: tdb $ |
| 36 |
* @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 |
public final String REVISION = "$Revision: 1.14 $"; |
| 46 |
|
| 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 |
// set the Thread name |
| 59 |
setName("rootfilter.CIWrapper"); |
| 60 |
|
| 61 |
_destination = destination; |
| 62 |
_queue = queue; |
| 63 |
_queueID = queue.getQueue(); |
| 64 |
} |
| 65 |
|
| 66 |
//---PUBLIC METHODS--- |
| 67 |
|
| 68 |
/** |
| 69 |
* start the thread and thus gets and sends data |
| 70 |
*/ |
| 71 |
public void run() { |
| 72 |
String xml = null; |
| 73 |
boolean run = true; |
| 74 |
while(run) { |
| 75 |
// get a line of XML from the queue |
| 76 |
try { |
| 77 |
xml = (String) _queue.get(_queueID); |
| 78 |
} |
| 79 |
catch (InvalidQueueException e) { |
| 80 |
_logger.write(toString(), Logger.ERROR, "Queue error: "+e); |
| 81 |
} |
| 82 |
// 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 |
} |
| 95 |
// 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 |
} |
| 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 |
* This uses the uk.org.iscream.cms.util.NameFormat class |
| 107 |
* to format the toString() |
| 108 |
* |
| 109 |
* @return the name of this class and its CVS revision |
| 110 |
*/ |
| 111 |
public String toString() { |
| 112 |
return FormatName.getName( |
| 113 |
_name, |
| 114 |
getClass().getName(), |
| 115 |
REVISION); |
| 116 |
} |
| 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 |
|
| 129 |
/** |
| 130 |
* Our Queue id. |
| 131 |
*/ |
| 132 |
private int _queueID; |
| 133 |
|
| 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 |
} |