KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > CORBA > PingAction


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.CORBA;
27
28 import javax.swing.Timer JavaDoc;
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 /**
37  * This action checks if a CORBA object already exists.
38  *
39  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
40  *
41  * @version 0.1
42  */

43 public class PingAction
44   implements MenuItem
45 {
46
47     //==================================================================
48
//
49
// Internal states.
50
//
51
//==================================================================
52

53     protected Timer JavaDoc timer_;
54     
55     //==================================================================
56
//
57
// Internal methods.
58
//
59
//==================================================================
60

61     //==================================================================
62
//
63
// Public methods for MenuItem interface.
64
//
65
//==================================================================
66

67     /* (non-Javadoc)
68      * @see org.objectweb.util.explorer.api.MenuItem#getStatus(org.objectweb.util.explorer.api.TreeView)
69      */

70     public int getStatus(TreeView treeView) {
71         return MenuItem.ENABLED_STATUS;
72     }
73
74     /* (non-Javadoc)
75      * @see org.objectweb.util.explorer.api.MenuItem#actionPerformed(org.objectweb.util.explorer.api.MenuItemTreeView)
76      */

77     public void actionPerformed(MenuItemTreeView e) throws Exception JavaDoc {
78         org.omg.CORBA.Object JavaDoc object = (org.omg.CORBA.Object JavaDoc)e.getSelectedObject();
79         org.omg.CORBA.ORB JavaDoc 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 JavaDoc(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     //==================================================================
99
//
100
// Protected classes.
101
//
102
//==================================================================
103

104     protected class PingObjectAction
105         implements java.awt.event.ActionListener JavaDoc {
106
107         protected Console console_;
108
109         protected String JavaDoc name_;
110
111         protected org.omg.CORBA.Object JavaDoc object_;
112
113         public PingObjectAction(Console console, String JavaDoc name, org.omg.CORBA.Object JavaDoc object){
114             console_ = console;
115             name_ = name;
116             object_ = object;
117         }
118
119         public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc ex){
127                 console_.add("Error: " + ex.getClass().getName());
128                 stopTimer();
129             }
130         }
131         
132     }
133         
134 }
135
Popular Tags