org.objectweb.cjdbc.controller.core
Class Controller

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.core.Controller
All Implemented Interfaces:
ControllerMBean, javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, XmlComponent

public final class Controller
extends AbstractStandardMBean
implements ControllerMBean, XmlComponent

The C-JDBC controller main class. It registers itself in the RMI registry and waits for C-JDBC driver requests.

Version:
1.0
Author:
Emmanuel Cecchet , Mathieu Peltier , Nicolas Modrzyk , Duncan Smith

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
private  int backlogSize
           
private  java.util.Hashtable configuration
          Hashtable of options
private  ControllerServerThread connectionThread
          Thread that listens for driver connections
private  java.lang.String ipAddress
          The IP address to bind the controller to.
private  boolean isShuttingDown
           
(package private) static Trace logger
          Logger instance.
private  int portNumber
          C-JDBC controller port number listening for driver connections
private  ReportManager report
          Report Manager
private  ControllerSecurityManager security
          Security Manager
private  java.util.Hashtable virtualDatabases
          Hashtable of VirtualDatabase objects.
 
Fields inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
 
Fields inherited from class javax.management.StandardMBean
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
Controller(java.lang.String ipAddress, int port, int backlog)
          Creates a new Controller instance.
 
Method Summary
 void addDriver(byte[] bytes)
          Adds a driver jar file sent in its binary form in the drivers directory of the controller.
 void addVirtualDatabase(VirtualDatabase vdb)
          Registers a new VirtualDatabase in this controller.
 void addVirtualDatabase(VirtualDatabase vdb, int autoLoad, java.lang.String checkPoint)
          Add the virtual database with the specified options
 void addVirtualDatabases(java.lang.String xml)
          Register a VirtualDatabase with default options
 void addVirtualDatabases(java.lang.String xml, java.lang.String vdbName, int autoEnable, java.lang.String checkpoint)
          Adds virtual databases contained in the XML document given as a String.
 void endOfController(java.lang.Exception fatal)
          Create report about fatal error
 java.lang.String generateLogReport()
          Generate a log report on the controller now
 java.lang.String generateReport()
          Generate a report on the controller now
 java.lang.String getAssociatedString()
          Allow to retrieve internationalization description on mbeans as well
 int getBacklogSize()
          Get the controller socket backlog size.
 java.util.Hashtable getConfiguration()
          Get current configuration options
 ControllerServerThread getConnectionThread()
          Access the connection thread.
 java.lang.String getControllerName()
          Returns the controller name.
 java.lang.String getIPAddress()
          Get the IP address to bind the controller to
 boolean getJmxEnable()
          Returns jmx enable
 java.lang.String getJmxName()
          Return the jmx name of this controller (hostname:rmiport)
 java.lang.String getLoggingConfiguration()
          Get the configuration of the logging now.
 int getPortNumber()
          Get the controller port number
 ReportManager getReport()
          Returns the report value.
 ControllerSecurityManager getSecurity()
           
static java.lang.String getVersion()
          Returns Version as a long String
 java.lang.String getVersionNumber()
          Gets the controller version.
 VirtualDatabase getVirtualDatabase(java.lang.String virtualDatabaseName)
          Gets the VirtualDatabase object corresponding to a virtual database name.
 java.util.ArrayList getVirtualDatabaseNames()
          Returns the names of currently available virtual databases.
 java.util.ArrayList getVirtualDatabases()
          Returns information about the available virtual databases.
 java.lang.String getXml()
          Return the xml version of the controller.xml file without doc type declaration, just data.
 java.lang.String getXmlController()
          Return the xml version of the controller.xml file without doc type declaration, just data.
 java.lang.String getXmlVirtualDatabases()
          Same as above but for the virtual databases.
 boolean hasVirtualDatabase(java.lang.String name)
          Tests if a VirtualDatabase of a given name exists in this controller.
 boolean isSecurityEnabled()
          Check whether security is enabled or not
 boolean isShuttingDown()
          Is the controller shutting down ?
 void launch()
          Actively launch the controller.
 java.lang.String loadXmlConfiguration(java.lang.String filename, java.lang.String virtualName, int autoLoad, java.lang.String checkPoint)
          Read a XML configuration file and load only the VirtualDatabase specified in the arguments list
static void main(java.lang.String[] args)
          Launches the C-JDBC controller and bind it with RMI registry.
 void refreshLogConfiguration()
          Refreshs the logging system configuration by re-reading the log4j.properties file.
 java.lang.String removeVirtualDatabase(java.lang.String virtualname)
          Prevent the controller from accessing a virtual database thereafter
 java.lang.String saveConfiguration()
          Save current configuration of the controller to a default file
 void setBacklogSize(int size)
          Set the controller socket backlog size.
 void setConfiguration(java.util.Hashtable configuration)
          Sets the configuration value.
 void setIPAddress(java.lang.String ipAddress)
          Set the IP address to bind the controller to
 void setJmxEnable(boolean enable)
          set enable JMX
 void setPortNumber(int port)
          Set the controller backlog size.
 void setReport(ReportManager report)
          Sets the report value.
 void setSecurity(ControllerSecurityManager security)
           
 void shutdown(int level)
          Turns the controller down by using default shutdown level
 void updateLogConfigurationFile(java.lang.String newConfiguration)
          Update the log4j configuration file with the given content Also call refreshLogConfiguration method
 java.lang.String viewLogConfigurationFile()
          Retrieve the content of the log4j configuration file
 
Methods inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
addNotificationListener, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getNotificationInfo, getParameterName, getParameterName, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class javax.management.StandardMBean
cacheMBeanInfo, getAttribute, getAttributes, getCachedMBeanInfo, getClassName, getConstructors, getDescription, getImpact, getImplementation, getImplementationClass, getMBeanInfo, getMBeanInterface, invoke, setAttribute, setAttributes, setImplementation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

portNumber

private int portNumber
C-JDBC controller port number listening for driver connections


backlogSize

private int backlogSize

ipAddress

private java.lang.String ipAddress
The IP address to bind the controller to. Useful for machines that contain multiple network interface cards and wish to bind to a specific card. Default evaluates to localhost IP address (127.0.0.1).


connectionThread

private ControllerServerThread connectionThread
Thread that listens for driver connections


logger

static Trace logger
Logger instance.


virtualDatabases

private java.util.Hashtable virtualDatabases
Hashtable of VirtualDatabase objects.


configuration

private java.util.Hashtable configuration
Hashtable of options


security

private ControllerSecurityManager security
Security Manager


report

private ReportManager report
Report Manager


isShuttingDown

private boolean isShuttingDown
Constructor Detail

Controller

public Controller(java.lang.String ipAddress,
                  int port,
                  int backlog)
           throws javax.management.NotCompliantMBeanException,
                  JmxException
Creates a new Controller instance.

Parameters:
ipAddress - bind the controller to this ipAddress
port - bind the controller to listen to this port
backlog - backlog connection size
Throws:
javax.management.NotCompliantMBeanException - in case the bean does not comply with jmx
JmxException - the bean could not be registered
Method Detail

addVirtualDatabases

public void addVirtualDatabases(java.lang.String xml,
                                java.lang.String vdbName,
                                int autoEnable,
                                java.lang.String checkpoint)
                         throws ControllerException
Adds virtual databases contained in the XML document given as a String. If a virtual database name is provided, only this database is loaded with the provided autoLoad and checkpoint information.

Parameters:
xml - XML configuration file content
vdbName - optional virtual database name to autoload
autoEnable - autoenable backend mode for virtual database
checkpoint - checkpoint name if autoEnable is set to force
Throws:
ControllerException - if an error occurs

addVirtualDatabases

public void addVirtualDatabases(java.lang.String xml)
                         throws ControllerException
Register a VirtualDatabase with default options

Specified by:
addVirtualDatabases in interface ControllerMBean
Parameters:
xml - XML code to parse
Throws:
ControllerException - if an error occurs while interpreting XML
See Also:
ControllerMBean.addVirtualDatabases(String)

addVirtualDatabase

public void addVirtualDatabase(VirtualDatabase vdb)
                        throws ControllerException
Registers a new VirtualDatabase in this controller.

Parameters:
vdb - the VirtualDatabase to register
Throws:
ControllerException - if an error occurs

addVirtualDatabase

public void addVirtualDatabase(VirtualDatabase vdb,
                               int autoLoad,
                               java.lang.String checkPoint)
                        throws ControllerException
Add the virtual database with the specified options

Parameters:
vdb - the VirtualDatabase object to add
autoLoad - specified if backends should be enabled
checkPoint - specified the checkPoint to recover from, leave null if no recovery speficied
Throws:
ControllerException - if database already exists on the specified Controller object

getVirtualDatabase

public VirtualDatabase getVirtualDatabase(java.lang.String virtualDatabaseName)
Gets the VirtualDatabase object corresponding to a virtual database name.

Parameters:
virtualDatabaseName - the virtual database name
Returns:
a VirtualDatabase object or null if not found

getVirtualDatabaseNames

public java.util.ArrayList getVirtualDatabaseNames()
Description copied from interface: ControllerMBean
Returns the names of currently available virtual databases.

Specified by:
getVirtualDatabaseNames in interface ControllerMBean
Returns:
ArrayList of String objects.
See Also:
ControllerMBean.getVirtualDatabaseNames()

getVirtualDatabases

public java.util.ArrayList getVirtualDatabases()
Returns information about the available virtual databases.

Returns:
ArrayList of information about virtual databases.

hasVirtualDatabase

public boolean hasVirtualDatabase(java.lang.String name)
Tests if a VirtualDatabase of a given name exists in this controller.

Specified by:
hasVirtualDatabase in interface ControllerMBean
Parameters:
name - the virtual database name
Returns:
true if the virtual database exists

removeVirtualDatabase

public java.lang.String removeVirtualDatabase(java.lang.String virtualname)
                                       throws ControllerException
Description copied from interface: ControllerMBean
Prevent the controller from accessing a virtual database thereafter

Specified by:
removeVirtualDatabase in interface ControllerMBean
Parameters:
virtualname - the virtual database name to remove
Returns:
description message
Throws:
ControllerException
See Also:
ControllerMBean.removeVirtualDatabase(String)

addDriver

public void addDriver(byte[] bytes)
               throws java.lang.Exception
Description copied from interface: ControllerMBean
Adds a driver jar file sent in its binary form in the drivers directory of the controller.

Specified by:
addDriver in interface ControllerMBean
Parameters:
bytes - the data in a byte array
Throws:
java.lang.Exception - if fails
See Also:
ControllerMBean.addDriver(byte[])

loadXmlConfiguration

public java.lang.String loadXmlConfiguration(java.lang.String filename,
                                             java.lang.String virtualName,
                                             int autoLoad,
                                             java.lang.String checkPoint)
                                      throws java.lang.Exception
Read a XML configuration file and load only the VirtualDatabase specified in the arguments list

Parameters:
filename - XML configuration file name to take info on VirtualDatabase
virtualName - the only database to load, null if should load all
autoLoad - specifies if the backends should be enabled automatically after loading
checkPoint - checkPoint to recover from when enabling backends. Leave null if no recovery option is needed.
Returns:
a diagnostic message (success or error)
Throws:
java.lang.Exception - if an error occurs

saveConfiguration

public java.lang.String saveConfiguration()
                                   throws VirtualDatabaseException
Save current configuration of the controller to a default file

Specified by:
saveConfiguration in interface ControllerMBean
Returns:
Status message
Throws:
VirtualDatabaseException - if an error occurs
See Also:
ControllerConstants.getSaveFile(java.lang.String)

endOfController

public void endOfController(java.lang.Exception fatal)
Create report about fatal error

Parameters:
fatal - the cause of the fatal error

getConnectionThread

public ControllerServerThread getConnectionThread()
Access the connection thread. Need this for shutting down

Returns:
connectionThread

isShuttingDown

public boolean isShuttingDown()
Description copied from interface: ControllerMBean
Is the controller shutting down ?

Specified by:
isShuttingDown in interface ControllerMBean
Returns:
true if the controller is no more accepting connection
See Also:
ControllerMBean.isShuttingDown()

shutdown

public void shutdown(int level)
              throws ControllerException
Description copied from interface: ControllerMBean
Turns the controller down by using default shutdown level

Specified by:
shutdown in interface ControllerMBean
Parameters:
level - Smart,Fast or Immediate.
Throws:
ControllerException - if unknown level or other error occurs.
See Also:
ControllerMBean.shutdown(int)

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Launches the C-JDBC controller and bind it with RMI registry. The available options are:

The controller starts listening for socket connections on the default port. Jmx is configured, and a virtual database can be added.

ControllerConstants.DEFAULT_PORT Default Listening port

Parameters:
args - command line arguments (see above)
Throws:
java.lang.Exception - when everything goes wrong

launch

public void launch()
Actively launch the controller. Add startup actions here to avoid them in main


getControllerName

public java.lang.String getControllerName()
Returns the controller name.

Specified by:
getControllerName in interface ControllerMBean
Returns:
String

getIPAddress

public java.lang.String getIPAddress()
Get the IP address to bind the controller to

Returns:
the IP address

setIPAddress

public void setIPAddress(java.lang.String ipAddress)
Set the IP address to bind the controller to

Parameters:
ipAddress - the IP address to use

getPortNumber

public int getPortNumber()
Get the controller port number

Specified by:
getPortNumber in interface ControllerMBean
Returns:
the port number

setPortNumber

public void setPortNumber(int port)
Set the controller backlog size.

Parameters:
port - the port number to set

getBacklogSize

public int getBacklogSize()
Description copied from interface: ControllerMBean
Get the controller socket backlog size.

Specified by:
getBacklogSize in interface ControllerMBean
Returns:
the backlog size
See Also:
ControllerMBean.getBacklogSize()

setBacklogSize

public void setBacklogSize(int size)
Description copied from interface: ControllerMBean
Set the controller socket backlog size.

Specified by:
setBacklogSize in interface ControllerMBean
Parameters:
size - backlog size
See Also:
ControllerMBean.setBacklogSize(int)

getJmxEnable

public boolean getJmxEnable()
Returns jmx enable

Returns:
jmxEnabled

getJmxName

public java.lang.String getJmxName()
Return the jmx name of this controller (hostname:rmiport)

Specified by:
getJmxName in interface ControllerMBean
Returns:
jmx name

setJmxEnable

public void setJmxEnable(boolean enable)
set enable JMX

Parameters:
enable - true if jmx should be enable.

getVersion

public static java.lang.String getVersion()
Returns Version as a long String

Returns:
version

getConfiguration

public java.util.Hashtable getConfiguration()
Get current configuration options

Returns:
configure a Hashtable with controller options

isSecurityEnabled

public boolean isSecurityEnabled()
Check whether security is enabled or not

Returns:
true if there is not null controller security manager

getSecurity

public ControllerSecurityManager getSecurity()
Returns:
Returns the security.

setSecurity

public void setSecurity(ControllerSecurityManager security)
Parameters:
security - The security to set.

generateReport

public java.lang.String generateReport()
                                throws java.lang.Exception
Description copied from interface: ControllerMBean
Generate a report on the controller now

Specified by:
generateReport in interface ControllerMBean
Returns:
the content of the report
Throws:
java.lang.Exception - if fails
See Also:
ControllerMBean.generateReport()

getLoggingConfiguration

public java.lang.String getLoggingConfiguration()
                                         throws java.lang.Exception
Description copied from interface: ControllerMBean
Get the configuration of the logging now.

Specified by:
getLoggingConfiguration in interface ControllerMBean
Returns:
a String representing the logging configuration
Throws:
java.lang.Exception - if the logging configuration can not be returned
See Also:
ControllerMBean.getLoggingConfiguration()

setConfiguration

public void setConfiguration(java.util.Hashtable configuration)
Sets the configuration value.

Parameters:
configuration - The configuration to set.

getVersionNumber

public java.lang.String getVersionNumber()
Description copied from interface: ControllerMBean
Gets the controller version.

Specified by:
getVersionNumber in interface ControllerMBean
Returns:
a String value containing the version number
See Also:
ControllerMBean.getVersionNumber()

getAssociatedString

public java.lang.String getAssociatedString()
Description copied from class: AbstractStandardMBean
Allow to retrieve internationalization description on mbeans as well

Specified by:
getAssociatedString in class AbstractStandardMBean
Returns:
part of the key to look for in the translation file.
See Also:
AbstractStandardMBean.getAssociatedString()

getXml

public java.lang.String getXml()
Description copied from interface: ControllerMBean
Return the xml version of the controller.xml file without doc type declaration, just data. The content is formatted using the controller xsl stylesheet.

Specified by:
getXml in interface ControllerMBean
Returns:
controller xml data
See Also:
XmlComponent.getXml()

getXmlController

public java.lang.String getXmlController()
Return the xml version of the controller.xml file without doc type declaration, just data.

Returns:
controller xml data

getXmlVirtualDatabases

public java.lang.String getXmlVirtualDatabases()
Same as above but for the virtual databases.

Returns:
xml virtual databases data.

generateLogReport

public java.lang.String generateLogReport()
                                   throws java.lang.Exception
Description copied from interface: ControllerMBean
Generate a log report on the controller now

Specified by:
generateLogReport in interface ControllerMBean
Returns:
the content of the logreport
Throws:
java.lang.Exception - if fails
See Also:
ControllerMBean.generateLogReport()

refreshLogConfiguration

public void refreshLogConfiguration()
                             throws ControllerException
Description copied from interface: ControllerMBean
Refreshs the logging system configuration by re-reading the log4j.properties file.

Specified by:
refreshLogConfiguration in interface ControllerMBean
Throws:
ControllerException - if the log4j.properties file cannot be found in classpath
See Also:
ControllerMBean.refreshLogConfiguration()

updateLogConfigurationFile

public void updateLogConfigurationFile(java.lang.String newConfiguration)
                                throws java.io.IOException,
                                       ControllerException
Description copied from interface: ControllerMBean
Update the log4j configuration file with the given content Also call refreshLogConfiguration method

Specified by:
updateLogConfigurationFile in interface ControllerMBean
Parameters:
newConfiguration - the content of the new log4j configuration
Throws:
java.io.IOException - if cannot access the log4j file
ControllerException - if could not refresh the logs
See Also:
ControllerMBean.updateLogConfigurationFile(java.lang.String)

viewLogConfigurationFile

public java.lang.String viewLogConfigurationFile()
                                          throws java.io.IOException
Description copied from interface: ControllerMBean
Retrieve the content of the log4j configuration file

Specified by:
viewLogConfigurationFile in interface ControllerMBean
Returns:
String
Throws:
java.io.IOException - if IO problems
See Also:
ControllerMBean.viewLogConfigurationFile()

getReport

public ReportManager getReport()
Returns the report value.

Returns:
Returns the report.

setReport

public void setReport(ReportManager report)
Sets the report value.

Parameters:
report - The report to set.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.