1 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 ; 14 import java.net.URL ; 15 16 import javax.management.AttributeNotFoundException ; 17 import javax.management.InstanceNotFoundException ; 18 import javax.management.MBeanException ; 19 import javax.management.ObjectName ; 20 import javax.management.ReflectionException ; 21 import javax.swing.Icon ; 22 import javax.swing.ImageIcon ; 23 24 public class LocksHelper extends BaseHelper { 25 private static LocksHelper m_helper = new LocksHelper(); 26 private Icon m_locksIcon; 27 private Icon m_lockIcon; 28 private Icon m_detectDeadlocksIcon; 29 30 public static LocksHelper getHelper() { 31 return m_helper; 32 } 33 34 public Icon getLocksIcon() { 35 if(m_locksIcon == null) { 36 URL url = getClass().getResource(ICONS_PATH+"owned_monitor_obj.gif"); 37 m_locksIcon = new ImageIcon (url); 38 } 39 40 return m_locksIcon; 41 } 42 43 public Icon getLockIcon() { 44 if(m_lockIcon == null) { 45 URL url = getClass().getResource(ICONS_PATH+"deadlock_view.gif"); 46 m_lockIcon = new ImageIcon (url); 47 } 48 49 return m_lockIcon; 50 } 51 52 public Icon getDetectDeadlocksIcon() { 53 if(m_detectDeadlocksIcon == null) { 54 URL url = getClass().getResource(ICONS_PATH+"insp_sbook.gif"); 55 m_detectDeadlocksIcon = new ImageIcon (url); 56 } 57 58 return m_detectDeadlocksIcon; 59 } 60 61 public LockMBean[] getLocks(ConnectionContext cc) 62 throws MBeanException , 63 AttributeNotFoundException , 64 InstanceNotFoundException , 65 ReflectionException , 66 IOException 67 { 68 ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc); 69 return (LockMBean[])cc.getAttribute(dso, "Locks"); 70 } 71 72 public void detectDeadlocks(ConnectionContext cc) { 73 try { 74 ObjectName dso = DSOHelper.getHelper().getDSOMBean(cc); 75 String op = "scanForDeadLocks"; 76 Object [] args = new Object [] {}; 77 String [] types = new String [] {}; 78 DeadlockChain[] chains = (DeadlockChain[])cc.invoke(dso, op, args, types); 79 StringBuffer sb = new StringBuffer (); 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 e) { 108 AdminClient.getContext().log(e); 109 } 110 } 111 } 112 | Popular Tags |