KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > dso > LocksHelper


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.admin.dso;
5
6 import com.tc.admin.BaseHelper;
7 import com.tc.admin.ConnectionContext;
8 import com.tc.admin.AdminClient;
9 import com.tc.admin.AdminClientContext;
10 import com.tc.objectserver.lockmanager.api.LockMBean;
11 import com.tc.objectserver.lockmanager.api.DeadlockChain;
12
13 import java.io.IOException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import javax.management.AttributeNotFoundException JavaDoc;
17 import javax.management.InstanceNotFoundException JavaDoc;
18 import javax.management.MBeanException JavaDoc;
19 import javax.management.ObjectName JavaDoc;
20 import javax.management.ReflectionException JavaDoc;
21 import javax.swing.Icon JavaDoc;
22 import javax.swing.ImageIcon JavaDoc;
23
24 public class LocksHelper extends BaseHelper {
25   private static LocksHelper m_helper = new LocksHelper();
26   private Icon JavaDoc m_locksIcon;
27   private Icon JavaDoc m_lockIcon;
28   private Icon JavaDoc m_detectDeadlocksIcon;
29
30   public static LocksHelper getHelper() {
31     return m_helper;
32   }
33
34   public Icon JavaDoc getLocksIcon() {
35     if(m_locksIcon == null) {
36       URL JavaDoc url = getClass().getResource(ICONS_PATH+"owned_monitor_obj.gif");
37       m_locksIcon = new ImageIcon JavaDoc(url);
38     }
39
40     return m_locksIcon;
41   }
42
43   public Icon JavaDoc getLockIcon() {
44     if(m_lockIcon == null) {
45       URL JavaDoc url = getClass().getResource(ICONS_PATH+"deadlock_view.gif");
46       m_lockIcon = new ImageIcon JavaDoc(url);
47     }
48
49     return m_lockIcon;
50   }
51
52   public Icon JavaDoc getDetectDeadlocksIcon() {
53     if(m_detectDeadlocksIcon == null) {
54       URL JavaDoc url = getClass().getResource(ICONS_PATH+"insp_sbook.gif");
55       m_detectDeadlocksIcon = new ImageIcon JavaDoc(url);
56     }
57
58     return m_detectDeadlocksIcon;
59   }
60
61   public LockMBean[] getLocks(ConnectionContext cc)
62     throws MBeanException JavaDoc,
63            AttributeNotFoundException JavaDoc,
64            InstanceNotFoundException JavaDoc,
65            ReflectionException JavaDoc,
66            IOException JavaDoc
67   {
68     ObjectName JavaDoc dso = DSOHelper.getHelper().getDSOMBean(cc);
69     return (LockMBean[])cc.getAttribute(dso, "Locks");
70   }
71
72   public void detectDeadlocks(ConnectionContext cc) {
73     try {
74       ObjectName JavaDoc dso = DSOHelper.getHelper().getDSOMBean(cc);
75       String JavaDoc op = "scanForDeadLocks";
76       Object JavaDoc[] args = new Object JavaDoc[] {};
77       String JavaDoc[] types = new String JavaDoc[] {};
78       DeadlockChain[] chains = (DeadlockChain[])cc.invoke(dso, op, args, types);
79       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
80
81       if(chains != null) {
82         DeadlockChain chainRoot;
83         DeadlockChain chain;
84
85         for(int i = 0; i < chains.length; i++) {
86           chainRoot = chains[i];
87           chain = null;
88
89           while(chainRoot != chain) {
90             if(chain == null) {
91               chain = chainRoot;
92             }
93
94             sb.append(chain.getWaiter());
95             sb.append(" waiting on ");
96             sb.append(chain.getWaitingOn());
97             sb.append(System.getProperty("line.separator"));
98             
99             chain = chain.getNextLink();
100           }
101         }
102
103         AdminClientContext acc = AdminClient.getContext();
104         acc.controller.log(sb.toString());
105       }
106     }
107     catch(Exception JavaDoc e) {
108       AdminClient.getContext().log(e);
109     }
110   }
111 }
112
Popular Tags