KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > ORBMonitoring


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.iiop;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.logging.*;
27
28 import org.omg.CORBA.ORB JavaDoc;
29
30 import com.sun.enterprise.server.ApplicationServer;
31 import com.sun.enterprise.server.ServerContext;
32
33 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry;
34 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistrationException;
35
36 import com.sun.enterprise.admin.monitor.stats.OrbConnectionManagerStats;
37 import com.sun.enterprise.admin.monitor.stats.ThreadPoolStats;
38
39 import com.sun.corba.ee.spi.monitoring.MonitoringConstants;
40 import com.sun.corba.ee.spi.monitoring.MonitoringFactories;
41 import com.sun.corba.ee.spi.monitoring.MonitoringManager;
42 import com.sun.corba.ee.spi.monitoring.MonitoredObject;
43
44 import com.sun.logging.*;
45
46
47 /**
48  * This file provides for the registration of the ThreadPool
49  * and orb connection statistics capture.
50  *
51  * @author Pramod Gopinath
52  */

53
54
55 public class ORBMonitoring {
56     static Logger _logger=LogDomains.getLogger(LogDomains.UTIL_LOGGER);
57
58     private ORB JavaDoc orb;
59     private MonitoringRegistry registry;
60
61     public ORBMonitoring(ORB JavaDoc orb) {
62         this.orb = orb;
63         registry = ApplicationServer.getServerContext().getMonitoringRegistry();
64         registerOrbStatistics();
65     }
66
67     public void registerOrbStatistics() {
68
69         registerThreadPoolStats();
70         registerORBConnectionStats();
71     }
72
73     /**
74      * This method is called to register the thread pool stats
75      * For each threadpool create an object that would be registerd with the
76      * admin framework.
77      *
78      */

79     private void registerThreadPoolStats() {
80         Iterator JavaDoc threadPoolsIterator;
81     MonitoredObject threadPoolRoot =
82         MonitoringFactories.getMonitoringManagerFactory().createMonitoringManager(
83         MonitoringConstants.DEFAULT_MONITORING_ROOT, null ).
84         getRootMonitoredObject();
85
86         try {
87             MonitoredObject rootThreadPoolNode = threadPoolRoot.getChild(
88                    MonitoringConstants.THREADPOOL_MONITORING_ROOT );
89
90             threadPoolsIterator = rootThreadPoolNode.getChildren().iterator();
91         } catch( Exception JavaDoc ex ) {
92             _logger.log( Level.WARNING,
93                 "Unexpected exception caught when accessing ThreadPool Stats:", ex );
94             return;
95         }
96
97         while( threadPoolsIterator.hasNext() ) {
98             MonitoredObject threadPool = (MonitoredObject) threadPoolsIterator.next();
99
100             try {
101                 ThreadPoolStats threadPoolStats =
102                     new ThreadPoolStatsImpl( threadPool );
103
104                 registry.registerThreadPoolStats( threadPoolStats,
105             threadPoolRoot.getName() +
106                     "." + MonitoringConstants.THREADPOOL_MONITORING_ROOT +
107                      "." + threadPool.getName(),
108                     null );
109             } catch( MonitoringRegistrationException mex ) {
110                 //TODO: localize these messages
111
_logger.log( Level.WARNING,
112                     "Unable to register ThreadPoolStats due to following exception ", mex );
113             } catch( Exception JavaDoc ex ) {
114                 //TODO: localize these messages
115
_logger.log( Level.WARNING,
116                     "Unexpected exception caught when registring ThreadPoolStats", ex );
117             }
118         }
119     }// registerThreadPoolStats()
120

121
122     /**
123      * This method is called to register the orb connection manager stats
124      * For each connection create an object that would be registerd with the
125      * admin framework.
126      *
127      */

128     private void registerORBConnectionStats() {
129         Iterator JavaDoc outboundConnectionListIterator;
130         Iterator JavaDoc inboundConnectionListIterator;
131
132         try {
133         com.sun.corba.ee.spi.orb.ORB internalORB =
134         (com.sun.corba.ee.spi.orb.ORB)orb ;
135         MonitoredObject orbRoot =
136         internalORB.getMonitoringManager().getRootMonitoredObject() ;
137
138             MonitoredObject rootConnectionNode =
139                 orbRoot.getChild( MonitoringConstants.CONNECTION_MONITORING_ROOT );
140     
141             MonitoredObject rootOutboundConnections =
142                 rootConnectionNode.getChild(
143                     MonitoringConstants.OUTBOUND_CONNECTION_MONITORING_ROOT );
144             MonitoredObject rootInboundConnections =
145                 rootConnectionNode.getChild(
146                     MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT );
147              
148             if( rootOutboundConnections != null ) {
149                 outboundConnectionListIterator =
150                     rootOutboundConnections.getChildren().iterator();
151
152                 while( outboundConnectionListIterator.hasNext() ) {
153                     MonitoredObject outboundConnection =
154                         (MonitoredObject) outboundConnectionListIterator.next();
155
156                     try {
157                         OrbConnectionManagerStats connectionManagerStats =
158                             new OrbConnectionManagerStatsImpl( outboundConnection );
159
160                         registry.registerOrbConnectionManagerStats( connectionManagerStats,
161                 orbRoot.getName() +
162                             "." + MonitoringConstants.CONNECTION_MONITORING_ROOT +
163                             "." + MonitoringConstants.OUTBOUND_CONNECTION_MONITORING_ROOT +
164                             "." + outboundConnection.getName(),
165                             null );
166
167                     } catch( MonitoringRegistrationException mex ) {
168                         //TODO: localize these messages
169
_logger.log( Level.WARNING,
170                             "Unable to register Outbound ORB Connections - ", mex );
171                     } catch( Exception JavaDoc ex ) {
172                         //TODO: localize these messages
173
_logger.log( Level.WARNING,
174                             "Unexpected exception caught when registering Outbound ORB Connections", ex );
175                     }
176                 }
177             }
178
179             if( rootInboundConnections != null ) {
180                 inboundConnectionListIterator =
181                     rootInboundConnections.getChildren().iterator();
182
183                 while( inboundConnectionListIterator.hasNext() ) {
184                     MonitoredObject inboundConnection =
185                         (MonitoredObject) inboundConnectionListIterator.next();
186         
187                     try {
188                         OrbConnectionManagerStats connectionManagerStats =
189                             new OrbConnectionManagerStatsImpl( inboundConnection );
190         
191                         registry.registerOrbConnectionManagerStats( connectionManagerStats,
192                 orbRoot.getName() +
193                             "." + MonitoringConstants.CONNECTION_MONITORING_ROOT +
194                             "." + MonitoringConstants.INBOUND_CONNECTION_MONITORING_ROOT +
195                             "." + inboundConnection.getName(),
196                             null );
197                     } catch( MonitoringRegistrationException mex ) {
198                         //TODO: localize these messages
199
_logger.log( Level.WARNING,
200                             "Unable to register Inbound ORB Connections - ", mex );
201                     } catch( Exception JavaDoc ex ) {
202                         //TODO: localize these messages
203
_logger.log( Level.WARNING,
204                             "Unexpected exception caught when registering Inbound ORB Connections", ex );
205                     }
206                 } //while()
207
} //if()
208

209         } catch( Exception JavaDoc ex ) {
210             _logger.log( Level.WARNING,
211                 "Unexpected exception caught when accessing ORB Connection Stats:", ex );
212             return;
213         }
214
215
216     } //registerORBConnectionStats()
217

218 } //ORBMonitoring{}
219
Popular Tags