KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > POAManagerMonitorImpl


1 package org.jacorb.poa;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1997-2004 Gerald Brose.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */

22
23 import org.jacorb.poa.gui.*;
24
25 import org.apache.avalon.framework.logger.Logger;
26 import org.apache.avalon.framework.configuration.*;
27
28
29 /**
30  * This class extends the POAManager with a monitoring gui for interacting
31  * with the POAManager and start and stop poa monitoring.
32  *
33  * @author Reimo Tiedemann, FU Berlin
34  * @version 1.05, 12/08/99, RT
35  */

36
37 public class POAManagerMonitorImpl
38     implements POAManagerMonitor, POAManagerMonitorController, Configurable
39 {
40     private POAManager model = null;
41     private POAManagerMonitorView view = null;
42
43     /** the configuration object for this POA instance */
44     private org.jacorb.config.Configuration configuration = null;
45     private Logger logger;
46
47     public void configure(Configuration myConfiguration)
48         throws ConfigurationException
49     {
50         this.configuration = (org.jacorb.config.Configuration)myConfiguration;
51         logger = configuration.getNamedLogger("jacorb.poa.manager_monitor");
52     }
53
54
55     public void actionClosePOAMonitor(String JavaDoc name)
56     {
57         if (model != null)
58         {
59             try
60             {
61                 printMessage("invoke \"closeMonitor()\" on POAMonitor "+name);
62                 model.getRegisteredPOA(reducePOAName(name)).getMonitor().closeMonitor();
63                 printMessage("closeMonitor() on POAMonitor "+name+" is returned successfully");
64             }
65             catch (Throwable JavaDoc e)
66             {
67                 printMessage("exception ocurred: "+e);
68             }
69         }
70     }
71
72     public void actionCloseView()
73     {
74         closeMonitor();
75     }
76
77     public void actionDestroyPOA(String JavaDoc name)
78     {
79         if (model != null)
80         {
81             try
82             {
83                 printMessage("invoke \"destroy()\" on POA "+name);
84                 model.getRegisteredPOA(reducePOAName(name)).destroy(true, true);
85                 printMessage("destroy() on POA "+name+" is returned successfully");
86             }
87             catch (Throwable JavaDoc e)
88             {
89                 printMessage("exception ocurred: "+e);
90             }
91         }
92     }
93     public void actionOpenPOAMonitor(String JavaDoc name) {
94         if (model != null) {
95             try {
96                 printMessage("invoke \"openMonitor()\" on POAMonitor "+name);
97                 model.getRegisteredPOA(reducePOAName(name)).getMonitor().openMonitor();
98                 printMessage("openMonitor() on POAMonitor "+name+" is returned successfully");
99             } catch (Throwable JavaDoc e) {
100                 printMessage("exception ocurred: "+e);
101             }
102         }
103     }
104     public void actionSetToActive() {
105         if (model != null) {
106             try {
107                 printMessage("invoke \"activate()\" on POAManager");
108                 model.activate();
109                 printMessage("activate() on POAManager is returned successfully");
110             } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc e) {
111                 printMessage("exception ocurred: "+e);
112                 resetState();
113             }
114         }
115     }
116     public void actionSetToDiscarding(boolean wait) {
117         if (model != null) {
118             try {
119                 printMessage("invoke \"discard_requests("+wait+")\" on POAManager");
120                 model.discard_requests(wait);
121                 printMessage("discard_requests("+wait+") on POAManager is returned successfully");
122             } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc e) {
123                 printMessage("exception ocurred: "+e);
124                 resetState();
125             }
126         }
127     }
128     public void actionSetToHolding(boolean wait) {
129         if (model != null) {
130             try {
131                 printMessage("invoke \"hold_requests("+wait+")\" on POAManager");
132                 model.hold_requests(wait);
133                 printMessage("hold_requests("+wait+") on POAManager is returned successfully");
134             } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc e) {
135                 printMessage("exception ocurred: "+e);
136                 resetState();
137             }
138         }
139     }
140     public void actionSetToInactive(boolean wait, boolean etherialize)
141     {
142         if (model != null)
143         {
144             try {
145                 printMessage("invoke \"deactivate("+etherialize+", "+wait+")\" on POAManager");
146                 model.deactivate(etherialize, wait);
147                 printMessage("deactivate("+etherialize+", "+wait+") on POAManager is returned successfully");
148             } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc e) {
149                 printMessage("exception ocurred: "+e);
150                 resetState();
151             }
152         }
153     }
154
155     public synchronized void addPOA(String JavaDoc name)
156     {
157         if (view != null)
158         {
159             try
160             {
161                 view._addPOA(expandPOAName(name));
162             }
163             catch (Throwable JavaDoc exception)
164             {
165                 if (logger.isErrorEnabled())
166                 {
167                     logger.error( "Exception in addPOA()" + exception.getMessage());
168                 }
169             }
170             printMessage("register POA "+name);
171         }
172     }
173
174     public synchronized void closeMonitor()
175     {
176         if (view != null)
177         {
178             try
179             {
180                 POAManagerMonitor newMonitor =
181                     (POAManagerMonitor)Class.forName("org.jacorb.poa.POAManagerMonitorImpl").newInstance();
182                 newMonitor.init(model);
183                 newMonitor.configure(configuration);
184                 model.setMonitor(newMonitor);
185                 POAManagerMonitorView tmp = view;
186                 view = null;
187                 tmp._destroy();
188             }
189             catch (Throwable JavaDoc exception)
190             {
191                 if (logger.isErrorEnabled())
192                 {
193                     logger.error( "Exception in closeMonitor" + exception.getMessage());
194                 }
195             }
196         }
197     }
198     private String JavaDoc expandPOAName(String JavaDoc name)
199     {
200         return name.equals("") ?
201             POAConstants.ROOT_POA_NAME :
202             POAConstants.ROOT_POA_NAME+POAConstants.OBJECT_KEY_SEPARATOR+name;
203     }
204
205     public void init(POAManager poaManager)
206     {
207         model = poaManager;
208     }
209
210     public synchronized void openMonitor()
211     {
212         try
213         {
214             view = new org.jacorb.poa.gui.pm.POAManagerFrame(this);
215             view._setVisible(true);
216         }
217         catch (Throwable JavaDoc exception)
218         {
219             if (logger.isErrorEnabled())
220             {
221                 logger.error( "Exception in openMonitor" + exception.getMessage());
222             }
223         }
224     }
225
226     public synchronized void printMessage(String JavaDoc str)
227     {
228         if (view != null) {
229             try
230             {
231                 view._printMessage(str);
232             }
233             catch (Throwable JavaDoc exception)
234             {
235                 if (logger.isErrorEnabled())
236                 {
237                     logger.error( "Exception int printMessage(): " + exception.getMessage());
238                 }
239             }
240         }
241     }
242
243     private String JavaDoc reducePOAName(String JavaDoc name)
244     {
245         return name.equals(POAConstants.ROOT_POA_NAME) ?
246             "" :
247             name.substring(POAConstants.ROOT_POA_NAME.length()+1);
248     }
249
250     public synchronized void removePOA(String JavaDoc name)
251     {
252         if (view != null)
253         {
254             try
255             {
256                 view._removePOA(expandPOAName(name));
257             }
258             catch (Throwable JavaDoc exception)
259             {
260                 if (logger.isErrorEnabled())
261                 {
262                     logger.error( "Exception in printMessage(): " + exception.getMessage());
263                 }
264             }
265             printMessage("unregister POA "+name);
266         }
267     }
268
269     protected synchronized void resetState() {
270         if (view != null)
271         {
272             try
273             {
274                 view._resetState();
275             }
276             catch (Throwable JavaDoc exception)
277             {
278                 if (logger.isErrorEnabled())
279                 {
280                     logger.error( "Exception in resetState(): " + exception.getMessage());
281                 }
282             }
283         }
284     }
285     public synchronized void setToActive()
286     {
287         if (view != null)
288         {
289             try
290             {
291                 view._setToActive();
292             }
293             catch (Throwable JavaDoc exception)
294             {
295                 if (logger.isErrorEnabled())
296                 {
297                     logger.error( "Exception in setToActive(): " + exception.getMessage());
298                 }
299             }
300             printMessage("POAManager is set to \"active\"");
301         }
302     }
303
304     public synchronized void setToDiscarding(boolean wait)
305     {
306         if (view != null)
307         {
308             try
309             {
310                 view._setToDiscarding(wait);
311             }
312             catch (Throwable JavaDoc exception)
313             {
314                 if (logger.isErrorEnabled())
315                 {
316                     logger.error( "Exception in setToActive(): " + exception.getMessage());
317                 }
318             }
319             printMessage("POAManager is set to \"discarding\"");
320         }
321     }
322
323     public synchronized void setToHolding(boolean wait)
324     {
325         if (view != null)
326         {
327             try
328             {
329                 view._setToHolding(wait);
330             }
331             catch (Throwable JavaDoc exception)
332             {
333                 if (logger.isErrorEnabled())
334                 {
335                     logger.error( "Exception in setToHolding(): " + exception.getMessage());
336                 }
337             }
338             printMessage("POAManager is set to \"holding\"");
339         }
340     }
341     public synchronized void setToInactive(boolean wait, boolean etherialize)
342     {
343         if (view != null)
344         {
345             try
346             {
347                 view._setToInactive(wait, etherialize);
348             }
349             catch (Throwable JavaDoc exception)
350             {
351                 if (logger.isErrorEnabled())
352                 {
353                     logger.error( "Exception in setToInactive(): " + exception.getMessage());
354                 }
355             }
356             printMessage("POAManager is set to \"inactive\"");
357         }
358     }
359 }
360
Popular Tags