KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > popups > BackendPopUpMenu


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2005 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): Emmanuel Cecchet.
23  */

24
25 package org.objectweb.cjdbc.console.gui.popups;
26
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.MouseListener JavaDoc;
29
30 import javax.swing.JMenu JavaDoc;
31 import javax.swing.JMenuItem JavaDoc;
32 import javax.swing.JSeparator JavaDoc;
33
34 import org.objectweb.cjdbc.common.jmx.mbeans.DataCollectorMBean;
35 import org.objectweb.cjdbc.common.monitor.DataCollection;
36 import org.objectweb.cjdbc.common.monitor.DataCollectionNames;
37 import org.objectweb.cjdbc.console.gui.CjdbcGui;
38 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
39 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
40 import org.objectweb.cjdbc.console.gui.objects.BackendObject;
41 import org.objectweb.cjdbc.console.jmx.RmiJmxClient;
42 import org.objectweb.cjdbc.console.monitoring.MonitoringConsole;
43
44 /**
45  * This class defines a BackendPopUpMenu
46  *
47  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
48  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet
49  * </a>
50  * @version 1.0
51  */

52 public class BackendPopUpMenu extends AbstractPopUpMenu
53     implements
54       MouseListener JavaDoc
55 {
56
57   private BackendObject bo;
58   JMenuItem JavaDoc backendRemove;
59   JMenuItem JavaDoc backendCreate;
60   JMenuItem JavaDoc backendCheckpoint;
61   JMenuItem JavaDoc backendUnsetCheckpoint;
62   JMenuItem JavaDoc backendEnable;
63   JMenuItem JavaDoc backendDisable;
64   JMenuItem JavaDoc backendRestore;
65   JMenuItem JavaDoc backendBackup;
66   JMenuItem JavaDoc backendTestConnection;
67   JMenu JavaDoc monitor;
68
69   /**
70    * Creates a new <code>BackendPopUpMenu</code> object
71    *
72    * @param gui the referenced gui
73    * @param bo the backend object
74    */

75   public BackendPopUpMenu(CjdbcGui gui, BackendObject bo)
76   {
77     super(gui);
78     this.bo = bo;
79
80     JSeparator JavaDoc separator = new JSeparator JavaDoc();
81
82     backendRemove = new JMenuItem JavaDoc(GuiCommands.COMMAND_BACKEND_REMOVE);
83     backendCreate = new JMenuItem JavaDoc(GuiCommands.COMMAND_BACKEND_CREATE_NEW);
84     backendCheckpoint = new JMenuItem JavaDoc(
85         GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT);
86     backendEnable = new JMenuItem JavaDoc(GuiConstants.BACKEND_STATE_ENABLED);
87     backendDisable = new JMenuItem JavaDoc(GuiConstants.BACKEND_STATE_DISABLED);
88     backendRestore = new JMenuItem JavaDoc(GuiConstants.BACKEND_STATE_RESTORE);
89     backendBackup = new JMenuItem JavaDoc(GuiConstants.BACKEND_STATE_BACKUP);
90     backendTestConnection = new JMenuItem JavaDoc(
91         GuiCommands.COMMAND_BACKEND_TEST_CONNECTION);
92     backendUnsetCheckpoint = new JMenuItem JavaDoc(
93         GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT);
94
95     this.add(backendRemove).addActionListener(this);
96     this.add(backendCreate).addActionListener(this);
97     this.add(backendCheckpoint).addActionListener(this);
98     this.add(backendUnsetCheckpoint).addActionListener(this);
99     this.add(backendTestConnection).addActionListener(this);
100     this.add(separator);
101     this.add(backendEnable).addActionListener(this);
102     this.add(backendDisable).addActionListener(this);
103     this.add(backendRestore).addActionListener(this);
104     this.add(backendBackup).addActionListener(this);
105     this.add(separator);
106
107     buildMonitorMenu();
108   }
109
110   private void buildMonitorMenu()
111   {
112     monitor = new JMenu JavaDoc("Monitor");
113     addToMonitorMenu(DataCollection.BACKEND_ACTIVE_TRANSACTION);
114     addToMonitorMenu(DataCollection.BACKEND_PENDING_REQUESTS);
115     addToMonitorMenu(DataCollection.BACKEND_TOTAL_ACTIVE_CONNECTIONS);
116     addToMonitorMenu(DataCollection.BACKEND_TOTAL_READ_REQUEST);
117     addToMonitorMenu(DataCollection.BACKEND_TOTAL_REQUEST);
118     addToMonitorMenu(DataCollection.BACKEND_TOTAL_TRANSACTIONS);
119     addToMonitorMenu(DataCollection.BACKEND_TOTAL_WRITE_REQUEST);
120     this.add(monitor);
121   }
122
123   private void addToMonitorMenu(int type)
124   {
125     String JavaDoc typeName = DataCollectionNames.get(type);
126     JMenuItem JavaDoc item = new JMenuItem JavaDoc(typeName);
127     String JavaDoc action = MonitoringConsole.getBackendActionCommand(typeName, bo
128         .getDatabase(), bo.getName());
129     item.setActionCommand(action);
130     monitor.add(item).addActionListener(this);
131   }
132
133   /**
134    * Returns the backendCheckpoint value.
135    *
136    * @return Returns the backendCheckpoint.
137    */

138   public final JMenuItem JavaDoc getBackendCheckpoint()
139   {
140     return backendCheckpoint;
141   }
142
143   /**
144    * Returns the backendCreate value.
145    *
146    * @return Returns the backendCreate.
147    */

148   public final JMenuItem JavaDoc getBackendCreate()
149   {
150     return backendCreate;
151   }
152
153   /**
154    * Returns the backendRemove value.
155    *
156    * @return Returns the backendRemove.
157    */

158   public final JMenuItem JavaDoc getBackendRemove()
159   {
160     return backendRemove;
161   }
162
163   /**
164    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
165    */

166   public void actionPerformed(ActionEvent JavaDoc e)
167   {
168     String JavaDoc action = e.getActionCommand();
169     if (action.startsWith("graph"))
170     {
171       RmiJmxClient controllerMBean = bo.getJmxClient();
172       DataCollectorMBean dataCollectorMBean;
173       try
174       {
175         dataCollectorMBean = controllerMBean.getDataCollectorProxy();
176         MonitoringConsole.graph(action, dataCollectorMBean, -1, 3600, 1000, 1,
177             null);
178         return;
179       }
180       catch (Exception JavaDoc e1)
181       {
182         e1.printStackTrace();
183         return;
184       }
185     }
186
187     if (action.equals(GuiCommands.COMMAND_BACKEND_REMOVE))
188     {
189       gui.publicActionRemoveBackend(bo);
190     }
191     else if (action.equals(GuiCommands.COMMAND_BACKEND_CREATE_NEW))
192     {
193       gui.publicActionNewBackendPrompt(bo);
194     }
195     else if (action.equals(GuiCommands.COMMAND_BACKEND_SET_CHECKPOINT))
196     {
197       gui.publicActionSetCheckpoint(bo);
198     }
199     else if (action.equals(GuiCommands.COMMAND_BACKEND_TEST_CONNECTION))
200     {
201       gui.publicActionTestBackendConnection(bo);
202     }
203     else if (action.equals(GuiCommands.COMMAND_BACKEND_UNSET_CHECKPOINT))
204     {
205       gui.publicActionUnSetCheckpoint(bo);
206     }
207     else
208     {
209       gui.publicActionExecuteBackendDrop(action, bo.getName());
210     }
211
212   }
213
214   /**
215    * Returns the backendBackup value.
216    *
217    * @return Returns the backendBackup.
218    */

219   public final JMenuItem JavaDoc getBackendBackup()
220   {
221     return backendBackup;
222   }
223
224   /**
225    * Returns the backendDisable value.
226    *
227    * @return Returns the backendDisable.
228    */

229   public final JMenuItem JavaDoc getBackendDisable()
230   {
231     return backendDisable;
232   }
233
234   /**
235    * Returns the backendEnable value.
236    *
237    * @return Returns the backendEnable.
238    */

239   public final JMenuItem JavaDoc getBackendEnable()
240   {
241     return backendEnable;
242   }
243
244   /**
245    * Returns the backendRestore value.
246    *
247    * @return Returns the backendRestore.
248    */

249   public final JMenuItem JavaDoc getBackendRestore()
250   {
251     return backendRestore;
252   }
253 }
Popular Tags