001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.admin.dso;
005:
006: import com.tc.admin.AdminClient;
007: import com.tc.admin.AdminClientContext;
008: import com.tc.admin.BaseHelper;
009: import com.tc.admin.ConnectionContext;
010: import com.tc.objectserver.lockmanager.api.DeadlockChain;
011: import com.tc.objectserver.lockmanager.api.LockMBean;
012:
013: import java.io.IOException;
014: import java.net.URL;
015:
016: import javax.management.AttributeNotFoundException;
017: import javax.management.InstanceNotFoundException;
018: import javax.management.MBeanException;
019: import javax.management.MalformedObjectNameException;
020: import javax.management.ObjectName;
021: import javax.management.ReflectionException;
022: import javax.swing.Icon;
023: import javax.swing.ImageIcon;
024:
025: public class LocksHelper extends BaseHelper {
026: private static LocksHelper m_helper = new LocksHelper();
027: private Icon m_locksIcon;
028: private Icon m_lockIcon;
029: private Icon m_detectDeadlocksIcon;
030:
031: public static LocksHelper getHelper() {
032: return m_helper;
033: }
034:
035: public Icon getLocksIcon() {
036: if (m_locksIcon == null) {
037: URL url = getClass().getResource(
038: ICONS_PATH + "owned_monitor_obj.gif");
039: m_locksIcon = new ImageIcon(url);
040: }
041:
042: return m_locksIcon;
043: }
044:
045: public Icon getLockIcon() {
046: if (m_lockIcon == null) {
047: URL url = getClass().getResource(
048: ICONS_PATH + "deadlock_view.gif");
049: m_lockIcon = new ImageIcon(url);
050: }
051:
052: return m_lockIcon;
053: }
054:
055: public Icon getDetectDeadlocksIcon() {
056: if (m_detectDeadlocksIcon == null) {
057: URL url = getClass().getResource(
058: ICONS_PATH + "insp_sbook.gif");
059: m_detectDeadlocksIcon = new ImageIcon(url);
060: }
061:
062: return m_detectDeadlocksIcon;
063: }
064:
065: public LockMBean[] getLocks(ConnectionContext cc)
066: throws MBeanException, AttributeNotFoundException,
067: InstanceNotFoundException, ReflectionException,
068: IOException, MalformedObjectNameException {
069: ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc);
070: return (LockMBean[]) cc.getAttribute(dso, "Locks");
071: }
072:
073: public void detectDeadlocks(ConnectionContext cc) {
074: try {
075: ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc);
076: String op = "scanForDeadLocks";
077: Object[] args = new Object[] {};
078: String[] types = new String[] {};
079: DeadlockChain[] chains = (DeadlockChain[]) cc.invoke(dso,
080: op, args, types);
081: StringBuffer sb = new StringBuffer();
082:
083: if (chains != null) {
084: DeadlockChain chainRoot;
085: DeadlockChain chain;
086:
087: for (int i = 0; i < chains.length; i++) {
088: chainRoot = chains[i];
089: chain = null;
090:
091: while (chainRoot != chain) {
092: if (chain == null) {
093: chain = chainRoot;
094: }
095:
096: sb.append(chain.getWaiter());
097: sb.append(" waiting on ");
098: sb.append(chain.getWaitingOn());
099: sb.append(System.getProperty("line.separator"));
100:
101: chain = chain.getNextLink();
102: }
103: }
104:
105: AdminClientContext acc = AdminClient.getContext();
106: acc.controller.log(sb.toString());
107: }
108: } catch (Exception e) {
109: AdminClient.getContext().log(e);
110: }
111: }
112: }
|