ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/clientinterface/CorbaControlHandlerServant.java
Revision: 1.18
Committed: Mon May 5 22:05:06 2003 UTC (21 years ago) by tdb
Branch: MAIN
Changes since 1.17: +2 -4 lines
Log Message:
Tidy up of the client interface code - more commonly known as the
"right hand side of the server". Right since the start the filter
side of the server has been nice and tree like - every Filter sent
data to another Filter. At the top of the tree there was a "special"
Filter known as the RootFilter, which to the other Filters just
looked like a normal Filter. This was nice, and simple, and expandable.

The Client Interface on the other hand was messy. The root filter
had some hacky wrapper threads which pulled from a queue and pushed
to the relevant client interfaces (one for real time stuff, and the
other for databases). There was no simple room for expandability -
it was all hardwired to do just what was needed at the time.

This commit changes that. A Client Interface now connects to another
Client Interface, with a special one being found in the RootFilter
(yes, maybe that needs a name change now :-). So we can chain client
interfaces, and move other bits and bobs around in the server - for
example, alerting no longer needs to be connected to the Client
Interface, it can connect straight to the RootFilter (or, wherever
the config tells it ;).

Hopefully this sanitizes the underlying layout of the server a bit.

As a final note, I dropped the DBInterface. This used to insert
data in to a MySQL database. We've long since stopped using that,
and it's fallen behind and is way out of date. For now, it's gone
in to the attic.

File Contents

# Content
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.clientinterface;
23
24 //---IMPORTS---
25 import uk.org.iscream.cms.util.*;
26 import uk.org.iscream.cms.server.componentmanager.*;
27 import uk.org.iscream.cms.server.core.*;
28
29
30 /**
31 * Acts as a Control Handler to a CORBA based client.
32 *
33 * @author $Author: tdb $
34 * @version $Id: CorbaControlHandlerServant.java,v 1.17 2003/02/05 16:43:46 tdb Exp $
35 */
36 class CorbaControlHandlerServant extends CorbaControlHandlerPOA {
37
38 //---FINAL ATTRIBUTES---
39
40 /**
41 * The current CVS revision of this class
42 */
43 public final String REVISION = "$Revision: 1.17 $";
44
45 //---STATIC METHODS---
46
47 //---CONSTRUCTORS---
48
49 /**
50 * Construct a new CorbaControlHandlerServant.
51 *
52 * @param packetSorter A reference to the PacketSorter in the component
53 * @param client A reference to the "servant" part of the connecting client.
54 * @param clientname A name to identify the client.
55 */
56 public CorbaControlHandlerServant(PacketSorter packetSorter, Client client, String clientname) {
57 _packetSorter = packetSorter;
58 _hostList = "";
59 _client = client;
60 _clientname = clientname;
61 _dataHandler = null;
62 _logger.write(toString(), Logger.SYSINIT, "created");
63 }
64
65 //---PUBLIC METHODS---
66
67 /**
68 * Start sending data to the client.
69 *
70 * @return a boolean stating whether the attempt to start succeeded
71 */
72 public boolean startData() {
73 if(_dataHandler == null) {
74 // create a new DataHandler
75 CorbaDataHandler dh = new CorbaDataHandler(_client, this);
76 // register the Queue
77 _packetSorter.register(dh.getQueue(), _hostList);
78 try {
79 // startup a monitor on the DataHandler's queue
80 ConfigurationProxy cp = ConfigurationProxy.getInstance();
81 int queueMonitorInterval = Integer.parseInt(cp.getProperty("ClientInterface", "Queue.MonitorInterval"));
82 String queueName = _name + " CorbaHandler:"+_clientname;
83 dh.getQueue().startMonitor(queueMonitorInterval*1000, _packetSorter.getQueue(), queueName);
84 } catch (PropertyNotFoundException e) {
85 _logger.write(toString(), Logger.WARNING, "failed to find queue monitor config, disabling. " + e);
86 }
87 // start the DataHandler running
88 dh.start();
89 // keep a reference
90 _dataHandler = dh;
91 return true;
92 }
93 else {
94 return false;
95 }
96 }
97
98 /**
99 * Stop sending data to the client.
100 *
101 * @return a boolean stating whether the attempt to stop succeeded
102 */
103 public boolean stopData() {
104 if(_dataHandler != null) {
105 // deregister the Queue
106 _packetSorter.deregister(_dataHandler.getQueue(), _hostList);
107 // stop the DataHandler
108 _dataHandler.shutdown();
109 // destroy the reference
110 _dataHandler = null;
111 return true;
112 }
113 else {
114 return false;
115 }
116 }
117
118 /**
119 * Sets the host list for the Client to the requested semi-colon separated
120 * list of hostnames. This will only succeed if we are not sending data.
121 *
122 * @param hostList A semi-colon separated list of hostnames to use.
123 * @return Whether the request succeeded.
124 */
125 public boolean setHostList(String hostList) {
126 if(_dataHandler == null) {
127 _hostList = hostList;
128 return true;
129 }
130 else {
131 return false;
132 }
133 }
134
135 /**
136 * Disconnect, this will shutdown the data and unhook from
137 * the CORBA ORB.
138 */
139 public void disconnect() {
140 // close the data handler
141 stopData();
142 // disconnect from the ORB
143 try {
144 byte[] oid = _refman.getRootPOA().servant_to_id(this);
145 _refman.getRootPOA().deactivate_object(oid);
146 } catch(Exception e) {
147 _logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e);
148 }
149 }
150
151 /**
152 * Overrides the {@link java.lang.Object#toString() Object.toString()}
153 * method to provide clean logging (every class should have this).
154 *
155 * This uses the uk.org.iscream.cms.util.NameFormat class
156 * to format the toString()
157 *
158 * @return the name of this class and its CVS revision
159 */
160 public String toString() {
161 return FormatName.getName(
162 _name,
163 getClass().getName(),
164 REVISION);
165 }
166
167 //---PRIVATE METHODS---
168
169 /**
170 * Overridden for debugging purposes
171 * to see when an instance of this class
172 * is destroyed
173 */
174 protected void finalize() throws Throwable {
175 _logger.write(this.toString(), Logger.DEBUG, "finalized by GC");
176 }
177
178 //---ACCESSOR/MUTATOR METHODS---
179
180 //---ATTRIBUTES---
181
182 /**
183 * This is the friendly identifier of the
184 * component this class is running in.
185 * eg, a Filter may be called "filter1",
186 * If this class does not have an owning
187 * component, a name from the configuration
188 * can be placed here. This name could also
189 * be changed to null for utility classes.
190 */
191 private String _name = ClientInterfaceMain.NAME;
192
193 /**
194 * This holds a reference to the
195 * system logger that is being used.
196 */
197 private Logger _logger = ReferenceManager.getInstance().getLogger();
198
199 /**
200 * A reference to the reference manager in use
201 */
202 private ReferenceManager _refman = ReferenceManager.getInstance();
203
204 /**
205 * A reference to the PacketSorter.
206 */
207 private PacketSorter _packetSorter;
208
209 /**
210 * The host list the Client has requested
211 */
212 private String _hostList;
213
214 /**
215 * The "servant" part of the client we're connected to.
216 */
217 private Client _client;
218
219 /**
220 * A reference to our DataHandler, if we have one
221 */
222 private CorbaDataHandler _dataHandler;
223
224 /**
225 * A name to identify the client
226 */
227 private String _clientname;
228
229 //---STATIC ATTRIBUTES---
230
231 }