org.objectweb.cjdbc.controller
Class Controller

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.Controller
All Implemented Interfaces:
ControllerMBean

public class Controller
extends java.lang.Object
implements ControllerMBean

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

Field Summary
private  int backlogSize
           
private static java.util.Hashtable configure
          Hashtable of options
private  ControllerServerThread connectionThread
          Thread that listens for driver connections
private static Controller controller
          Controller static
private  java.lang.String controllerName
          C-JDBC controller name .
private  java.lang.String ipAddress
          The IP address to bind the controller to.
private static CjdbcJmxAgent jmxAgent
          JMX agent that starts the JMX server, adaptors and registers the MBeans.
(package private) static Trace logger
          Logger instance.
private  int portNumber
          C-JDBC controller port number listening for driver connections
private  java.util.Hashtable virtualDatabases
          Hashtable of VirtualDatabase objects.
 
Constructor Summary
Controller()
          Creates a new Controller instance.
Controller(java.lang.String name)
          Creates a new Controller instance with the specified controllerName
 
Method Summary
 void addDriver(byte[] bytes)
          Reads a driver binary data
 java.lang.String addDriver(java.lang.String filename)
          Reads a driver JAR file.
 void addVirtualDatabase(VirtualDatabase vdb)
          Registers a new VirtualDatabase in this controller.
 void addVirtualDatabase(VirtualDatabase vdb, boolean autoEnable, java.lang.String checkPoint)
          Add the virtual database with the specified options
 void addVirtualDatabases(java.lang.String xml)
          Register a VirtualDatabase via RMI with default options
 void addVirtualDatabases(java.lang.String xml, java.lang.String virtualName, boolean autoEnable, java.lang.String checkPoint)
          Registers one or several virtual databases in the controller.
static void endOfController(java.lang.Exception fatal)
          Create report about fatal error
static boolean getAllowAddDriver()
          get allow add driver
 int getBacklogSize()
          Get the controller socket backlog size.
 java.lang.String getBindName()
          Returns the controller name.
static java.util.Hashtable getConfiguration()
          Get current configuration options
 ControllerServerThread getConnectionThread()
          Access the connection thread.
 java.lang.String getInformation()
           
 java.lang.String getIPAddress()
          Get the IP address to bind the controller to
 JmxAgent getJmxAgent()
          Returns the jmxAgent.
static boolean getJmxEnable()
          Returns jmx enable
 int getPortNumber()
          Get the controller port number
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 getVirtualDatabases()
          Returns information about the available virtual databases.
 java.util.ArrayList getVirtualDatabasesInfo()
          Returns the available virtual databases.
 java.lang.String getXmlInformation()
          Return the controller information in XML format.
 boolean hasVirtualDatabase(java.lang.String name)
          Tests if a VirtualDatabase of a given name exists in this controller.
 void launch()
          Actively launch the controller Add startup actions here to avoid them in main
 java.lang.String loadXML(java.lang.String filename)
          Read a XML configuration file for a set of virtual databases
 java.lang.String loadXmlConfiguration(java.lang.String filename, java.lang.String virtualName, boolean autoEnable, 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
 java.lang.String saveConfiguration(java.lang.String filepath)
          Save current configuration to the file specified as argument.
static void setAllowAddDriver(boolean enable)
          Set allow add driver
 void setBacklogSize(int size)
          Set the controller socket backlog size.
 void setBindName(java.lang.String controllerName)
          Sets the controller name
 void setIPAddress(java.lang.String ipAddress)
          Set the IP address to bind the controller to
 void setJMXAgent(CjdbcJmxAgent agent)
          Set the JmxAgent
static void setJmxEnable(boolean enable)
          set enable JMX
 void setPortNumber(int port)
          Set the controller backlog size.
 void shutdown()
          Turns the controller down by using default shutdown level
 void shutdown(int level)
          Turns the controller down by using default shutdown level
 java.lang.String viewConfiguration()
          Retrieve the configuration about this controller in xml format.
 java.lang.String viewInfo()
          Retrieve the information about this controller in xml format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

controllerName

private java.lang.String controllerName
C-JDBC controller name .


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


jmxAgent

private static CjdbcJmxAgent jmxAgent
JMX agent that starts the JMX server, adaptors and registers the MBeans.


logger

static Trace logger
Logger instance.


virtualDatabases

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


configure

private static java.util.Hashtable configure
Hashtable of options


controller

private static Controller controller
Controller static

Constructor Detail

Controller

public Controller(java.lang.String name)
Creates a new Controller instance with the specified controllerName

Parameters:
name - the controllerName to register the controller with

Controller

public Controller()
Creates a new Controller instance.

Method Detail

addVirtualDatabases

public void addVirtualDatabases(java.lang.String xml,
                                java.lang.String virtualName,
                                boolean autoEnable,
                                java.lang.String checkPoint)
                         throws ControllerException
Description copied from interface: ControllerMBean
Registers one or several virtual databases in the controller. The description of each Virtual Database must contain the definition of the backends and components (cache, scheduler, load balancer) to use.

This function expects the content of an XML file conforming to the C-JDBC DTD to be given as a single String object.

Specified by:
addVirtualDatabases in interface ControllerMBean
Parameters:
xml - XML code to parse
virtualName - name of the virtual database
autoEnable - specify if should be enabled as soon as it is added
checkPoint - the checkpoint to use to enable the database
Throws:
ControllerException - if an error occurs while interpreting XML
See Also:
org.objectweb.cjdbc.controller.ControllerInterface#addVirtualDatabases(java.lang.String)

addVirtualDatabases

public void addVirtualDatabases(java.lang.String xml)
                         throws ControllerException
Register a VirtualDatabase via RMI 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:
org.objectweb.cjdbc.controller.ControllerInterface#addVirtualDatabases(java.lang.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,
                               boolean autoEnable,
                               java.lang.String checkPoint)
                        throws ControllerException
Add the virtual database with the specified options

Parameters:
vdb - the VirtualDatabase object to add
autoEnable - 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

viewInfo

public java.lang.String viewInfo()
                          throws java.lang.Exception
Description copied from interface: ControllerMBean
Retrieve the information about this controller in xml format.

Specified by:
viewInfo in interface ControllerMBean
Returns:
the complete xml formatted description of this controller
Throws:
java.lang.Exception - if fails
See Also:
ControllerMBean.viewInfo()

viewConfiguration

public java.lang.String viewConfiguration()
                                   throws java.lang.Exception
Description copied from interface: ControllerMBean
Retrieve the configuration about this controller in xml format.

Specified by:
viewConfiguration in interface ControllerMBean
Returns:
the complete xml formatted description of this controller
Throws:
java.lang.Exception - if fails
See Also:
ControllerMBean.viewConfiguration()

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(java.lang.String)

addDriver

public void addDriver(byte[] bytes)
               throws java.lang.Exception
Description copied from interface: ControllerMBean
Reads a driver binary data

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[])

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

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()

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()

getXmlInformation

public java.lang.String getXmlInformation()
                                   throws VirtualDatabaseException
Return the controller information in XML format.

Returns:
controller information in XML format
Throws:
VirtualDatabaseException - if an error occurs

getConnectionThread

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

Returns:
connectionThread

shutdown

public void shutdown()
              throws ControllerException
Turns the controller down by using default shutdown level

Throws:
ControllerException
See Also:
ControllerMBean.shutdown(int)

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)

saveConfiguration

public java.lang.String saveConfiguration()
                                   throws java.io.IOException,
                                          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
java.io.IOException - if writing failed
See Also:
ControllerConstants.getSaveConfigurationFile()

saveConfiguration

public java.lang.String saveConfiguration(java.lang.String filepath)
                                   throws VirtualDatabaseException
Save current configuration to the file specified as argument.

Parameters:
filepath - path to save file
Returns:
status message
Throws:
VirtualDatabaseException - if error occurs

getInformation

public java.lang.String getInformation()
See Also:
org.objectweb.cjdbc.controller.ControllerInterface#getInformation()

hasVirtualDatabase

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

Parameters:
name - the virtual database name
Returns:
true if the virtual database exists

main

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

If the RMI registry does not exist, a RMI registry that accepts requests on the specified port is automatically started. The controller is registered in the registry under the '/C-JDBC/Controller/name' name, name being the specified controller name.

If no port number or controller name are specified, else the default org.objectweb.cjdbc.controller.ControllerConstants#DEFAULT_RMI_PORT RMI port value, default org.objectweb.cjdbc.controller.ControllerConstants#DEFAULT_JMX_PORT JMX port value, and the default 'ControllerConstants.DEFAULT_NAME' controller name are used.

Parameters:
args - command line arguments (see above)

endOfController

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

Parameters:
fatal - the cause of the fatal error

launch

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


getBindName

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

Specified by:
getBindName in interface ControllerMBean
Returns:
String

setBindName

public void setBindName(java.lang.String controllerName)
Sets the controller name

Parameters:
controllerName - The controller name

loadXmlConfiguration

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

Specified by:
loadXmlConfiguration in interface ControllerMBean
Parameters:
filename - XML configuration file name to take info on VirtualDatabase
virtualName - the only database to load
autoEnable - 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

loadXML

public java.lang.String loadXML(java.lang.String filename)
                         throws java.lang.Exception
Read a XML configuration file for a set of virtual databases

Specified by:
loadXML in interface ControllerMBean
Parameters:
filename - XML configuration file name
Returns:
a diagnostic message (success or error)
Throws:
java.lang.Exception - if an error occurs

addDriver

public java.lang.String addDriver(java.lang.String filename)
                           throws java.lang.Exception
Reads a driver JAR file.

Specified by:
addDriver in interface ControllerMBean
Parameters:
filename - name of the file
Returns:
a diagnostic message
Throws:
java.lang.Exception - if an error occurs

getVirtualDatabasesInfo

public java.util.ArrayList getVirtualDatabasesInfo()
                                            throws java.lang.Exception
Returns the available virtual databases.

Returns:
ArrayList of virtual databases.
Throws:
java.lang.Exception - if an error occurs

getVirtualDatabases

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

Specified by:
getVirtualDatabases in interface ControllerMBean
Returns:
ArrayList of information about virtual databases.
Throws:
java.lang.Exception - if an error occurs

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()
Get the controller socket backlog size.

Returns:
the backlog size

setBacklogSize

public void setBacklogSize(int size)
Set the controller socket backlog size.

Parameters:
size - backlog size

getJmxAgent

public JmxAgent getJmxAgent()
Returns the jmxAgent.

Returns:
JmxAgent

setJMXAgent

public void setJMXAgent(CjdbcJmxAgent agent)
Set the JmxAgent

Parameters:
agent - the jmx agent

getJmxEnable

public static boolean getJmxEnable()
Returns jmx enable

Returns:
jmxEnabled

setJmxEnable

public static void setJmxEnable(boolean enable)
set enable JMX

Parameters:
enable - true if jmx should be enable.

setAllowAddDriver

public static void setAllowAddDriver(boolean enable)
Set allow add driver

Parameters:
enable - true/false

getAllowAddDriver

public static boolean getAllowAddDriver()
get allow add driver

Returns:
true if additionnal driver jars can be loaded.

getVersion

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

Returns:
version

getConfiguration

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

Returns:
configure a Hashtable with controller options


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