1 26 package org.objectweb.openccm.explorer.CORBA; 27 28 import javax.swing.Timer ; 29 30 import org.objectweb.openccm.explorer.util.ior.IorPrinter; 31 import org.objectweb.util.explorer.api.MenuItem; 32 import org.objectweb.util.explorer.api.MenuItemTreeView; 33 import org.objectweb.util.explorer.api.TreeView; 34 import org.objectweb.util.explorer.swing.gui.api.Console; 35 36 43 public class PingAction 44 implements MenuItem 45 { 46 47 53 protected Timer timer_; 54 55 61 67 70 public int getStatus(TreeView treeView) { 71 return MenuItem.ENABLED_STATUS; 72 } 73 74 77 public void actionPerformed(MenuItemTreeView e) throws Exception { 78 org.omg.CORBA.Object object = (org.omg.CORBA.Object )e.getSelectedObject(); 79 org.omg.CORBA.ORB orb = org.objectweb.openccm.corba.TheORB.getORB(); 80 IorPrinter iorPrinter = new IorPrinter(orb.object_to_string(object)); 81 Console console = ConsoleFactory.getPingConsole(); 82 console.clear(); 83 timer_ = new javax.swing.Timer (1000, new PingObjectAction(console, e.getSelectedEntry().getName().toString() + " (" + iorPrinter.getHost() + ":" + iorPrinter.getPort() + ")", object)); 84 timer_.setInitialDelay(0); 85 startTimer(); 86 console.show(); 87 stopTimer(); 88 } 89 90 public void startTimer(){ 91 timer_.start(); 92 } 93 94 public void stopTimer(){ 95 timer_.stop(); 96 } 97 98 104 protected class PingObjectAction 105 implements java.awt.event.ActionListener { 106 107 protected Console console_; 108 109 protected String name_; 110 111 protected org.omg.CORBA.Object object_; 112 113 public PingObjectAction(Console console, String name, org.omg.CORBA.Object object){ 114 console_ = console; 115 name_ = name; 116 object_ = object; 117 } 118 119 public void actionPerformed(java.awt.event.ActionEvent e){ 120 console_.add("Pinging " + name_ + ": "); 121 try { 122 long timeBefore = System.currentTimeMillis(); 123 object_._non_existent(); 124 long timeAfter = System.currentTimeMillis(); 125 console_.add("time=" + (timeAfter - timeBefore) + " ms\n"); 126 }catch(Exception ex){ 127 console_.add("Error: " + ex.getClass().getName()); 128 stopTimer(); 129 } 130 } 131 132 } 133 134 } 135 | Popular Tags |