1 3 package org.jgroups.debug; 4 5 import org.jgroups.JChannel; 6 import org.jgroups.stack.Protocol; 7 import org.jgroups.stack.ProtocolStack; 8 9 import javax.swing.*; 10 import javax.swing.table.DefaultTableModel ; 11 import java.awt.*; 12 import java.util.Vector ; 13 14 15 21 public class Debugger extends JFrame { 22 JChannel channel=null; 23 Vector prots=new Vector (); 24 JButton b1, b2; 25 JPanel button_panel; 26 JTable table; 27 DefaultTableModel table_model; 28 JScrollPane scroll_pane; 29 public static final Font helvetica_12=new Font("Helvetica", Font.PLAIN, 12);; 30 public boolean cummulative=false; 32 33 34 public Debugger() { 35 super("Debugger Window"); 36 } 37 38 39 public Debugger(JChannel channel) { 40 super("Debugger Window"); 41 this.channel=channel; 42 } 43 44 45 public Debugger(JChannel channel, String name) { 46 super(name); 47 this.channel=channel; 48 } 49 50 public Debugger(JChannel channel, boolean cummulative) { 51 super("Debugger Window"); 52 this.channel=channel; 53 this.cummulative=cummulative; 54 } 55 56 57 public Debugger(JChannel channel, boolean cummulative, String name) { 58 super(name); 59 this.channel=channel; 60 this.cummulative=cummulative; 61 } 62 63 64 public void setChannel(JChannel channel) { 65 this.channel=channel; 66 } 67 68 69 public void start() { 70 Protocol prot; 71 ProtocolStack stack; 72 ProtocolView view=null; 73 74 if(channel == null) return; 75 stack=channel.getProtocolStack(); 76 prots=stack.getProtocols(); 77 78 setBounds(new Rectangle(30, 30, 300, 300)); 79 table_model=new DefaultTableModel (); 80 table=new JTable(table_model); 81 table.setFont(helvetica_12); 82 scroll_pane=new JScrollPane(table); 83 table_model.setColumnIdentifiers(new String []{"Index", "Name", "up", "down"}); 84 85 getContentPane().add(scroll_pane); 86 show(); 87 88 for(int i=0; i < prots.size(); i++) { 89 prot=(Protocol)prots.elementAt(i); 90 view=new ProtocolView(prot, table_model, i, cummulative); 91 prot.setObserver(view); 92 table_model.insertRow(i, new Object []{"" + (i + 1), 93 prot.getName(), prot.getUpQueue().size() + "", 94 prot.getDownQueue().size() + "", "0", "0"}); 95 96 } 103 } 104 105 public void stop() { 106 Protocol prot; 107 ProtocolStack stack; 108 109 if(channel == null) return; 110 stack=channel.getProtocolStack(); 111 prots=stack.getProtocols(); 112 113 for(int i=0; i < prots.size(); i++) { 114 prot=(Protocol)prots.elementAt(i); 115 prot.setObserver(null); 116 } 117 dispose(); 118 } 119 120 121 JComponent createProtocolView(String protname) { 122 String classname="org.jgroups.debug." + protname + "View"; 123 try { 124 ClassLoader loader=Thread.currentThread().getContextClassLoader(); 125 return (JComponent)loader.loadClass(classname).newInstance(); 126 } 127 catch(Exception e) { return null; 129 } 130 } 131 132 133 public static void main(String [] args) { 134 Debugger d=new Debugger(); 135 d.start(); 136 } 137 } 138 139 | Popular Tags |