|
Line 0
Link Here
|
|
|
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 1998, 2010 Oracle. All rights reserved. |
| 3 |
* This program and the accompanying materials are made available under the |
| 4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
| 5 |
* which accompanies this distribution. |
| 6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* and the Eclipse Distribution License is available at |
| 8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
| 9 |
* |
| 10 |
* Contributors: |
| 11 |
* @author mobrien |
| 12 |
* @since EclipseLink 2.2 enh# 316511 |
| 13 |
* 06/22/2010-2.2 Michael O'Brien |
| 14 |
* - 316511: Add JBoss specific JMX MBean attributes and functions |
| 15 |
* see <link>http://wiki.eclipse.org/EclipseLink/DesignDocs/316513</link> |
| 16 |
******************************************************************************/ |
| 17 |
package org.eclipse.persistence.services.jboss; |
| 18 |
|
| 19 |
import java.util.ArrayList; |
| 20 |
import java.util.Collections; |
| 21 |
import java.util.Enumeration; |
| 22 |
import java.util.HashMap; |
| 23 |
import java.util.Hashtable; |
| 24 |
import java.util.Iterator; |
| 25 |
import java.util.Locale; |
| 26 |
import java.util.Map; |
| 27 |
import java.util.StringTokenizer; |
| 28 |
import java.util.Vector; |
| 29 |
import java.util.regex.PatternSyntaxException; |
| 30 |
|
| 31 |
import javax.management.openmbean.CompositeData; |
| 32 |
import javax.management.openmbean.CompositeDataSupport; |
| 33 |
import javax.management.openmbean.CompositeType; |
| 34 |
import javax.management.openmbean.OpenDataException; |
| 35 |
import javax.management.openmbean.OpenType; |
| 36 |
import javax.management.openmbean.SimpleType; |
| 37 |
import javax.management.openmbean.TabularData; |
| 38 |
import javax.management.openmbean.TabularDataSupport; |
| 39 |
import javax.management.openmbean.TabularType; |
| 40 |
|
| 41 |
|
| 42 |
import org.eclipse.persistence.descriptors.ClassDescriptor; |
| 43 |
import org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor; |
| 44 |
import org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform; |
| 45 |
import org.eclipse.persistence.internal.helper.ClassConstants; |
| 46 |
import org.eclipse.persistence.internal.helper.Helper; |
| 47 |
import org.eclipse.persistence.internal.identitymaps.CacheIdentityMap; |
| 48 |
import org.eclipse.persistence.internal.identitymaps.CacheKey; |
| 49 |
import org.eclipse.persistence.internal.identitymaps.FullIdentityMap; |
| 50 |
import org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap; |
| 51 |
import org.eclipse.persistence.internal.identitymaps.IdentityMap; |
| 52 |
import org.eclipse.persistence.internal.identitymaps.NoIdentityMap; |
| 53 |
import org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap; |
| 54 |
import org.eclipse.persistence.internal.identitymaps.SoftIdentityMap; |
| 55 |
import org.eclipse.persistence.internal.identitymaps.WeakIdentityMap; |
| 56 |
import org.eclipse.persistence.internal.sessions.AbstractSession; |
| 57 |
import org.eclipse.persistence.internal.sessions.DatabaseSessionImpl; |
| 58 |
import org.eclipse.persistence.logging.AbstractSessionLog; |
| 59 |
import org.eclipse.persistence.logging.DefaultSessionLog; |
| 60 |
import org.eclipse.persistence.logging.JavaLog; |
| 61 |
import org.eclipse.persistence.logging.SessionLog; |
| 62 |
import org.eclipse.persistence.platform.server.jboss.JBossPlatform; |
| 63 |
import org.eclipse.persistence.platform.server.wls.WebLogicPlatform; |
| 64 |
import org.eclipse.persistence.services.RuntimeServices; |
| 65 |
import org.eclipse.persistence.sessions.DatabaseLogin; |
| 66 |
import org.eclipse.persistence.sessions.DefaultConnector; |
| 67 |
import org.eclipse.persistence.sessions.server.ConnectionPool; |
| 68 |
import org.eclipse.persistence.sessions.server.ServerSession; |
| 69 |
import org.eclipse.persistence.tools.profiler.PerformanceProfiler; |
| 70 |
|
| 71 |
/** |
| 72 |
* <p> |
| 73 |
* <b>Purpose</b>: Provide a dynamic interface into the EclipseLink Session. |
| 74 |
* <p> |
| 75 |
* <b>Description</b>: This class is meant to provide facilities for managing an EclipseLink session external |
| 76 |
* to EclipseLink over JMX. |
| 77 |
*/ |
| 78 |
public class JBossRuntimeServices extends RuntimeServices { |
| 79 |
|
| 80 |
/** |
| 81 |
* PUBLIC: |
| 82 |
* Default Constructor |
| 83 |
*/ |
| 84 |
public JBossRuntimeServices() { |
| 85 |
super(); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* PUBLIC: |
| 90 |
* Create an instance of WebLogicRuntimeServices to be associated with the provided session |
| 91 |
* |
| 92 |
* @param session The session to be used with these RuntimeServices |
| 93 |
* @param String myBaseObjectName: "weblogic:....." (The JMX object name before it's wrapped in a ObjectName) |
| 94 |
*/ |
| 95 |
public JBossRuntimeServices(AbstractSession session) { |
| 96 |
super(); |
| 97 |
this.session = session; |
| 98 |
this.updateDeploymentTimeData(); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Create an instance of WebLogicRuntimeServices to be associated with the provided locale |
| 103 |
* |
| 104 |
* The user must call setSession(Session) afterwards to define the session. |
| 105 |
*/ |
| 106 |
public JBossRuntimeServices(Locale locale) { |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* INTERNAL: |
| 111 |
* Define the session that this instance is providing runtime services for |
| 112 |
* |
| 113 |
* @param Session session The session to be used with these RuntimeServices |
| 114 |
*/ |
| 115 |
protected void setSession(AbstractSession newSession) { |
| 116 |
this.session = newSession; |
| 117 |
this.updateDeploymentTimeData(); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Answer the name of the EclipseLink session this MBean represents. |
| 122 |
*/ |
| 123 |
public String getSessionName() { |
| 124 |
return getSession().getName(); |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Answer the type of the EclipseLink session this MBean represents. |
| 129 |
* Types include: "ServerSession", "DatabaseSession", "SessionBroker" |
| 130 |
*/ |
| 131 |
public String getSessionType() { |
| 132 |
return Helper.getShortClassName(getSession().getClass()); |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Provide an instance of 2 Dimensional Array simulating tabular format information about all |
| 137 |
* classes in the session whose class names match the provided filter. |
| 138 |
* |
| 139 |
* The 2 Dimensional array contains each item with values being row object array. Each row object array |
| 140 |
* represents EclipseLink class details info with respect to below attributes: |
| 141 |
* ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 142 |
* |
| 143 |
*/ |
| 144 |
public Object[][] getClassSummaryDetailsUsingFilter(String filter){ |
| 145 |
try{ |
| 146 |
return tabularDataTo2DArray(buildClassSummaryDetailsUsingFilter(filter),new String[] { |
| 147 |
"Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size" }); |
| 148 |
} catch (Exception exception) { |
| 149 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", exception); |
| 150 |
} |
| 151 |
return null; |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* Provide a list of instance of ClassSummaryDetail containing information about the |
| 156 |
* classes in the session whose class names match the provided filter. |
| 157 |
* |
| 158 |
* ClassSummaryDetail is a model specific class that can be used internally by the Portable JMX Framework to |
| 159 |
* convert class attribute to JMX required open type, it has:- |
| 160 |
* 1. model specific type that needs to be converted : ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 161 |
* 2. convert methods. |
| 162 |
* |
| 163 |
* @param filter A comma separated list of strings to match against. |
| 164 |
* @return A ArrayList of instance of ClassSummaryDetail containing class information for the class names that match the filter. |
| 165 |
*/ |
| 166 |
public ArrayList <ClassSummaryDetail> getClassSummaryDetailsUsingFilterArray(String filter) { |
| 167 |
// if the filter is null, return all the details |
| 168 |
if (filter == null) { |
| 169 |
return getClassSummaryDetailsArray(); |
| 170 |
} |
| 171 |
|
| 172 |
try { |
| 173 |
Vector mappedClassNames = getMappedClassNamesUsingFilter(filter); |
| 174 |
String mappedClassName; |
| 175 |
ArrayList classSummaryDetails = new ArrayList<ClassSummaryDetail>(); |
| 176 |
// Check if there aren't any classes mapped |
| 177 |
if (mappedClassNames.size() == 0) { |
| 178 |
return null; |
| 179 |
} |
| 180 |
|
| 181 |
// get details for each class, and add the details to the summary |
| 182 |
for (int index = 0; index < mappedClassNames.size(); index++) { |
| 183 |
mappedClassName = (String)mappedClassNames.elementAt(index); |
| 184 |
classSummaryDetails.add(buildLowlevelDetailsFor(mappedClassName)); |
| 185 |
} |
| 186 |
return classSummaryDetails; |
| 187 |
} catch (Exception openTypeException) { |
| 188 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", openTypeException); |
| 189 |
openTypeException.printStackTrace(); |
| 190 |
} |
| 191 |
|
| 192 |
// wait to get requirements from EM |
| 193 |
return null; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* Provide a list of instance of ClassSummaryDetail containing information about all |
| 198 |
* classes in the session. |
| 199 |
* |
| 200 |
* ClassSummaryDetail is a model specific class that can be used internally by the Portable JMX Framework to |
| 201 |
* convert class attribute to JMX required open type, it has:- |
| 202 |
* 1. model specific type that needs to be converted : ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 203 |
* 2. convert methods. |
| 204 |
* |
| 205 |
* @return A ArrayList of instance of ClassSummaryDetail containing class information for the class names that match the filter. |
| 206 |
*/ |
| 207 |
public ArrayList <ClassSummaryDetail> getClassSummaryDetailsArray() { |
| 208 |
try { |
| 209 |
Vector mappedClassNames = getMappedClassNames(); |
| 210 |
ArrayList classSummaryDetails = new ArrayList<ClassSummaryDetail>(); |
| 211 |
// Check if there aren't any classes mapped |
| 212 |
if (mappedClassNames.size() == 0) { |
| 213 |
return null; |
| 214 |
} |
| 215 |
|
| 216 |
// get details for each class, and add the details to the summary |
| 217 |
for (int index = 0; index < mappedClassNames.size(); index++) { |
| 218 |
String mappedClassName = (String)mappedClassNames.elementAt(index); |
| 219 |
classSummaryDetails.add(buildLowlevelDetailsFor(mappedClassName)); |
| 220 |
} |
| 221 |
|
| 222 |
return classSummaryDetails; |
| 223 |
} catch (Exception openTypeException) { |
| 224 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", openTypeException); |
| 225 |
openTypeException.printStackTrace(); |
| 226 |
} |
| 227 |
|
| 228 |
// wait to get requirements from EM |
| 229 |
return null; |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* PUBLIC: Provide an instance of 2 Dimensional Array simulating tabular format information about all |
| 234 |
* classes in the session. |
| 235 |
* |
| 236 |
* The 2 Dimensional array contains each item with values being row object array. Each row object array |
| 237 |
* represents EclipseLink class details info with respect to below attributes: |
| 238 |
* ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 239 |
* |
| 240 |
*/ |
| 241 |
public Object[][] getClassSummaryDetails() { |
| 242 |
try{ |
| 243 |
return tabularDataTo2DArray(buildClassSummaryDetails(),new String[] { |
| 244 |
"Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size" }); |
| 245 |
} catch (Exception exception){ |
| 246 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", exception); |
| 247 |
} |
| 248 |
return null; |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* INTERNAL: |
| 253 |
* Provide an instance of TabularData containing information about the |
| 254 |
* classes in the session whose class names match the provided filter. |
| 255 |
* |
| 256 |
* The TabularData contains rowData with values being CompositeData(s) |
| 257 |
* |
| 258 |
* CompositeData has: |
| 259 |
* CompositeType: column names are ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 260 |
* |
| 261 |
* Each CompositeData can have get(myColumnName) sent to it. |
| 262 |
* |
| 263 |
* |
| 264 |
* @param filter A comma separated list of strings to match against. |
| 265 |
* @return A TabularData of information for the class names that match the filter. |
| 266 |
*/ |
| 267 |
private TabularData buildClassSummaryDetailsUsingFilter(String filter) { |
| 268 |
// if the filter is null, return all the details |
| 269 |
if (filter == null) { |
| 270 |
return buildClassSummaryDetails(); |
| 271 |
} |
| 272 |
|
| 273 |
try { |
| 274 |
Vector mappedClassNames = getMappedClassNamesUsingFilter(filter); |
| 275 |
String mappedClassName; |
| 276 |
TabularDataSupport rowData = new TabularDataSupport(buildTabularTypeForClassSummaryDetails()); |
| 277 |
// Check if there aren't any classes mapped |
| 278 |
if (mappedClassNames.size() == 0) { |
| 279 |
return null; |
| 280 |
} |
| 281 |
|
| 282 |
// get details for each class, and add the details to the summary |
| 283 |
for (int index = 0; index < mappedClassNames.size(); index++) { |
| 284 |
mappedClassName = (String)mappedClassNames.elementAt(index); |
| 285 |
String[] key = new String[] { mappedClassName }; |
| 286 |
rowData.put(key, buildDetailsFor(mappedClassName, rowData.getTabularType().getRowType())); |
| 287 |
} |
| 288 |
return rowData; |
| 289 |
} catch (Exception exception) { |
| 290 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", exception); |
| 291 |
} |
| 292 |
|
| 293 |
// wait to get requirements from EM |
| 294 |
return null; |
| 295 |
} |
| 296 |
|
| 297 |
/** |
| 298 |
* INTERNAL: |
| 299 |
* Provide an instance of TabularData containing information about all |
| 300 |
* classes in the session. |
| 301 |
* |
| 302 |
* The TabularData contains rowData with values being CompositeData(s) |
| 303 |
* |
| 304 |
* CompositeData has: |
| 305 |
* CompositeType: column names are ["Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size"] |
| 306 |
* |
| 307 |
* Each CompositeData can have get(myColumnName) sent to it. |
| 308 |
* |
| 309 |
*/ |
| 310 |
private TabularData buildClassSummaryDetails() { |
| 311 |
try { |
| 312 |
Vector mappedClassNames = getMappedClassNames(); |
| 313 |
String mappedClassName; |
| 314 |
TabularDataSupport rowData = new TabularDataSupport(buildTabularTypeForClassSummaryDetails()); |
| 315 |
// Check if there aren't any classes mapped |
| 316 |
if (mappedClassNames.size() == 0) { |
| 317 |
return null; |
| 318 |
} |
| 319 |
|
| 320 |
// get details for each class, and add the details to the summary |
| 321 |
for (int index = 0; index < mappedClassNames.size(); index++) { |
| 322 |
mappedClassName = (String)mappedClassNames.elementAt(index); |
| 323 |
String[] key = new String[] { mappedClassName }; |
| 324 |
rowData.put(key, buildDetailsFor(mappedClassName, rowData.getTabularType().getRowType())); |
| 325 |
} |
| 326 |
|
| 327 |
return rowData; |
| 328 |
} catch (Exception exception) { |
| 329 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", exception); |
| 330 |
} |
| 331 |
|
| 332 |
// wait to get requirements from EM |
| 333 |
return null; |
| 334 |
} |
| 335 |
|
| 336 |
/** |
| 337 |
* INTERNAL: |
| 338 |
* Answer the fully qualified names of the classes mapped in the session. |
| 339 |
* This uses the mappedClass from the CMPPolicy. |
| 340 |
* |
| 341 |
* @return java.util.Vector |
| 342 |
*/ |
| 343 |
|
| 344 |
private Vector getMappedClassNames() { |
| 345 |
Hashtable alreadyAdded = new Hashtable(); |
| 346 |
Vector mappedClassNames = new Vector(); |
| 347 |
String mappedClassName = null; |
| 348 |
|
| 349 |
Iterator descriptorsIterator = getSession().getProject().getDescriptors() |
| 350 |
.values().iterator(); |
| 351 |
while (descriptorsIterator.hasNext()) { |
| 352 |
ClassDescriptor nextDescriptor = (ClassDescriptor) descriptorsIterator.next(); |
| 353 |
|
| 354 |
// differentiate between a generated class and not, by comparing the descriptor's Java class |
| 355 |
if (nextDescriptor.getCMPPolicy() != null) { |
| 356 |
if (nextDescriptor.getCMPPolicy().getMappedClass() != null) { |
| 357 |
mappedClassName = nextDescriptor.getCMPPolicy().getMappedClass().getName(); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
if (mappedClassName == null) { |
| 362 |
mappedClassName = nextDescriptor.getJavaClassName(); |
| 363 |
} |
| 364 |
if (alreadyAdded.get(mappedClassName) == null) { |
| 365 |
alreadyAdded.put(mappedClassName, Boolean.TRUE); |
| 366 |
mappedClassNames.addElement(mappedClassName); |
| 367 |
} |
| 368 |
mappedClassName = null; |
| 369 |
} |
| 370 |
return mappedClassNames; |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* INTERNAL: |
| 375 |
* This method traverses the EclipseLink descriptors and returns a Vector of the descriptor's |
| 376 |
* reference class names that match the provided filter. The filter is a comma separated |
| 377 |
* list of strings to match against. |
| 378 |
* |
| 379 |
* @param filter A comma separated list of strings to match against. |
| 380 |
* @return A Vector of class names that match the filter. |
| 381 |
*/ |
| 382 |
public Vector getMappedClassNamesUsingFilter(String filter) { |
| 383 |
//Output Vector |
| 384 |
Vector outputVector = new Vector(); |
| 385 |
|
| 386 |
//Input mapped class names |
| 387 |
Vector mappedClassNames = getMappedClassNames(); |
| 388 |
|
| 389 |
//Input filter values |
| 390 |
ArrayList filters = new ArrayList(); |
| 391 |
StringTokenizer lineTokens = new StringTokenizer(filter, ","); |
| 392 |
while (lineTokens.hasMoreTokens()) { |
| 393 |
filters.add(lineTokens.nextToken()); |
| 394 |
} |
| 395 |
for (int i = 0; i < mappedClassNames.size(); i++) { |
| 396 |
String className = (String)mappedClassNames.get(i); |
| 397 |
String classNameLowerCase = ((String)mappedClassNames.get(i)).toLowerCase(); |
| 398 |
for (int j = 0; j < filters.size(); j++) { |
| 399 |
String filterValue = (Helper.rightTrimString((String)filters.get(j)).trim()).toLowerCase(); |
| 400 |
if (filterValue.indexOf('*') == 0) { |
| 401 |
filterValue = filterValue.substring(1); |
| 402 |
} |
| 403 |
try { |
| 404 |
//Note: String.matches(String regex) since jdk1.4 |
| 405 |
if (classNameLowerCase.matches(new StringBuffer().append("^.*").append(filterValue).append(".*$").toString())) { |
| 406 |
if (!outputVector.contains(className)) { |
| 407 |
outputVector.add(className); |
| 408 |
} |
| 409 |
} |
| 410 |
} catch (PatternSyntaxException exception) { |
| 411 |
//regular expression syntax error |
| 412 |
AbstractSessionLog.getLog().log(SessionLog.FINEST, "pattern_syntax_error", exception); |
| 413 |
} |
| 414 |
} |
| 415 |
} |
| 416 |
Collections.sort(outputVector); |
| 417 |
return outputVector; |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* INTERNAL: |
| 422 |
* Answer the TabularType describing the TabularData that we return from |
| 423 |
* getCacheSummaryDetails() and getCacheSummaryDetails(String filter) |
| 424 |
* |
| 425 |
* This is mostly for the client side to see what kind of information is returned. |
| 426 |
* |
| 427 |
* @return javax.management.openmbean.TabularType |
| 428 |
*/ |
| 429 |
private TabularType buildTabularTypeForClassSummaryDetails() throws OpenDataException { |
| 430 |
return new TabularType(getSessionName(), "Session description", buildCompositeTypeForClassSummaryDetails(), |
| 431 |
new String[] { "Class Name" }); |
| 432 |
} |
| 433 |
|
| 434 |
/** |
| 435 |
* INTERNAL: |
| 436 |
* Answer the CompositeType describing the CompositeData that we return for |
| 437 |
* each IdentityMap (or subclass). |
| 438 |
* |
| 439 |
* This is mostly for the client side to see what kind of information is returned. |
| 440 |
* @return javax.management.openmbean.CompositeType |
| 441 |
*/ |
| 442 |
private CompositeType buildCompositeTypeForClassSummaryDetails() throws OpenDataException { |
| 443 |
return new CompositeType("Class Details", "Details of class for Class Summary", new String[] { |
| 444 |
"Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size" }, new String[] { |
| 445 |
"Class Name", "Parent Class Name", "Cache Type", "Configured Size", "Current Size" }, new OpenType[] { |
| 446 |
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING }); |
| 447 |
} |
| 448 |
|
| 449 |
/** |
| 450 |
* INTERNAL: |
| 451 |
* Answer the CompositeData containing the cache details for the given mappedClassName |
| 452 |
* This uses a CompositeDataSupport, which implements CompositeData |
| 453 |
* |
| 454 |
* @param String mappedClassName: fullyQualified class name of the class |
| 455 |
* @param CompositeType detailsType: describes the format of the returned CompositeData |
| 456 |
|
| 457 |
* @return javax.management.openmbean.CompositeData |
| 458 |
*/ |
| 459 |
private CompositeData buildDetailsFor(String mappedClassName, CompositeType detailsType) throws Exception { |
| 460 |
return new CompositeDataSupport(detailsType, buildLowlevelDetailsFor(mappedClassName)); |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* INTERNAL: |
| 465 |
* Helper to build a HashMap to help in the construction of a CompositeData |
| 466 |
* |
| 467 |
* @param String mappedClassName: fullyQualified class name of the class |
| 468 |
|
| 469 |
* @return HashMap |
| 470 |
*/ |
| 471 |
private HashMap buildLowlevelDetailsFor(String mappedClassName) { |
| 472 |
Class mappedClass = (Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(mappedClassName, ClassConstants.CLASS); |
| 473 |
IdentityMap identityMap = getSession().getIdentityMapAccessorInstance().getIdentityMap(mappedClass); |
| 474 |
ClassDescriptor descriptor = getSession().getProject().getDescriptor(mappedClass); |
| 475 |
|
| 476 |
String cacheType = getCacheTypeFor(identityMap.getClass()); |
| 477 |
String configuredSize = "" + identityMap.getMaxSize(); |
| 478 |
String currentSize = ""; |
| 479 |
|
| 480 |
//show the current size, including subclasses |
| 481 |
currentSize = "" + identityMap.getSize(mappedClass, true); |
| 482 |
|
| 483 |
String parentClassName = ""; |
| 484 |
|
| 485 |
boolean isChildDescriptor = descriptor.isChildDescriptor(); |
| 486 |
|
| 487 |
HashMap details = new HashMap(); |
| 488 |
|
| 489 |
details.put("Class Name", mappedClassName); |
| 490 |
details.put("Cache Type", (isChildDescriptor ? "" : cacheType)); |
| 491 |
details.put("Configured Size", (isChildDescriptor ? "" : configuredSize)); |
| 492 |
details.put("Current Size", currentSize); |
| 493 |
//If I have a parent class name, get it. Otherwise, leave blank |
| 494 |
if (descriptor.hasInheritance()) { |
| 495 |
if (descriptor.getInheritancePolicy().getParentDescriptor() != null) { |
| 496 |
parentClassName = descriptor.getInheritancePolicy().getParentClassName(); |
| 497 |
} |
| 498 |
} |
| 499 |
details.put("Parent Class Name", parentClassName); |
| 500 |
|
| 501 |
return details; |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* INTERNAL: |
| 506 |
* Helper to build a HashMap to help in the construction of a CompositeData |
| 507 |
* |
| 508 |
* @param String mappedClassName: fullyQualified class name of the class |
| 509 |
|
| 510 |
* @return HashMap |
| 511 |
*/ |
| 512 |
private ClassSummaryDetail buildLowlevelDetailsForNew(String mappedClassName) { |
| 513 |
Class mappedClass = (Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(mappedClassName, ClassConstants.CLASS); |
| 514 |
IdentityMap identityMap = getSession().getIdentityMapAccessorInstance().getIdentityMap(mappedClass); |
| 515 |
ClassDescriptor descriptor = getSession().getProject().getDescriptor(mappedClass); |
| 516 |
|
| 517 |
String cacheType = getCacheTypeFor(identityMap.getClass()); |
| 518 |
String configuredSize = "" + identityMap.getMaxSize(); |
| 519 |
String currentSize = ""; |
| 520 |
|
| 521 |
//show the current size, including subclasses |
| 522 |
currentSize = "" + identityMap.getSize(mappedClass, true); |
| 523 |
|
| 524 |
String parentClassName = ""; |
| 525 |
|
| 526 |
boolean isChildDescriptor = descriptor.isChildDescriptor(); |
| 527 |
|
| 528 |
ClassSummaryDetail details = new ClassSummaryDetail( |
| 529 |
mappedClassName, |
| 530 |
(isChildDescriptor ? "" : cacheType), |
| 531 |
(isChildDescriptor ? "" : configuredSize), |
| 532 |
currentSize, |
| 533 |
parentClassName); |
| 534 |
|
| 535 |
return details; |
| 536 |
} |
| 537 |
|
| 538 |
/** |
| 539 |
* INTERNAL: |
| 540 |
* getCacheTypeFor: Give a more UI-friendly version of the cache type |
| 541 |
*/ |
| 542 |
private String getCacheTypeFor(Class identityMapClass) { |
| 543 |
if (identityMapClass == CacheIdentityMap.class) { |
| 544 |
return "Cache"; |
| 545 |
} else if (identityMapClass == FullIdentityMap.class) { |
| 546 |
return "Full"; |
| 547 |
} else if (identityMapClass == HardCacheWeakIdentityMap.class) { |
| 548 |
return "HardWeak"; |
| 549 |
} else if (identityMapClass == NoIdentityMap.class) { |
| 550 |
return "None"; |
| 551 |
} else if (identityMapClass == SoftCacheWeakIdentityMap.class) { |
| 552 |
return "SoftWeak"; |
| 553 |
} else if (identityMapClass == WeakIdentityMap.class) { |
| 554 |
return "Weak"; |
| 555 |
} else if (identityMapClass == SoftIdentityMap.class) { |
| 556 |
return "Soft"; |
| 557 |
} |
| 558 |
return "N/A"; |
| 559 |
} |
| 560 |
|
| 561 |
/** |
| 562 |
* getModuleName(): Answer the name of the context-root of the application that this session is associated with. |
| 563 |
* Answer "unknown" if there is no module name available. |
| 564 |
* Default behavior is to return "unknown" |
| 565 |
*/ |
| 566 |
public String getModuleName() { |
| 567 |
return ((DatabaseSessionImpl)getSession()) |
| 568 |
.getServerPlatform().getModuleName(); |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
/** |
| 573 |
* getApplicationName(): Answer the name of the module (EAR name) that this session is associated with. |
| 574 |
* Answer "unknown" if there is no application name available. |
| 575 |
* Default behavior is to return "unknown" |
| 576 |
*/ |
| 577 |
public String getApplicationName() { |
| 578 |
return ((JBossPlatform)((DatabaseSessionImpl)getSession()) |
| 579 |
.getServerPlatform()).getApplicationName(); |
| 580 |
} |
| 581 |
|
| 582 |
/** |
| 583 |
* PUBLIC: Answer the EclipseLink log level at deployment time. This is read-only. |
| 584 |
*/ |
| 585 |
public String getDeployedEclipseLinkLogLevel() { |
| 586 |
return getNameForLogLevel(getDeployedSessionLog().getLevel()); |
| 587 |
} |
| 588 |
|
| 589 |
/** |
| 590 |
* PUBLIC: Answer the EclipseLink log level that is changeable. |
| 591 |
* This does not affect the log level in the project (i.e. The next |
| 592 |
* time the application is deployed, changes are forgotten) |
| 593 |
*/ |
| 594 |
public String getCurrentEclipseLinkLogLevel() { |
| 595 |
return getNameForLogLevel(this.getSession().getSessionLog().getLevel()); |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* PUBLIC: Set the EclipseLink log level to be used at runtime. |
| 600 |
* |
| 601 |
* This does not affect the log level in the project (i.e. The next |
| 602 |
* time the application is deployed, changes are forgotten) |
| 603 |
* |
| 604 |
* @param String newLevel: new log level |
| 605 |
*/ |
| 606 |
public synchronized void setCurrentEclipseLinkLogLevel(String newLevel) { |
| 607 |
this.getSession().setLogLevel(this.getLogLevelForName(newLevel)); |
| 608 |
} |
| 609 |
|
| 610 |
/** |
| 611 |
* INTERNAL: Answer the name for the log level given. |
| 612 |
* |
| 613 |
* @return String (one of OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL) |
| 614 |
*/ |
| 615 |
private String getNameForLogLevel(int logLevel) { |
| 616 |
switch (logLevel) { |
| 617 |
case SessionLog.ALL: |
| 618 |
return SessionLog.ALL_LABEL; |
| 619 |
case SessionLog.SEVERE: |
| 620 |
return SessionLog.SEVERE_LABEL; |
| 621 |
case SessionLog.WARNING: |
| 622 |
return SessionLog.WARNING_LABEL; |
| 623 |
case SessionLog.INFO: |
| 624 |
return SessionLog.INFO_LABEL; |
| 625 |
case SessionLog.CONFIG: |
| 626 |
return SessionLog.CONFIG_LABEL; |
| 627 |
case SessionLog.FINE: |
| 628 |
return SessionLog.FINE_LABEL; |
| 629 |
case SessionLog.FINER: |
| 630 |
return SessionLog.FINER_LABEL; |
| 631 |
case SessionLog.FINEST: |
| 632 |
return SessionLog.FINEST_LABEL; |
| 633 |
case SessionLog.OFF: |
| 634 |
return SessionLog.OFF_LABEL; |
| 635 |
} |
| 636 |
return "N/A"; |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* INTERNAL: Answer the log level for the given name. |
| 641 |
* |
| 642 |
* @return int for OFF, SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL |
| 643 |
*/ |
| 644 |
private int getLogLevelForName(String levelName) { |
| 645 |
if (levelName.equals(SessionLog.ALL_LABEL)) { |
| 646 |
return SessionLog.ALL; |
| 647 |
} |
| 648 |
if (levelName.equals(SessionLog.SEVERE_LABEL)) { |
| 649 |
return SessionLog.SEVERE; |
| 650 |
} |
| 651 |
if (levelName.equals(SessionLog.WARNING_LABEL)) { |
| 652 |
return SessionLog.WARNING; |
| 653 |
} |
| 654 |
if (levelName.equals(SessionLog.INFO_LABEL)) { |
| 655 |
return SessionLog.INFO; |
| 656 |
} |
| 657 |
if (levelName.equals(SessionLog.CONFIG_LABEL)) { |
| 658 |
return SessionLog.CONFIG; |
| 659 |
} |
| 660 |
if (levelName.equals(SessionLog.FINE_LABEL)) { |
| 661 |
return SessionLog.FINE; |
| 662 |
} |
| 663 |
if (levelName.equals(SessionLog.FINER_LABEL)) { |
| 664 |
return SessionLog.FINER; |
| 665 |
} |
| 666 |
if (levelName.equals(SessionLog.FINEST_LABEL)) { |
| 667 |
return SessionLog.FINEST; |
| 668 |
} |
| 669 |
return SessionLog.OFF; |
| 670 |
} |
| 671 |
|
| 672 |
/** |
| 673 |
* Method returns if all Parameters should be bound or not |
| 674 |
*/ |
| 675 |
public Boolean getShouldBindAllParameters() { |
| 676 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 677 |
return Boolean.FALSE; |
| 678 |
} |
| 679 |
return Boolean.valueOf(((DatabaseLogin)getSession().getDatasourceLogin()).shouldBindAllParameters()); |
| 680 |
} |
| 681 |
|
| 682 |
/** |
| 683 |
* Return the size of strings after which will be bound into the statement |
| 684 |
* If we are not using a DatabaseLogin, or we're not using string binding, |
| 685 |
* answer 0 (zero). |
| 686 |
*/ |
| 687 |
public Integer getStringBindingSize() { |
| 688 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 689 |
return Integer.valueOf(0); |
| 690 |
} |
| 691 |
if (!((DatabaseLogin)getSession().getDatasourceLogin()).getPlatform().usesStringBinding()) { |
| 692 |
return Integer.valueOf(0); |
| 693 |
} |
| 694 |
return Integer.valueOf(((DatabaseLogin)getSession().getDatasourceLogin()).getStringBindingSize()); |
| 695 |
} |
| 696 |
|
| 697 |
/** |
| 698 |
* This method will return if batchWriting is in use or not. |
| 699 |
*/ |
| 700 |
public Boolean getUsesBatchWriting() { |
| 701 |
return Boolean.valueOf(getSession().getDatasourceLogin().getPlatform().usesBatchWriting()); |
| 702 |
} |
| 703 |
|
| 704 |
/** |
| 705 |
* This method will return a long indicating the exact time in Milliseconds that the |
| 706 |
* session connected to the database. |
| 707 |
*/ |
| 708 |
public Long getTimeConnectionEstablished() { |
| 709 |
return Long.valueOf(((DatabaseSessionImpl)getSession()).getConnectedTime()); |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* This method will return if batchWriting is in use or not. |
| 714 |
*/ |
| 715 |
public Boolean getUsesJDBCBatchWriting() { |
| 716 |
return Boolean.valueOf(getSession().getDatasourceLogin().getPlatform().usesJDBCBatchWriting()); |
| 717 |
} |
| 718 |
|
| 719 |
/** |
| 720 |
* Shows if Byte Array Binding is turned on or not |
| 721 |
*/ |
| 722 |
public Boolean getUsesByteArrayBinding() { |
| 723 |
return Boolean.valueOf(getSession().getDatasourceLogin().getPlatform().usesByteArrayBinding()); |
| 724 |
} |
| 725 |
|
| 726 |
/** |
| 727 |
* Shows if native SQL is being used |
| 728 |
*/ |
| 729 |
public Boolean getUsesNativeSQL() { |
| 730 |
return Boolean.valueOf(getSession().getDatasourceLogin().getPlatform().usesNativeSQL()); |
| 731 |
} |
| 732 |
|
| 733 |
/** |
| 734 |
* This method indicates if streams are being used for binding |
| 735 |
*/ |
| 736 |
public Boolean getUsesStreamsForBinding() { |
| 737 |
return Boolean.valueOf(getSession().getDatasourceLogin().getPlatform().usesStreamsForBinding()); |
| 738 |
} |
| 739 |
|
| 740 |
/** |
| 741 |
* This method indicates if Strings are being bound |
| 742 |
*/ |
| 743 |
public Boolean getUsesStringBinding() { |
| 744 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 745 |
return Boolean.FALSE; |
| 746 |
} |
| 747 |
return Boolean.valueOf(((DatabaseLogin)getSession().getDatasourceLogin()).getPlatform().usesStringBinding()); |
| 748 |
} |
| 749 |
|
| 750 |
/** |
| 751 |
* Returns if statements should be cached or not |
| 752 |
*/ |
| 753 |
public boolean getShouldCacheAllStatements() { |
| 754 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 755 |
return Boolean.FALSE; |
| 756 |
} |
| 757 |
return Boolean.valueOf(((DatabaseLogin)getSession().getDatasourceLogin()).shouldCacheAllStatements()); |
| 758 |
} |
| 759 |
|
| 760 |
/** |
| 761 |
* Returns the statement cache size. Only valid if statements are being cached |
| 762 |
*/ |
| 763 |
public int getStatementCacheSize() { |
| 764 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 765 |
return 0; |
| 766 |
} |
| 767 |
return Integer.valueOf(((DatabaseLogin)getSession().getDatasourceLogin()).getStatementCacheSize()); |
| 768 |
} |
| 769 |
|
| 770 |
/** |
| 771 |
* Used to clear the statement cache. Only valid if statements are being cached |
| 772 |
*/ |
| 773 |
public synchronized void clearStatementCache() { |
| 774 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 775 |
return; |
| 776 |
} |
| 777 |
((DatabaseAccessor)getSession().getAccessor()).clearStatementCache(getSession()); |
| 778 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_statement_cache_cleared"); |
| 779 |
|
| 780 |
} |
| 781 |
|
| 782 |
/** |
| 783 |
* Method returns the value of the Sequence Preallocation size |
| 784 |
*/ |
| 785 |
public int getSequencePreallocationSize() { |
| 786 |
if (!(getSession().getDatasourceLogin() instanceof DatabaseLogin)) { |
| 787 |
return 0; |
| 788 |
} |
| 789 |
return ((DatasourcePlatform)getSession().getDatasourcePlatform()).getSequencePreallocationSize(); |
| 790 |
} |
| 791 |
|
| 792 |
/** |
| 793 |
* This method will print the available Connection pools to the SessionLog. |
| 794 |
* @return void |
| 795 |
*/ |
| 796 |
public void printAvailableConnectionPools() { |
| 797 |
if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { |
| 798 |
Map pools = ((ServerSession)getSession()).getConnectionPools(); |
| 799 |
Iterator poolNames = pools.keySet().iterator(); |
| 800 |
while (poolNames.hasNext()) { |
| 801 |
String poolName = poolNames.next().toString(); |
| 802 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_pool_name", poolName); |
| 803 |
} |
| 804 |
} else { |
| 805 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_connection_pools_available"); |
| 806 |
|
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
/** |
| 811 |
* This method will retrieve the max size of a particular connection pool |
| 812 |
* @param poolName the name of the pool to get the max size for |
| 813 |
* @return Integer for the max size of the pool. Return -1 if pool doesn't exist. |
| 814 |
*/ |
| 815 |
public Integer getMaxSizeForPool(String poolName) { |
| 816 |
if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { |
| 817 |
ConnectionPool connectionPool = ((ServerSession)getSession()).getConnectionPool(poolName); |
| 818 |
if (connectionPool != null) { |
| 819 |
return Integer.valueOf(connectionPool.getMaxNumberOfConnections()); |
| 820 |
} |
| 821 |
} |
| 822 |
return Integer.valueOf(-1); |
| 823 |
} |
| 824 |
|
| 825 |
/** |
| 826 |
* This method will retrieve the min size of a particular connection pool |
| 827 |
* @param poolName the name of the pool to get the min size for |
| 828 |
* @return Integer for the min size of the pool. Return -1 if pool doesn't exist. |
| 829 |
*/ |
| 830 |
public Integer getMinSizeForPool(String poolName) { |
| 831 |
if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { |
| 832 |
ConnectionPool connectionPool = ((ServerSession)getSession()).getConnectionPool(poolName); |
| 833 |
if (connectionPool != null) { |
| 834 |
return Integer.valueOf(connectionPool.getMinNumberOfConnections()); |
| 835 |
} |
| 836 |
} |
| 837 |
return Integer.valueOf(-1); |
| 838 |
} |
| 839 |
|
| 840 |
/** |
| 841 |
* This method is used to reset connections from the session to the database. Please |
| 842 |
* Note that this will not work with a SessionBroker at this time |
| 843 |
*/ |
| 844 |
public synchronized void resetAllConnections() { |
| 845 |
if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { |
| 846 |
Iterator enumtr = ((ServerSession)getSession()).getConnectionPools().values().iterator(); |
| 847 |
while (enumtr.hasNext()) { |
| 848 |
ConnectionPool pool = (ConnectionPool)enumtr.next(); |
| 849 |
pool.shutDown(); |
| 850 |
pool.startUp(); |
| 851 |
} |
| 852 |
} else if (ClassConstants.PublicInterfaceDatabaseSession_Class.isAssignableFrom(getSession().getClass())) { |
| 853 |
getSession().getAccessor().reestablishConnection(getSession()); |
| 854 |
} |
| 855 |
} |
| 856 |
|
| 857 |
/** |
| 858 |
* This method is used to output those Class Names that have identity Maps in the Session. |
| 859 |
* Please note that SubClasses and aggregates will be missing from this list as they do not have |
| 860 |
* separate identity maps. |
| 861 |
* @return void |
| 862 |
*/ |
| 863 |
public void printClassesInSession() { |
| 864 |
Vector classes = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); |
| 865 |
int index; |
| 866 |
if (classes.isEmpty()) { |
| 867 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_classes_in_session"); |
| 868 |
return; |
| 869 |
} |
| 870 |
|
| 871 |
for (index = 0; index < classes.size(); index++) { |
| 872 |
getSession().getSessionLog().log(SessionLog.FINEST, (String)classes.elementAt(index)); |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* This method will log the objects in the Identity Map. |
| 878 |
* There is no particular order to these objects. |
| 879 |
* @param className the fully qualified classname identifying the identity map |
| 880 |
* @exception thrown then the IdentityMap for that class name could not be found |
| 881 |
*/ |
| 882 |
public void printObjectsInIdentityMap(String className) throws ClassNotFoundException { |
| 883 |
Class classWithMap = (Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS); |
| 884 |
IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(classWithMap); |
| 885 |
|
| 886 |
//check if the identity map exists |
| 887 |
if (null == map) { |
| 888 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_non_existent", className); |
| 889 |
return; |
| 890 |
} |
| 891 |
|
| 892 |
//check if there are any objects in the identity map. Print if so. |
| 893 |
Enumeration objects = map.keys(); |
| 894 |
if (!objects.hasMoreElements()) { |
| 895 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_empty", className); |
| 896 |
} |
| 897 |
|
| 898 |
CacheKey cacheKey; |
| 899 |
while (objects.hasMoreElements()) { |
| 900 |
cacheKey = (CacheKey)objects.nextElement(); |
| 901 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_print_cache_key_value", |
| 902 |
cacheKey.getKey().toString(), cacheKey.getObject().toString()); |
| 903 |
} |
| 904 |
} |
| 905 |
|
| 906 |
/** |
| 907 |
* This method will log the types of Identity Maps in the session. |
| 908 |
*/ |
| 909 |
public void printAllIdentityMapTypes() { |
| 910 |
Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); |
| 911 |
String registeredClassName; |
| 912 |
Class registeredClass; |
| 913 |
|
| 914 |
//Check if there aren't any classes registered |
| 915 |
if (classesRegistered.size() == 0) { |
| 916 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_identity_maps_in_session"); |
| 917 |
return; |
| 918 |
} |
| 919 |
|
| 920 |
//get each identity map, and log the type |
| 921 |
for (int index = 0; index < classesRegistered.size(); index++) { |
| 922 |
registeredClassName = (String)classesRegistered.elementAt(index); |
| 923 |
registeredClass = (Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(registeredClassName, ClassConstants.CLASS); |
| 924 |
IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(registeredClass); |
| 925 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_class", |
| 926 |
registeredClassName, map.getClass()); |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
/** |
| 931 |
* This method will log all objects in all Identity Maps in the session. |
| 932 |
*/ |
| 933 |
public void printObjectsInIdentityMaps() { |
| 934 |
Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); |
| 935 |
String registeredClassName; |
| 936 |
|
| 937 |
//Check if there aren't any classes registered |
| 938 |
if (classesRegistered.size() == 0) { |
| 939 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_identity_maps_in_session"); |
| 940 |
return; |
| 941 |
} |
| 942 |
|
| 943 |
//get each identity map, and log the type |
| 944 |
for (int index = 0; index < classesRegistered.size(); index++) { |
| 945 |
registeredClassName = (String)classesRegistered.elementAt(index); |
| 946 |
try { |
| 947 |
this.printObjectsInIdentityMap(registeredClassName); |
| 948 |
} catch (ClassNotFoundException classNotFound) { |
| 949 |
//we are enumerating registered classes, so this shouldn't happen. Print anyway |
| 950 |
classNotFound.printStackTrace(); |
| 951 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", classNotFound); |
| 952 |
} |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
/** |
| 957 |
* This method is used to return the number of objects in a particular Identity Map |
| 958 |
* @param className the fully qualified name of the class to get number of instances of. |
| 959 |
* @exception thrown then the IdentityMap for that class name could not be found |
| 960 |
*/ |
| 961 |
public Integer getNumberOfObjectsInIdentityMap(String className) throws ClassNotFoundException { |
| 962 |
//BUG 3982060: Always use the root class in combination with the identity map's getSize(class, true) to get an accurate count |
| 963 |
Class classWithIdentityMap = (Class)getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS); |
| 964 |
Class rootClass = null; |
| 965 |
|
| 966 |
ClassDescriptor descriptor = getSession().getDescriptor(classWithIdentityMap); |
| 967 |
ClassDescriptor rootDescriptor; |
| 968 |
|
| 969 |
if (descriptor.hasInheritance()) { |
| 970 |
rootDescriptor = descriptor.getInheritancePolicy().getRootParentDescriptor(); |
| 971 |
} else { |
| 972 |
rootDescriptor = descriptor; |
| 973 |
} |
| 974 |
if (rootDescriptor.getCMPPolicy() != null) { |
| 975 |
if (rootDescriptor.getCMPPolicy().getMappedClass() != null) { |
| 976 |
rootClass = rootDescriptor.getCMPPolicy().getMappedClass(); |
| 977 |
} |
| 978 |
} |
| 979 |
|
| 980 |
if (rootClass == null) { |
| 981 |
rootClass = rootDescriptor.getJavaClass(); |
| 982 |
} |
| 983 |
|
| 984 |
return Integer.valueOf(getSession().getIdentityMapAccessorInstance().getIdentityMap(rootClass).getSize(rootClass, true)); |
| 985 |
} |
| 986 |
|
| 987 |
/** |
| 988 |
* This method will SUM and return the number of objects in all Identity Maps in the session. |
| 989 |
*/ |
| 990 |
public Integer getNumberOfObjectsInAllIdentityMaps() { |
| 991 |
Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); |
| 992 |
String registeredClassName; |
| 993 |
int sum = 0; |
| 994 |
|
| 995 |
//Check if there aren't any classes registered |
| 996 |
if (classesRegistered.size() == 0) { |
| 997 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_identity_maps_in_session"); |
| 998 |
return Integer.valueOf(0); |
| 999 |
} |
| 1000 |
|
| 1001 |
//get each identity map, and log the size |
| 1002 |
for (int index = 0; index < classesRegistered.size(); index++) { |
| 1003 |
registeredClassName = (String)classesRegistered.elementAt(index); |
| 1004 |
try { |
| 1005 |
sum += this.getNumberOfObjectsInIdentityMap(registeredClassName).intValue(); |
| 1006 |
} catch (ClassNotFoundException classNotFound) { |
| 1007 |
//we are enumerating registered classes, so this shouldn't happen. Print anyway |
| 1008 |
classNotFound.printStackTrace(); |
| 1009 |
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "weblogic_mbean_runtime_exception", classNotFound); |
| 1010 |
} |
| 1011 |
} |
| 1012 |
|
| 1013 |
return Integer.valueOf(sum); |
| 1014 |
} |
| 1015 |
|
| 1016 |
/** |
| 1017 |
* This method will answer the number of persistent classes contained in the session. |
| 1018 |
* This does not include aggregates. |
| 1019 |
*/ |
| 1020 |
public Integer getNumberOfPersistentClasses() { |
| 1021 |
Hashtable classesTable = new Hashtable(); |
| 1022 |
ClassDescriptor currentDescriptor; |
| 1023 |
|
| 1024 |
//use a table to eliminate duplicate classes. Ignore Aggregates |
| 1025 |
Iterator descriptors = getSession().getProject().getDescriptors().values().iterator(); |
| 1026 |
while (descriptors.hasNext()) { |
| 1027 |
currentDescriptor = (ClassDescriptor)descriptors.next(); |
| 1028 |
if (!currentDescriptor.isAggregateDescriptor()) { |
| 1029 |
classesTable.put(currentDescriptor.getJavaClassName(), Boolean.TRUE); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
return Integer.valueOf(classesTable.size()); |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
/** |
| 1038 |
* Return the log type, either "EclipseLink", "Java" or the simple name of the logging class used. |
| 1039 |
* |
| 1040 |
* @return the log type |
| 1041 |
*/ |
| 1042 |
public String getLogType() { |
| 1043 |
if (this.getSession().getSessionLog().getClass() == JavaLog.class) { |
| 1044 |
return "Java"; |
| 1045 |
} else if (this.getSession().getSessionLog().getClass() == DefaultSessionLog.class) { |
| 1046 |
return EclipseLink_Product_Name; |
| 1047 |
} else { |
| 1048 |
return this.getSession().getSessionLog().getClass().getSimpleName(); |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
/** |
| 1053 |
* Return the database platform used by the DatabaseSession. |
| 1054 |
* |
| 1055 |
* @return String databasePlatform |
| 1056 |
*/ |
| 1057 |
public String getDatabasePlatform() { |
| 1058 |
return getSession().getDatasourcePlatform().getClass().getName(); |
| 1059 |
} |
| 1060 |
|
| 1061 |
/** |
| 1062 |
* Return JDBCConnection detail information. This includes URL and datasource information. |
| 1063 |
*/ |
| 1064 |
public synchronized String getJdbcConnectionDetails() { |
| 1065 |
return getSession().getLogin().getConnector().getConnectionDetails(); |
| 1066 |
} |
| 1067 |
|
| 1068 |
/** |
| 1069 |
* Return connection pool type. Values include: "Internal", "External" and "N/A". |
| 1070 |
*/ |
| 1071 |
public synchronized String getConnectionPoolType() { |
| 1072 |
if (getSession().getLogin().shouldUseExternalConnectionPooling()) { |
| 1073 |
return "External"; |
| 1074 |
} else { |
| 1075 |
return "N/A"; |
| 1076 |
} |
| 1077 |
} |
| 1078 |
|
| 1079 |
/** |
| 1080 |
* Return db driver class name. This only applies to DefaultConnector. Return "N/A" otherwise. |
| 1081 |
*/ |
| 1082 |
public synchronized String getDriver() { |
| 1083 |
if (getSession().getLogin().getConnector() instanceof DefaultConnector) { |
| 1084 |
return getSession().getLogin().getDriverClassName(); |
| 1085 |
} |
| 1086 |
return "N/A"; |
| 1087 |
} |
| 1088 |
|
| 1089 |
/** |
| 1090 |
* Return the log filename. This returns the fully qualified path of the log file when |
| 1091 |
* EclipseLink DefaultSessionLog instance is used. Null is returned otherwise. |
| 1092 |
* |
| 1093 |
* @return String logFilename |
| 1094 |
*/ |
| 1095 |
public String getLogFilename() { |
| 1096 |
// returns String or null. |
| 1097 |
if ( session.getSessionLog() instanceof DefaultSessionLog) { |
| 1098 |
return ((DefaultSessionLog)session.getSessionLog()).getWriterFilename(); |
| 1099 |
} else { |
| 1100 |
return null; |
| 1101 |
} |
| 1102 |
} |
| 1103 |
|
| 1104 |
/** |
| 1105 |
* This method is used to initialize the identity maps in the session. |
| 1106 |
*/ |
| 1107 |
public synchronized void initializeAllIdentityMaps() { |
| 1108 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
| 1109 |
} |
| 1110 |
|
| 1111 |
/** |
| 1112 |
* This method is used to initialize the identity maps specified by the Vector of classNames. |
| 1113 |
* |
| 1114 |
* @param classNames String[] of fully qualified classnames identifying the identity maps to initialize |
| 1115 |
*/ |
| 1116 |
public synchronized void initializeIdentityMaps(String[] classNames) throws ClassNotFoundException { |
| 1117 |
for (int index = 0; index < classNames.length; index++) { |
| 1118 |
initializeIdentityMap(classNames[index]); |
| 1119 |
} |
| 1120 |
} |
| 1121 |
|
| 1122 |
/** |
| 1123 |
* This method is used to invalidate the identity maps in the session. |
| 1124 |
*/ |
| 1125 |
public synchronized void invalidateAllIdentityMaps() { |
| 1126 |
Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); |
| 1127 |
String registeredClassName; |
| 1128 |
Class registeredClass; |
| 1129 |
|
| 1130 |
if (classesRegistered.isEmpty()) { |
| 1131 |
getSession().getSessionLog().info("There are no Identity Maps in this session"); |
| 1132 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_identity_maps_in_session"); |
| 1133 |
} |
| 1134 |
|
| 1135 |
//get each identity map, and invalidate |
| 1136 |
for (int index = 0; index < classesRegistered.size(); index++) { |
| 1137 |
registeredClassName = (String)classesRegistered.elementAt(index); |
| 1138 |
registeredClass = (Class)getSession().getDatasourcePlatform().getConversionManager() |
| 1139 |
.convertObject(registeredClassName, ClassConstants.CLASS); |
| 1140 |
getSession().getIdentityMapAccessor().invalidateClass(registeredClass); |
| 1141 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_invalidated", registeredClassName); |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
/** |
| 1146 |
* This method is used to invalidate the identity maps specified by the String[] of classNames. |
| 1147 |
* |
| 1148 |
* @param classNames String[] of fully qualified classnames identifying the identity maps to invalidate |
| 1149 |
* @param recurse Boolean indicating if we want to invalidate the children identity maps too |
| 1150 |
*/ |
| 1151 |
public synchronized void invalidateIdentityMaps(String[] classNamesParam, Boolean recurse) throws ClassNotFoundException { |
| 1152 |
String[] classNames = classNamesParam; |
| 1153 |
for (int index = 0; index < classNames.length; index++) { |
| 1154 |
invalidateIdentityMap(classNames[index], recurse); |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
/** |
| 1159 |
* This method is used to invalidate the identity maps specified by className. This does not |
| 1160 |
* invalidate the children identity maps |
| 1161 |
* |
| 1162 |
* @param className the fully qualified classname identifying the identity map to invalidate |
| 1163 |
*/ |
| 1164 |
public synchronized void invalidateIdentityMap(String className) throws ClassNotFoundException { |
| 1165 |
this.invalidateIdentityMap(className, Boolean.FALSE); |
| 1166 |
} |
| 1167 |
|
| 1168 |
/** |
| 1169 |
* This method is used to invalidate the identity maps specified by className. |
| 1170 |
* |
| 1171 |
* @param className the fully qualified classname identifying the identity map to invalidate |
| 1172 |
* @param recurse Boolean indicating if we want to invalidate the children identity maps too |
| 1173 |
*/ |
| 1174 |
public synchronized void invalidateIdentityMap(String className, Boolean recurse) throws ClassNotFoundException { |
| 1175 |
Class registeredClass; |
| 1176 |
|
| 1177 |
//get identity map, and invalidate |
| 1178 |
registeredClass = (Class)getSession().getDatasourcePlatform().getConversionManager() |
| 1179 |
.convertObject(className, ClassConstants.CLASS); |
| 1180 |
getSession().getIdentityMapAccessor().invalidateClass(registeredClass); |
| 1181 |
((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_invalidated", className); |
| 1182 |
} |
| 1183 |
|
| 1184 |
/** |
| 1185 |
* |
| 1186 |
* INTERNAL: |
| 1187 |
* Convert the TabularData to a two-dimensional array |
| 1188 |
* @param tdata the TabularData to be converted |
| 1189 |
* @param names the order of the columns |
| 1190 |
* @return a two-dimensional array |
| 1191 |
* @throws Exception |
| 1192 |
*/ |
| 1193 |
private Object[][] tabularDataTo2DArray(TabularData tdata, String[] names) throws Exception { |
| 1194 |
if(tdata==null){ |
| 1195 |
return null; |
| 1196 |
} |
| 1197 |
Object[] rows = tdata.values().toArray(); |
| 1198 |
Object[][] data = new Object[rows.length][]; |
| 1199 |
|
| 1200 |
for (int i=0; i<rows.length; i++) { |
| 1201 |
data[i] = ((CompositeData) rows[i]).getAll(names); |
| 1202 |
} |
| 1203 |
return data; |
| 1204 |
} |
| 1205 |
|
| 1206 |
|
| 1207 |
/** |
| 1208 |
* Return whether this session is an EclipseLink JPA session. |
| 1209 |
* The absence of this function or a value of false will signify that the session |
| 1210 |
* belongs to a provider other than EclipseLink. |
| 1211 |
* @return |
| 1212 |
*/ |
| 1213 |
public boolean isJPASession() { |
| 1214 |
return true; |
| 1215 |
} |
| 1216 |
} |