001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.management;
027:
028: import java.lang.management.LockInfo;
029: import java.lang.management.ThreadInfo;
030: import javax.management.Attribute;
031: import javax.management.StandardMBean;
032: import javax.management.openmbean.CompositeData;
033:
034: /**
035: * This MXBean is used for data conversion from LockInfo
036: * to CompositeData (its mapped type) or vice versa.
037: */
038: class LockDataConverter extends StandardMBean implements
039: LockDataConverterMXBean {
040: private LockInfo lockInfo;
041: private LockInfo[] lockedSyncs;
042:
043: LockDataConverter() {
044: super (LockDataConverterMXBean.class, true);
045: this .lockInfo = null;
046: this .lockedSyncs = null;
047: }
048:
049: LockDataConverter(ThreadInfo ti) {
050: super (LockDataConverterMXBean.class, true);
051: this .lockInfo = ti.getLockInfo();
052: this .lockedSyncs = ti.getLockedSynchronizers();
053: }
054:
055: public void setLockInfo(LockInfo l) {
056: this .lockInfo = l;
057: }
058:
059: public LockInfo getLockInfo() {
060: return this .lockInfo;
061: }
062:
063: public void setLockedSynchronizers(LockInfo[] l) {
064: this .lockedSyncs = l;
065: }
066:
067: public LockInfo[] getLockedSynchronizers() {
068: return this .lockedSyncs;
069: }
070:
071: // helper methods
072: CompositeData toLockInfoCompositeData() {
073: try {
074: return (CompositeData) getAttribute("LockInfo");
075: } catch (Exception e) {
076: throw Util.newInternalError(e);
077: }
078: }
079:
080: CompositeData[] toLockedSynchronizersCompositeData() {
081: try {
082: return (CompositeData[]) getAttribute("LockedSynchronizers");
083: } catch (Exception e) {
084: throw Util.newInternalError(e);
085: }
086: }
087:
088: LockInfo toLockInfo(CompositeData cd) {
089: try {
090: setAttribute(new Attribute("LockInfo", cd));
091: } catch (Exception e) {
092: throw Util.newInternalError(e);
093: }
094: return getLockInfo();
095: }
096:
097: LockInfo[] toLockedSynchronizers(CompositeData[] cd) {
098: try {
099: setAttribute(new Attribute("LockedSynchronizers", cd));
100: } catch (Exception e) {
101: throw Util.newInternalError(e);
102: }
103: return getLockedSynchronizers();
104: }
105:
106: static CompositeData toLockInfoCompositeData(LockInfo l) {
107: LockDataConverter ldc = new LockDataConverter();
108: ldc.setLockInfo(l);
109: return ldc.toLockInfoCompositeData();
110: }
111: }
|