Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.console.jmx.RmiJmxClient Class Reference

List of all members.

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

Detailed Description

This class defines a RmiJmxClient that uses Jmx 2.0 specifications to connect to the RmiSever

Author:
Nicolas Modrzyk
Version:
1.0

Definition at line 65 of file RmiJmxClient.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.console.jmx.RmiJmxClient.RmiJmxClient String  port,
String  host,
String  jmxUser,
String  jmxPassword
throws IOException
 

Creates a new RmiJmxClient.java object

Parameters:
port the port of the host to connect to
host the host name to connect to
jmxUser the jmxUser if one, to be authenticated with
jmxPassword the jmxPassword if one, to be authenticated with
Exceptions:
IOException if cannot connect

Definition at line 119 of file RmiJmxClient.java.

00121   {
00122     this(port, host, PasswordAuthenticator.createCredentials(jmxUser,
00123         jmxPassword));
00124   }

org.objectweb.cjdbc.console.jmx.RmiJmxClient.RmiJmxClient String  url,
Object  credentials
throws IOException
 

Creates a new RmiJmxClient object

Parameters:
url the jmx connector url
credentials to use for the connection
Exceptions:
IOException if connect fails

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   }

org.objectweb.cjdbc.console.jmx.RmiJmxClient.RmiJmxClient String  port,
String  host,
Object  credentials
throws IOException
 

Creates a new RmiJmxClient.java object

Parameters:
port the port of the host to connect to
host the host name to connect to
credentials to use for the connection
Exceptions:
IOException if connect fails

Definition at line 149 of file RmiJmxClient.java.

00151   {
00152     connect(port, host, credentials);
00153   }


Member Function Documentation

void org.objectweb.cjdbc.console.jmx.RmiJmxClient.connect String  port,
String  host,
Object  credentials
throws IOException
 

Connect to the MBean server

Parameters:
port the port of the host to connect to
host the host name to connect to
credentials to use for the connection
Exceptions:
IOException if connect fails

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   }

Object org.objectweb.cjdbc.console.jmx.RmiJmxClient.getAttributeValue ObjectName  mbean,
String  attribute
throws Exception
 

Get the value of an attribute on the given mbean

Parameters:
mbean the ObjectName of the mbean to access
attribute the attribute name
Returns:
Object being the value returned by the get <attribute> method
Exceptions:
Exception if fails

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   }

ControllerMBean org.objectweb.cjdbc.console.jmx.RmiJmxClient.getControllerProxy  )  throws IOException
 

Get a proxy to the ControllerMBean

Returns:
ControllerMBean instance
Exceptions:
IOException if cannot connect to MBean

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   }

Object org.objectweb.cjdbc.console.jmx.RmiJmxClient.getCredentials  ) 
 

Returns the credentials value.

Returns:
Returns the credentials.

Definition at line 105 of file RmiJmxClient.java.

Referenced by org.objectweb.cjdbc.console.text.commands.controller.Bind.parse().

00106   {
00107     return credentials;
00108   }

DatabaseBackendMBean org.objectweb.cjdbc.console.jmx.RmiJmxClient.getDatabaseBackendProxy String  vdb,
String  backend,
String  user,
String  password
throws InstanceNotFoundException, IOException
 

Get a proxy to the DatabaseBackendMBean

Returns:
DatabaseBackendMBean instance
Parameters:
vdb virtual database name
backend backend name
user user name
password password name
Exceptions:
IOException if cannot connect to MBean
InstanceNotFoundException if cannot locate MBean

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   }

DataCollectorMBean org.objectweb.cjdbc.console.jmx.RmiJmxClient.getDataCollectorProxy  )  throws IOException
 

Get a proxy to the DataCollectorMBean

Returns:
DataCollectorMBean instance
Exceptions:
IOException if fails

Definition at line 434 of file RmiJmxClient.java.

Referenced by org.objectweb.cjdbc.console.gui.popups.BackendPopUpMenu.actionPerformed(), org.objectweb.cjdbc.console.monitoring.MonitoringConsole.MonitoringConsole(), org.objectweb.cjdbc.console.text.commands.monitor.ShowStats.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowScheduler.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowRecoveryLog.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowDatabases.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowController.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowCacheStats.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowCache.parse(), org.objectweb.cjdbc.console.text.commands.monitor.ShowBackends.parse(), and org.objectweb.cjdbc.console.text.commands.monitor.ChangeTarget.parse().

00435   {
00436 
00437     if (dataMBean != null && isValidConnection())
00438     {
00439       return dataMBean;
00440     }
00441     else
00442     {
00443       if (!isValidConnection())
00444         reconnect();
00445       ObjectName db = JmxConstants.getDataCollectorObjectName();
00446 
00447       // we create a new proxy to the data collector
00448       dataMBean = (DataCollectorMBean) MBeanServerInvocationHandler
00449           .newProxyInstance(connector.getMBeanServerConnection(), db,
00450               DataCollectorMBean.class, false);
00451       return dataMBean;
00452     }
00453   }

MBeanInfo org.objectweb.cjdbc.console.jmx.RmiJmxClient.getMBeanInfo ObjectName  mbean  )  throws Exception
 

Get the mbean information

Parameters:
mbean the ObjectName of the mbean to access
Returns:
MBeanInfo object
Exceptions:
Exception if fails

Definition at line 209 of file RmiJmxClient.java.

00210   {
00211     return connector.getMBeanServerConnection().getMBeanInfo(mbean);
00212   }

NotificationListener org.objectweb.cjdbc.console.jmx.RmiJmxClient.getNotificationListener  ) 
 

Returns the notificationListener value.

Returns:
Returns the notificationListener.

Definition at line 85 of file RmiJmxClient.java.

00086   {
00087     return notificationListener;
00088   }

String org.objectweb.cjdbc.console.jmx.RmiJmxClient.getRemoteHostAddress  ) 
 

Returns the remoteHostAddress value.

Returns:
Returns the remoteHostAddress.

Definition at line 533 of file RmiJmxClient.java.

00534   {
00535     return remoteHostAddress;
00536   }

String org.objectweb.cjdbc.console.jmx.RmiJmxClient.getRemoteHostPort  ) 
 

Returns the remoteHostPort value.

Returns:
Returns the remoteHostPort.

Definition at line 543 of file RmiJmxClient.java.

00544   {
00545     return remoteHostPort;
00546   }

String org.objectweb.cjdbc.console.jmx.RmiJmxClient.getRemoteName  ) 
 

Get the controller name used for jmx connection This is [hostname]:[jmxServerPort]

Returns:
remoteHostName+":"+remoteHostPort

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   }

VirtualDatabaseMBean org.objectweb.cjdbc.console.jmx.RmiJmxClient.getVirtualDatabaseProxy String  database,
String  user,
String  password
throws InstanceNotFoundException, IOException, VirtualDatabaseException
 

Get a reference to the virtualdatabaseMbean with the given authentication

Parameters:
database the virtual database name
user the user recognized as the VirtualDatabaseUser
password the password for the VirtualDatabaseUser
Returns:
VirtualDatabaseMBean instance
Exceptions:
IOException if cannot connect to MBean
InstanceNotFoundException if cannot locate MBean
VirtualDatabaseException if virtual database fails

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   }

Object org.objectweb.cjdbc.console.jmx.RmiJmxClient.invokeOperation ObjectName  name,
MBeanOperationInfo  operation,
Object[]  args
throws Exception
 

Invoke an operation on the given object.

Parameters:
name object name
operation operation to invoke
args method arguments
Returns:
result of operation invocation
Exceptions:
Exception if an error occurs

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   }

boolean org.objectweb.cjdbc.console.jmx.RmiJmxClient.isSubjectSet  ) 
 

Has the subject been set?

Returns:
true if the subject is not null

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   }

boolean org.objectweb.cjdbc.console.jmx.RmiJmxClient.isValidConnection  ) 
 

Test if the connection with the mbean server is still valid

Returns:
true if it is

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   }

Set org.objectweb.cjdbc.console.jmx.RmiJmxClient.listCJDBCMBeans  )  throws Exception
 

List of all the mbean on the current server

Returns:
a set of ObjectInstance
Exceptions:
Exception if fails

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   }

void org.objectweb.cjdbc.console.jmx.RmiJmxClient.reconnect  )  throws IOException
 

Reconnect to the same mbean server

Exceptions:
IOException if reconnection failed

Definition at line 553 of file RmiJmxClient.java.

00554   {
00555     connect(remoteHostPort, remoteHostAddress, credentials);
00556   }

void org.objectweb.cjdbc.console.jmx.RmiJmxClient.setAttributeValue ObjectName  mbean,
String  attribute,
Object  value
throws Exception
 

Change an attribute value

Parameters:
mbean the ObjectName of the mbean to access
attribute the attribute name
value the attribute new value
Exceptions:
Exception if fails

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   }

void org.objectweb.cjdbc.console.jmx.RmiJmxClient.setCurrentSubject String  user,
String  password
 

Set the current subject for authentication

Parameters:
user the user login
password the user password

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   }

void org.objectweb.cjdbc.console.jmx.RmiJmxClient.setNotificationListener NotificationListener  notificationListener  ) 
 

Sets the notificationListener value.

Parameters:
notificationListener The notificationListener to set.

Definition at line 95 of file RmiJmxClient.java.

00096   {
00097     this.notificationListener = notificationListener;
00098   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:40 2005 for C-JDBC by  doxygen 1.3.9.1