Public Member Functions | |
NotificationListener | getNotificationListener () |
void | setNotificationListener (NotificationListener notificationListener) |
Object | getCredentials () |
RmiJmxClient (String port, String host, String jmxUser, String jmxPassword) throws IOException | |
RmiJmxClient (String url, Object credentials) throws IOException | |
RmiJmxClient (String port, String host, Object credentials) throws IOException | |
void | connect (String port, String host, Object credentials) throws IOException |
Set | listCJDBCMBeans () throws Exception |
MBeanInfo | getMBeanInfo (ObjectName mbean) throws Exception |
Object | getAttributeValue (ObjectName mbean, String attribute) throws Exception |
void | setAttributeValue (ObjectName mbean, String attribute, Object value) throws Exception |
void | setCurrentSubject (String user, String password) |
boolean | isSubjectSet () |
Object | invokeOperation (ObjectName name, MBeanOperationInfo operation, Object[] args) throws Exception |
VirtualDatabaseMBean | getVirtualDatabaseProxy (String database, String user, String password) throws InstanceNotFoundException, IOException, VirtualDatabaseException |
ControllerMBean | getControllerProxy () throws IOException |
DataCollectorMBean | getDataCollectorProxy () throws IOException |
DatabaseBackendMBean | getDatabaseBackendProxy (String vdb, String backend, String user, String password) throws InstanceNotFoundException, IOException |
String | getRemoteName () |
String | getRemoteHostAddress () |
String | getRemoteHostPort () |
void | reconnect () throws IOException |
boolean | isValidConnection () |
Package Attributes | |
Subject | subject |
Definition at line 65 of file RmiJmxClient.java.
|
Creates a new
Definition at line 119 of file RmiJmxClient.java. 00121 {
00122 this(port, host, PasswordAuthenticator.createCredentials(jmxUser,
00123 jmxPassword));
00124 }
|
|
Creates a new
Definition at line 133 of file RmiJmxClient.java. 00134 { 00135 int index = url.indexOf(":"); 00136 String ip = url.substring(0, index); 00137 String port = url.substring(index + 1); 00138 connect(port, ip, credentials); 00139 }
|
|
Creates a new
Definition at line 149 of file RmiJmxClient.java. 00151 { 00152 connect(port, host, credentials); 00153 }
|
|
Connect to the MBean server
Definition at line 163 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.commands.controller.Bind.parse(). 00165 { 00166 JMXServiceURL address = new JMXServiceURL("rmi", host, 0, "/jndi/jrmp"); 00167 00168 Map environment = new HashMap(); 00169 environment.put(Context.INITIAL_CONTEXT_FACTORY, 00170 "com.sun.jndi.rmi.registry.RegistryContextFactory"); 00171 environment.put(Context.PROVIDER_URL, "rmi://" + host + ":" + port); 00172 00173 // use username and password for authentication of connections 00174 // with the controller, the values are compared to the ones 00175 // specified in the controller.xml config file. 00176 if (credentials != null) 00177 { 00178 // this line is not required if no username/password has been configered 00179 environment.put(JMXConnector.CREDENTIALS, credentials); 00180 } 00181 00182 this.credentials = credentials; 00183 00184 connector = JMXConnectorFactory.connect(address, environment); 00185 remoteHostAddress = host; 00186 remoteHostPort = port; 00187 }
|
|
Get the value of an attribute on the given mbean
Definition at line 223 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.gui.frames.jmxdesktop.AttributeChangeDialog.AttributeChangeDialog(). 00225 {
00226 return connector.getMBeanServerConnection().getAttribute(mbean, attribute);
00227 }
|
|
Get a proxy to the ControllerMBean
Definition at line 391 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin.login(), org.objectweb.cjdbc.console.text.commands.controller.Shutdown.parse(), org.objectweb.cjdbc.console.text.commands.controller.SaveConfiguration.parse(), org.objectweb.cjdbc.console.text.commands.controller.Report.parse(), org.objectweb.cjdbc.console.text.commands.controller.RefreshLogs.parse(), org.objectweb.cjdbc.console.text.commands.controller.Load.parse(), org.objectweb.cjdbc.console.text.commands.controller.ListDatabases.parse(), org.objectweb.cjdbc.console.text.commands.controller.GetXml.parse(), org.objectweb.cjdbc.console.text.commands.controller.GetInfo.parse(), org.objectweb.cjdbc.console.text.commands.controller.DropDB.parse(), and org.objectweb.cjdbc.console.text.commands.controller.AddDriver.parse(). 00392 { 00393 00394 if (controllerMBean != null && isValidConnection()) 00395 { 00396 return controllerMBean; 00397 } 00398 else 00399 { 00400 if (!isValidConnection()) 00401 reconnect(); 00402 00403 ObjectName db = JmxConstants.getControllerObjectName(); 00404 00405 // we create a new proxy to the controller 00406 controllerMBean = (ControllerMBean) MBeanServerInvocationHandler 00407 .newProxyInstance(connector.getMBeanServerConnection(), db, 00408 ControllerMBean.class, false); 00409 00410 // Add notification listener 00411 if (notificationListener != null) 00412 { 00413 try 00414 { 00415 connector.getMBeanServerConnection().addNotificationListener(db, 00416 notificationListener, null, null); 00417 } 00418 catch (Exception e) 00419 { 00420 throw new IOException("Could not register listener on the mbean"); 00421 } 00422 } 00423 00424 return controllerMBean; 00425 } 00426 }
|
|
Returns the credentials value.
Definition at line 105 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.commands.controller.Bind.parse(). 00106 {
00107 return credentials;
00108 }
|
|
Get a proxy to the DatabaseBackendMBean
Definition at line 466 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.commands.dbadmin.EnableWrite.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.EnableRead.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.DisableWrite.parse(), and org.objectweb.cjdbc.console.text.commands.dbadmin.DisableRead.parse(). 00469 { 00470 if (backendMBean != null && isValidConnection()) 00471 { 00472 try 00473 { 00474 if (backendMBean.getName().equals(backend)) 00475 return backendMBean; 00476 } 00477 catch (Exception e) 00478 { 00479 // backend is no more there 00480 } 00481 } 00482 00483 if (!isValidConnection()) 00484 reconnect(); 00485 00486 // we build a subject for authentication 00487 AdminUser dbUser = new AdminUser(user, password); 00488 Set principals = new HashSet(); 00489 principals.add(dbUser); 00490 Subject subj = new Subject(true, principals, new HashSet(), new HashSet()); 00491 00492 ObjectName db = JmxConstants.getDatabaseBackendObjectName(vdb, backend); 00493 MBeanServerConnection delegateConnection = connector 00494 .getMBeanServerConnection(subj); 00495 00496 if (notificationListener != null) 00497 { 00498 delegateConnection.addNotificationListener(db, notificationListener, 00499 null, null); 00500 StringMonitor sm = new StringMonitor(); 00501 sm.setObservedObject(db); 00502 sm.setObservedAttribute("LastKnownCheckpoint"); 00503 sm.setStringToCompare("hello"); 00504 sm.setGranularityPeriod(100); 00505 sm.setNotifyDiffer(true); 00506 sm.addNotificationListener(notificationListener, null, null); 00507 sm.start(); 00508 } 00509 00510 // we create a proxy to the database backend 00511 backendMBean = (DatabaseBackendMBean) MBeanServerInvocationHandler 00512 .newProxyInstance(delegateConnection, db, DatabaseBackendMBean.class, 00513 false); 00514 return backendMBean; 00515 }
|
|
|
Get the mbean information
Definition at line 209 of file RmiJmxClient.java. 00210 {
00211 return connector.getMBeanServerConnection().getMBeanInfo(mbean);
00212 }
|
|
Returns the notificationListener value.
Definition at line 85 of file RmiJmxClient.java. 00086 {
00087 return notificationListener;
00088 }
|
|
Returns the remoteHostAddress value.
Definition at line 533 of file RmiJmxClient.java. 00534 {
00535 return remoteHostAddress;
00536 }
|
|
Returns the remoteHostPort value.
Definition at line 543 of file RmiJmxClient.java. 00544 {
00545 return remoteHostPort;
00546 }
|
|
Get the controller name used for jmx connection This is [hostname]:[jmxServerPort]
Definition at line 523 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.module.ControllerConsole.getPromptString(), and org.objectweb.cjdbc.console.text.commands.monitor.ChangeTarget.parse(). 00524 { 00525 return remoteHostAddress + ":" + remoteHostPort; 00526 }
|
|
Get a reference to the virtualdatabaseMbean with the given authentication
Definition at line 321 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.module.VirtualDatabaseAdmin.login(), org.objectweb.cjdbc.console.text.commands.dbadmin.ViewDumpNames.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.ViewCheckpointNames.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.TransferBackend.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.ShowBackendState.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.ShowBackends.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.Restore.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.RemoveDumpFile.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.RemoveCheckpoint.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.EnableWrite.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.EnableAll.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.Enable.parse(), org.objectweb.cjdbc.console.text.commands.dbadmin.DisableAll.parse(), and org.objectweb.cjdbc.console.text.commands.dbadmin.Disable.parse(). 00324 { 00325 if (virtualDbMBean != null && isValidConnection() 00326 && virtualDbMBean.getVirtualDatabaseName().equals(database)) 00327 { 00328 return virtualDbMBean; 00329 } 00330 else 00331 { 00332 ObjectName db = JmxConstants.getVirtualDbObjectName(database); 00333 00334 // we build a subject for authentication 00335 AdminUser dbUser = new AdminUser(user, password); 00336 Set principals = new HashSet(); 00337 principals.add(dbUser); 00338 Subject subj = new Subject(true, principals, new HashSet(), new HashSet()); 00339 00340 // we open a connection for this subject, all subsequent calls with this 00341 // connection will be executed on the behalf of our subject. 00342 MBeanServerConnection delegateConnection = connector 00343 .getMBeanServerConnection(subj); 00344 00345 // we create a proxy to the virtual database 00346 VirtualDatabaseMBean local = (VirtualDatabaseMBean) MBeanServerInvocationHandler 00347 .newProxyInstance(delegateConnection, db, VirtualDatabaseMBean.class, 00348 false); 00349 00350 // Check authentication 00351 boolean authenticated = false; 00352 try 00353 { 00354 authenticated = local.checkAdminAuthentication(user, password); 00355 } 00356 catch (Exception e) 00357 { 00358 throw new VirtualDatabaseException( 00359 "Could not check authentication. MBean is not accessible."); 00360 } 00361 if (!authenticated) 00362 throw new VirtualDatabaseException("Authentication Failed"); 00363 00364 // Add notification listener 00365 if (notificationListener != null) 00366 { 00367 delegateConnection.addNotificationListener(db, notificationListener, 00368 null, null); 00369 00370 // CounterMonitor cm = new CounterMonitor(); 00371 // cm.setNotify(true); 00372 // cm.setGranularityPeriod(100); 00373 // cm.setObservedObject(db); 00374 // cm.setObservedAttribute("currentNbOfThreads"); 00375 // cm.setThreshold(new Integer(6)); 00376 // cm.start(); 00377 } 00378 00379 this.virtualDbMBean = local; 00380 00381 return virtualDbMBean; 00382 } 00383 }
|
|
Invoke an operation on the given object.
Definition at line 283 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.gui.frames.jmxdesktop.OperationCallDialog.actionPerformed(). 00285 { 00286 if (JmxConstants.mbeanNeedAuthentication(name)) 00287 { 00288 if (!isSubjectSet()) 00289 throw new Exception( 00290 "Subject has not been set for this jmx client, and authentication is required"); 00291 return connector.getMBeanServerConnection(subject).invoke(name, 00292 operation.getName(), args, getSignature(operation)); 00293 } 00294 else 00295 { 00296 return connector.getMBeanServerConnection().invoke(name, 00297 operation.getName(), args, getSignature(operation)); 00298 } 00299 }
|
|
Has the subject been set?
Definition at line 269 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.gui.frames.jmxdesktop.OperationCallDialog.actionPerformed(). 00270 {
00271 return subject != null;
00272 }
|
|
Test if the connection with the mbean server is still valid
Definition at line 563 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.text.commands.controller.Shutdown.parse(). 00564 { 00565 try 00566 { 00567 connector.getMBeanServerConnection().getMBeanCount(); 00568 return true; 00569 } 00570 catch (Exception e) 00571 { 00572 controllerMBean = null; 00573 backendMBean = null; 00574 virtualDbMBean = null; 00575 dataMBean = null; 00576 return false; 00577 } 00578 }
|
|
List of all the mbean on the current server
Definition at line 195 of file RmiJmxClient.java. 00196 { 00197 Set set = connector.getMBeanServerConnection().queryMBeans( 00198 new ObjectName("c-jdbc:*"), null); 00199 return set; 00200 }
|
|
Reconnect to the same mbean server
Definition at line 553 of file RmiJmxClient.java. 00554 { 00555 connect(remoteHostPort, remoteHostAddress, credentials); 00556 }
|
|
Change an attribute value
Definition at line 237 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.gui.frames.jmxdesktop.AttributeChangeDialog.actionPerformed(). 00239 {
00240 Attribute att = new Attribute(attribute, value);
00241 connector.getMBeanServerConnection().setAttribute(mbean, att);
00242 }
|
|
Set the current subject for authentication
Definition at line 250 of file RmiJmxClient.java. Referenced by org.objectweb.cjdbc.console.gui.frames.jmxdesktop.SetSubjectDialog.actionPerformed(). 00251 { 00252 if (user != null && password != null) 00253 { 00254 // we build a subject for authentication 00255 AdminUser dbUser = new AdminUser(user, password); 00256 Set principals = new HashSet(); 00257 principals.add(dbUser); 00258 subject = new Subject(true, principals, new HashSet(), new HashSet()); 00259 } 00260 }
|
|
Sets the notificationListener value.
Definition at line 95 of file RmiJmxClient.java. 00096 {
00097 this.notificationListener = notificationListener;
00098 }
|