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

org.objectweb.cjdbc.controller.core.Controller Class Reference

Collaboration diagram for org.objectweb.cjdbc.controller.core.Controller:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Controller (String ipAddress, int port, int backlog) throws NotCompliantMBeanException, JmxException
void addVirtualDatabases (String xml, String vdbName, int autoEnable, String checkpoint) throws ControllerException
void addVirtualDatabases (String xml) throws ControllerException
void addVirtualDatabase (VirtualDatabase vdb) throws ControllerException
synchronized void addVirtualDatabase (VirtualDatabase vdb, int autoLoad, String checkPoint) throws ControllerException
VirtualDatabase getVirtualDatabase (String virtualDatabaseName)
ArrayList getVirtualDatabaseNames ()
ArrayList getVirtualDatabases ()
boolean hasVirtualDatabase (String name)
String removeVirtualDatabase (String virtualname) throws ControllerException
void addDriver (byte[] bytes) throws Exception
String loadXmlConfiguration (String filename, String virtualName, int autoLoad, String checkPoint) throws Exception
String loadXml (String filename) throws Exception
String saveConfiguration () throws VirtualDatabaseException
void endOfController (Exception fatal)
ControllerServerThread getConnectionThread ()
boolean isShuttingDown ()
void shutdown (int level) throws ControllerException
void launch ()
String getControllerName ()
String getIPAddress ()
void setIPAddress (String ipAddress)
int getPortNumber ()
void setPortNumber (int port)
int getBacklogSize ()
void setBacklogSize (int size)
boolean getJmxEnable ()
String getJmxName ()
void setJmxEnable (boolean enable)
Hashtable getConfiguration ()
boolean isSecurityEnabled ()
ControllerSecurityManager getSecurity ()
void setSecurity (ControllerSecurityManager security)
String generateReport () throws Exception
void setConfiguration (Hashtable configuration)
String getVersionNumber ()
String getAssociatedString ()
String getXml ()
String getXmlController ()
String getXmlVirtualDatabases ()
String generateLogReport () throws Exception
void refreshLogConfiguration () throws ControllerException
void updateLogConfigurationFile (String newConfiguration) throws IOException, ControllerException
String viewLogConfigurationFile () throws IOException
ReportManager getReport ()
void setReport (ReportManager report)

Static Public Member Functions

void main (String args[]) throws Exception
String getVersion ()

Static Package Attributes

Trace logger

Detailed Description

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

Author:
Emmanuel Cecchet

Mathieu Peltier

Nicolas Modrzyk

Duncan Smith

Version:
1.0

Definition at line 87 of file Controller.java.


Constructor & Destructor Documentation

org.objectweb.cjdbc.controller.core.Controller.Controller String  ipAddress,
int  port,
int  backlog
throws 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
Exceptions:
NotCompliantMBeanException in case the bean does not comply with jmx
JmxException the bean could not be registered

Definition at line 137 of file Controller.java.

00139   {
00140     super(ControllerMBean.class);
00141     virtualDatabases = new Hashtable();
00142     this.ipAddress = ipAddress;
00143     this.portNumber = port;
00144     this.backlogSize = backlog;
00145     ObjectName name = JmxConstants.getControllerObjectName();
00146     MBeanServerManager.registerMBean(this, name);
00147   }


Member Function Documentation

void org.objectweb.cjdbc.controller.core.Controller.addDriver byte[]  bytes  )  throws Exception
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.addDriver(byte[])

Definition at line 392 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.logger.

00393   {
00394     // Try to find drivers directory in the classpath
00395     File driversDirectory = null;
00396     URL url = Controller.class
00397         .getResource(ControllerConstants.C_JDBC_DRIVER_JAR_FILE);
00398     boolean error = false;
00399     if (url != null)
00400     {
00401       driversDirectory = (new File(URLDecoder.decode(url.getFile())))
00402           .getParentFile();
00403       error = (driversDirectory == null) || !driversDirectory.exists();
00404     }
00405 
00406     if (error)
00407     {
00408       String msg = Translate.get("controller.driver.dir.not.found");
00409       logger.error(msg);
00410       throw new ControllerException(msg);
00411     }
00412 
00413     // Read the array of bytes to a file
00414     File temp = null;
00415     try
00416     {
00417       temp = File.createTempFile("driver", "zip", driversDirectory);
00418       FileOutputStream output = new FileOutputStream(temp);
00419       output.write(bytes);
00420       output.close();
00421     }
00422     catch (IOException e)
00423     {
00424       String msg = Translate.get("controller.add.jar.read.failed", e);
00425       logger.error(msg);
00426       throw new ControllerException(msg);
00427     }
00428 
00429     // Unzip the file content
00430     try
00431     {
00432       Enumeration entries;
00433       ZipFile zipFile = new ZipFile(temp);
00434 
00435       // Read the file
00436       int lenght;
00437       InputStream in;
00438       BufferedOutputStream out;
00439       byte[] buffer = new byte[1024];
00440 
00441       entries = zipFile.entries();
00442       while (entries.hasMoreElements())
00443       {
00444         ZipEntry entry = (ZipEntry) entries.nextElement();
00445 
00446         if (entry.isDirectory())
00447         {
00448           // Create the directory
00449           if (logger.isDebugEnabled())
00450             logger.debug(Translate.get("controller.add.jar.extract.dir", entry
00451                 .getName()));
00452 
00453           (new File(driversDirectory, entry.getName())).mkdir();
00454           continue;
00455         }
00456 
00457         // Extract the file
00458         if (logger.isDebugEnabled())
00459           logger.debug(Translate.get("controller.add.jar.extract.file", entry
00460               .getName()));
00461 
00462         in = zipFile.getInputStream(entry);
00463         out = new BufferedOutputStream(new FileOutputStream(driversDirectory
00464             + System.getProperty("file.separator") + entry.getName()));
00465         while ((lenght = in.read(buffer)) >= 0)
00466           out.write(buffer, 0, lenght);
00467 
00468         in.close();
00469         out.close();
00470       }
00471 
00472       zipFile.close();
00473       temp.delete();
00474       logger.info(Translate.get("controller.add.jar.to.directory",
00475           driversDirectory.toString()));
00476     }
00477     catch (IOException e)
00478     {
00479       String msg = Translate.get("controller.driver.extract.failed", e);
00480       logger.error(msg);
00481       throw new ControllerException(msg);
00482     }
00483   }

synchronized void org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabase VirtualDatabase  vdb,
int  autoLoad,
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
Exceptions:
ControllerException if database already exists on the specified Controller object

Definition at line 227 of file Controller.java.

References org.objectweb.cjdbc.controller.xml.DatabasesParser.error(), org.objectweb.cjdbc.controller.core.Controller.hasVirtualDatabase(), and org.objectweb.cjdbc.controller.core.Controller.logger.

00229   {
00230     // Add the database or retrieve it if it already exists
00231     if (hasVirtualDatabase(vdb.getDatabaseName()))
00232     {
00233       String msg = Translate.get("controller.database.already.exists", vdb
00234           .getDatabaseName());
00235       logger.warn(msg);
00236       throw new ControllerException(msg);
00237     }
00238     else
00239     {
00240       virtualDatabases.put(vdb.getDatabaseName(), vdb);
00241 
00242       // Send notification
00243       if (MBeanServerManager.isJmxEnabled())
00244       {
00245         Hashtable databases = new Hashtable();
00246         try
00247         {
00248           databases.put("backends", vdb.getAllBackendNames());
00249         }
00250         catch (VirtualDatabaseException e)
00251         {
00252           // ignore
00253         }
00254         RmiConnector.broadcastNotification(this,
00255             CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_ADDED,
00256             CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get(
00257                 "notification.virtualdatabase.added", vdb
00258                     .getVirtualDatabaseName()), databases);
00259       }
00260     }
00261 
00262     // Enable backends with the proper states
00263     try
00264     {
00265       if (logger.isDebugEnabled())
00266         logger.debug(Translate.get("controller.database.autoenable", autoLoad));
00267 
00268       switch (autoLoad)
00269       {
00270         case ControllerConstants.AUTO_ENABLE_TRUE :
00271           vdb.enableAllBackendsFromCheckpoint();
00272           break;
00273         case ControllerConstants.AUTO_ENABLE_FALSE :
00274           break;
00275         case ControllerConstants.AUTO_ENABLE_FORCE :
00276           logger.warn("Backends enabled in force mode from checkpoint "
00277               + checkPoint);
00278           vdb.forceEnableAllBackendsFromCheckpoint(checkPoint);
00279           break;
00280         default :
00281           logger
00282               .error("Unsupported autoEnabledBackends mode in controller configuration");
00283           break;
00284       }
00285     }
00286     catch (VirtualDatabaseException e)
00287     {
00288       throw new ControllerException(e);
00289     }
00290 
00291     logger.info(Translate.get("controller.add.virtualdatabase", vdb
00292         .getDatabaseName()));
00293   }

void org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabase VirtualDatabase  vdb  )  throws ControllerException
 

Registers a new VirtualDatabase in this controller.

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

Definition at line 210 of file Controller.java.

00212   {
00213     this.addVirtualDatabase(vdb, ControllerConstants.AUTO_ENABLE_BACKEND,
00214         ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00215   }

void org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabases String  xml  )  throws ControllerException
 

Register a VirtualDatabase with default options

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.addVirtualDatabases(String)

Definition at line 193 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.logger.

00194   {
00195     if (logger.isDebugEnabled())
00196     {
00197       logger.debug(Translate.get("controller.loading.virtualdatabase"));
00198     }
00199     this.addVirtualDatabases(xml, null,
00200         ControllerConstants.AUTO_ENABLE_BACKEND,
00201         ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00202   }

void org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabases String  xml,
String  vdbName,
int  autoEnable,
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
Exceptions:
ControllerException if an error occurs

Definition at line 164 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.logger, and org.objectweb.cjdbc.controller.xml.DatabasesParser.readXML().

Referenced by org.objectweb.cjdbc.controller.core.Controller.loadXmlConfiguration().

00166   {
00167     if (logger.isDebugEnabled())
00168       logger.debug(Translate.get("controller.add.virtualdatabase", vdbName));
00169     if (vdbName != null && this.hasVirtualDatabase(vdbName))
00170     {
00171       throw new ControllerException(Translate
00172           .get("controller.add.virtualdatabase.already.used"));
00173     }
00174     try
00175     {
00176       DatabasesParser parser = new DatabasesParser(this, vdbName, autoEnable,
00177           checkpoint);
00178       parser.readXML(xml, true);
00179     }
00180     catch (Exception e)
00181     {
00182       String msg = Translate.get("controller.add.virtualdatabase.failed", e);
00183       logger.warn(msg, e);
00184       throw new ControllerException(msg);
00185     }
00186   }

void org.objectweb.cjdbc.controller.core.Controller.endOfController Exception  fatal  ) 
 

Create report about fatal error

Parameters:
fatal the cause of the fatal error

Definition at line 597 of file Controller.java.

References org.objectweb.cjdbc.controller.core.ReportManager.getReportLocation(), org.objectweb.cjdbc.controller.core.ReportManager.isGenerateOnFatal(), and org.objectweb.cjdbc.controller.core.Controller.logger.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread().

00598   {
00599     logger.fatal(Translate.get("fatal.error"));
00600     if (report.isGenerateOnFatal())
00601     {
00602       new ReportManager(this, fatal).generate();
00603       logger.info(Translate.get("fatal.report.generated", report
00604           .getReportLocation()
00605           + File.separator + ControllerConstants.REPORT_FILE));
00606     }
00607     Runtime.getRuntime().exit(1);
00608   }

String org.objectweb.cjdbc.controller.core.Controller.generateLogReport  )  throws Exception
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.generateLogReport()

Definition at line 1040 of file Controller.java.

References org.objectweb.cjdbc.controller.core.ReportManager.generateJustLogs().

01041   {
01042     ReportManager report = new ReportManager(this, true);
01043     return report.generateJustLogs();
01044   }

String org.objectweb.cjdbc.controller.core.Controller.generateReport  )  throws Exception
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.generateReport()

Definition at line 905 of file Controller.java.

References org.objectweb.cjdbc.controller.core.ReportManager.generate(), and org.objectweb.cjdbc.controller.core.ReportManager.startReport().

00906   {
00907     report.startReport();
00908     return report.generate();
00909   }

String org.objectweb.cjdbc.controller.core.Controller.getAssociatedString  ) 
 

See also:
org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean.getAssociatedString()

Definition at line 932 of file Controller.java.

00933   {
00934     return "controller";
00935   }

int org.objectweb.cjdbc.controller.core.Controller.getBacklogSize  ) 
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.getBacklogSize()

Definition at line 806 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread().

00807   {
00808     return backlogSize;
00809   }

Hashtable org.objectweb.cjdbc.controller.core.Controller.getConfiguration  ) 
 

Get current configuration options

Returns:
configure a Hashtable with controller options

Definition at line 871 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ReportManager.writeControllerSettings().

00872   {
00873     return configuration;
00874   }

ControllerServerThread org.objectweb.cjdbc.controller.core.Controller.getConnectionThread  ) 
 

Access the connection thread. Need this for shutting down

Returns:
connectionThread

Definition at line 615 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.shutdownServerConnectionThread().

00616   {
00617     return connectionThread;
00618   }

String org.objectweb.cjdbc.controller.core.Controller.getControllerName  ) 
 

Returns the controller name.

Returns:
String

Definition at line 758 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase.getControllerName(), org.objectweb.cjdbc.controller.core.Controller.getJmxName(), org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase.handleMessageMultiThreaded(), and org.objectweb.cjdbc.controller.core.Controller.launch().

00759   {
00760     return ipAddress + ":" + portNumber;
00761   }

String org.objectweb.cjdbc.controller.core.Controller.getIPAddress  ) 
 

Get the IP address to bind the controller to

Returns:
the IP address

Definition at line 768 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread(), and org.objectweb.cjdbc.controller.core.ControllerFactory.setUpJmx().

00769   {
00770     return ipAddress;
00771   }

boolean org.objectweb.cjdbc.controller.core.Controller.getJmxEnable  ) 
 

Returns jmx enable

Returns:
jmxEnabled

Definition at line 824 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.Controller.getJmxName(), org.objectweb.cjdbc.controller.core.Controller.getXmlController(), and org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.shutdownJmxAgent().

00825   {
00826     return MBeanServerManager.isJmxEnabled();
00827   }

String org.objectweb.cjdbc.controller.core.Controller.getJmxName  ) 
 

Return the jmx name of this controller (hostname:rmiport)

Returns:
jmx name

Definition at line 834 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.getControllerName(), org.objectweb.cjdbc.controller.jmx.RmiConnector.getHostName(), org.objectweb.cjdbc.controller.core.Controller.getJmxEnable(), and org.objectweb.cjdbc.controller.jmx.RmiConnector.getPort().

Referenced by org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase.handleMessageMultiThreaded(), and org.objectweb.cjdbc.controller.virtualdatabase.DistributedVirtualDatabase.joinGroup().

00835   {
00836     if (getJmxEnable())
00837     {
00838       RmiConnector connector = ((RmiConnector) RmiConnector.getRmiConnectors()
00839           .get(0));
00840       return connector.getHostName() + ":" + connector.getPort();
00841     }
00842     else
00843       return getControllerName();
00844   }

int org.objectweb.cjdbc.controller.core.Controller.getPortNumber  ) 
 

Get the controller port number

Returns:
the port number

Definition at line 788 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread().

00789   {
00790     return portNumber;
00791   }

ReportManager org.objectweb.cjdbc.controller.core.Controller.getReport  ) 
 

Returns the report value.

Returns:
Returns the report.

Definition at line 1105 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.generateReportIfNeeded().

01106   {
01107     return report;
01108   }

ControllerSecurityManager org.objectweb.cjdbc.controller.core.Controller.getSecurity  ) 
 

Returns:
Returns the security.

Definition at line 889 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread(), and org.objectweb.cjdbc.controller.core.Controller.getXmlController().

00890   {
00891     return security;
00892   }

String org.objectweb.cjdbc.controller.core.Controller.getVersion  )  [static]
 

Returns Version as a long String

Returns:
version

Definition at line 861 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.Controller.main().

00862   {
00863     return Translate.get("controller.info", Constants.VERSION);
00864   }

String org.objectweb.cjdbc.controller.core.Controller.getVersionNumber  ) 
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.getVersionNumber()

Definition at line 924 of file Controller.java.

00925   {
00926     return Constants.VERSION;
00927   }

VirtualDatabase org.objectweb.cjdbc.controller.core.Controller.getVirtualDatabase 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

Definition at line 302 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerWorkerThread.run().

00303   {
00304     return (VirtualDatabase) virtualDatabases.get(virtualDatabaseName);
00305   }

ArrayList org.objectweb.cjdbc.controller.core.Controller.getVirtualDatabaseNames  ) 
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.getVirtualDatabaseNames()

Definition at line 310 of file Controller.java.

00311   {
00312     ArrayList result = new ArrayList();
00313     for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();)
00314       result.add(((VirtualDatabase) iter.next()).getVirtualDatabaseName());
00315     return result;
00316   }

ArrayList org.objectweb.cjdbc.controller.core.Controller.getVirtualDatabases  ) 
 

Returns information about the available virtual databases.

Returns:
ArrayList of information about virtual databases.

Definition at line 323 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.shutdown.ControllerShutdownThread.shutdownDatabases().

00324   {
00325     ArrayList result = new ArrayList();
00326     for (Iterator iter = virtualDatabases.values().iterator(); iter.hasNext();)
00327       result.add(iter.next());
00328     return result;
00329   }

String org.objectweb.cjdbc.controller.core.Controller.getXml  ) 
 

See also:
org.objectweb.cjdbc.common.xml.XmlComponent.getXml()

Definition at line 940 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.getXmlController(), and org.objectweb.cjdbc.controller.core.Controller.logger.

Referenced by org.objectweb.cjdbc.controller.core.Controller.getXmlController(), and org.objectweb.cjdbc.controller.core.ReportManager.writeControllerInfo().

00941   {
00942     try
00943     {
00944       return XmlTools.prettyXml(getXmlController());
00945     }
00946     catch (Exception e)
00947     {
00948       logger.error(Translate.get("controller.xml.transformation.failed", e));
00949       return e.getMessage();
00950     }
00951   }

String org.objectweb.cjdbc.controller.core.Controller.getXmlController  ) 
 

Return the xml version of the controller.xml file without doc type declaration, just data.

Returns:
controller xml data

Definition at line 959 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.getJmxEnable(), org.objectweb.cjdbc.controller.core.ReportManager.getReportLocation(), org.objectweb.cjdbc.controller.core.Controller.getSecurity(), org.objectweb.cjdbc.controller.core.Controller.getXml(), org.objectweb.cjdbc.controller.core.ReportManager.isEnableFileLogging(), org.objectweb.cjdbc.controller.core.ReportManager.isGenerateOnFatal(), org.objectweb.cjdbc.controller.core.ReportManager.isGenerateOnShutdown(), org.objectweb.cjdbc.controller.core.ReportManager.isHideSensitiveData(), and org.objectweb.cjdbc.controller.core.ReportManager.isReportEnabled().

Referenced by org.objectweb.cjdbc.controller.core.Controller.getXml().

00960   {
00961     StringBuffer info = new StringBuffer();
00962     info.append("<C-JDBC-CONTROLLER>");
00963     info.append("<" + ControllerXmlTags.ELT_CONTROLLER + " "
00964         + ControllerXmlTags.ATT_CONTROLLER_IP + "=\"" + this.getIPAddress()
00965         + "\" " + ControllerXmlTags.ATT_CONTROLLER_PORT + "=\""
00966         + this.getPortNumber() + "\" " + ">");
00967 
00968     info.append("<" + ControllerXmlTags.ELT_INTERNATIONALIZATION + " "
00969         + ControllerXmlTags.ATT_LANGUAGE + "=\""
00970         + Locale.getDefault().getLanguage() + "\"/>");
00971 
00972     if (report.isReportEnabled())
00973     {
00974       info.append("<" + ControllerXmlTags.ELT_REPORT + " "
00975           + ControllerXmlTags.ATT_REPORT_ENABLE_FILE_LOGGING + "=\""
00976           + report.isEnableFileLogging() + "\" "
00977           + ControllerXmlTags.ATT_REPORT_HIDE_SENSITIVE_DATA + "=\""
00978           + report.isHideSensitiveData() + "\" "
00979           + ControllerXmlTags.ATT_REPORT_GENERATE_ON_FATAL + "=\""
00980           + report.isGenerateOnFatal() + "\" "
00981           + ControllerXmlTags.ATT_REPORT_GENERATE_ON_SHUTDOWN + "=\""
00982           + report.isGenerateOnShutdown() + "\" "
00983           + ControllerXmlTags.ATT_REPORT_REPORT_LOCATION + "=\""
00984           + report.getReportLocation() + "\" />");
00985     }
00986 
00987     if (getJmxEnable())
00988     {
00989       info.append("<" + ControllerXmlTags.ELT_JMX + ">");
00990       if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_HTTP))
00991       {
00992         info.append("<" + ControllerXmlTags.ELT_HTTP_JMX_ADAPTOR + " "
00993             + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\""
00994             + configuration.get(JmxConstants.ADAPTOR_TYPE_HTTP) + "\" />");
00995       }
00996       if (configuration.containsKey(JmxConstants.ADAPTOR_TYPE_RMI))
00997       {
00998         info.append("<" + ControllerXmlTags.ELT_RMI_JMX_ADAPTOR + " "
00999             + ControllerXmlTags.ATT_JMX_ADAPTOR_PORT + "=\""
01000             + configuration.get(JmxConstants.ADAPTOR_TYPE_RMI) + "\" />");
01001       }
01002 
01003       info.append("</" + ControllerXmlTags.ELT_JMX + ">");
01004     }
01005 
01006     if (this.isSecurityEnabled())
01007       info.append(this.getSecurity().getXml());
01008     info.append("</" + ControllerXmlTags.ELT_CONTROLLER + ">");
01009     info.append("</C-JDBC-CONTROLLER>");
01010     return info.toString();
01011   }

String org.objectweb.cjdbc.controller.core.Controller.getXmlVirtualDatabases  ) 
 

Same as above but for the virtual databases.

Returns:
xml virtual databases data.

Definition at line 1018 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.logger.

Referenced by org.objectweb.cjdbc.controller.core.Controller.saveConfiguration(), and org.objectweb.cjdbc.controller.core.ReportManager.writeControllerInfo().

01019   {
01020     try
01021     {
01022       StringBuffer info = new StringBuffer();
01023       info.append("<C-JDBC>");
01024       ArrayList virtualDatabases = this.getVirtualDatabases();
01025       for (int i = 0, size = virtualDatabases.size(); i < size; i++)
01026         info.append(((VirtualDatabase) virtualDatabases.get(i)).getXml());
01027       info.append("</C-JDBC>");
01028       return info.toString();
01029     }
01030     catch (Exception e)
01031     {
01032       logger.error(e.getMessage(), e);
01033       return e.getMessage();
01034     }
01035   }

boolean org.objectweb.cjdbc.controller.core.Controller.hasVirtualDatabase 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

Definition at line 338 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabase(), and org.objectweb.cjdbc.controller.core.Controller.removeVirtualDatabase().

00339   {
00340     return virtualDatabases.containsKey(name);
00341   }

boolean org.objectweb.cjdbc.controller.core.Controller.isSecurityEnabled  ) 
 

Check whether security is enabled or not

Returns:
true if there is not null controller security manager

Definition at line 881 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.ControllerServerThread.ControllerServerThread(), and org.objectweb.cjdbc.controller.core.Controller.shutdown().

00882   {
00883     return security != null;
00884   }

boolean org.objectweb.cjdbc.controller.core.Controller.isShuttingDown  ) 
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.isShuttingDown()

Definition at line 623 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.Controller.shutdown().

00624   {
00625     return isShuttingDown;
00626   }

void org.objectweb.cjdbc.controller.core.Controller.launch  ) 
 

Actively launch the controller. Add startup actions here to avoid them in <method>main </method>

Definition at line 736 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.getControllerName(), and org.objectweb.cjdbc.controller.core.Controller.logger.

Referenced by org.objectweb.cjdbc.controller.core.Controller.main().

00737   {
00738     connectionThread = new ControllerServerThread(this);
00739     connectionThread.start();
00740 
00741     SimpleDateFormat formatter = new SimpleDateFormat(
00742         "yyyy.MM.dd ww 'at' hh:mm:ss a zzz");
00743     Date day = new Date();
00744     String date = formatter.format(day);
00745     logger.info(Translate.get("controller.date", date));
00746     logger.info(Translate.get("controller.ready", getControllerName()));
00747   }

String org.objectweb.cjdbc.controller.core.Controller.loadXml String  filename  )  throws Exception
 

Read a XML configuration file for a set of virtual databases

Parameters:
filename XML configuration file name
Returns:
a diagnostic message (success or error)
Exceptions:
Exception if an error occurs

Definition at line 551 of file Controller.java.

00552   {
00553     return this.loadXmlConfiguration(filename, null,
00554         ControllerConstants.AUTO_ENABLE_BACKEND,
00555         ControllerConstants.DATABASE_DEFAULT_CHECKPOINT);
00556   }

String org.objectweb.cjdbc.controller.core.Controller.loadXmlConfiguration String  filename,
String  virtualName,
int  autoLoad,
String  checkPoint
throws 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)
Exceptions:
Exception if an error occurs

Definition at line 499 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabases(), and org.objectweb.cjdbc.controller.core.Controller.logger.

00501   {
00502     FileReader fileReader = null;
00503     try
00504     {
00505       filename = filename.trim();
00506       try
00507       {
00508         fileReader = new FileReader(filename);
00509       }
00510       catch (FileNotFoundException fnf)
00511       {
00512         return Translate.get("controller.file.not.found", filename);
00513       }
00514 
00515       // Read the file
00516       BufferedReader in = new BufferedReader(fileReader);
00517       StringBuffer xml = new StringBuffer();
00518       String line;
00519       do
00520       {
00521         line = in.readLine();
00522         if (line != null)
00523           xml.append(line);
00524       }
00525       while (line != null);
00526 
00527       // Send it to the controller
00528       addVirtualDatabases(xml.toString(), virtualName, autoLoad, checkPoint);
00529       return Translate.get("controller.file.send", filename);
00530     }
00531     catch (Exception e)
00532     {
00533       logger.error(Translate.get("controller.loadXml.failed", e), e);
00534       throw new ControllerException(Translate.get("controller.loadXml.failed",
00535           e));
00536     }
00537     finally
00538     {
00539       if (fileReader != null)
00540         fileReader.close();
00541     }
00542   }

void org.objectweb.cjdbc.controller.core.Controller.main String  args[]  )  throws Exception [static]
 

Launches the C-JDBC controller and bind it with RMI registry. The available options are:

  • -h or --help <port>: displays usage informations.
  • -j or --jmx <port>: optinal JMX server HTTP adaptor port number.
  • -n or --name <name>: optional controller name.
  • -i or --ip <ip>: optional IP address to beind the controller to.
  • -r or --rmi <port>: optional RMI registry port number.
  • -v or --version: displays version informations.

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

org.objectweb.cjdbc.controller.core.ControllerConstants#DEFAULT_PORT Default Listening port

Parameters:
args command line arguments (see above)
Exceptions:
Exception when everything goes wrong

Definition at line 717 of file Controller.java.

References org.objectweb.cjdbc.controller.core.ControllerFactory.getController(), org.objectweb.cjdbc.controller.core.Controller.getVersion(), org.objectweb.cjdbc.controller.core.Controller.launch(), and org.objectweb.cjdbc.controller.core.Controller.logger.

00718   {
00719     logger.info(getVersion());
00720 
00721     System.setProperty("javax.management.builder.initial",
00722         org.objectweb.cjdbc.controller.jmx.MBeanServerBuilder.class.getName());
00723 
00724     ControllerFactory conf = new ControllerFactory(args);
00725     Controller controller = conf.getController();
00726     if (controller != null)
00727       controller.launch();
00728     else
00729       throw new Exception(Translate.get("controller.configure.failed"));
00730   }

void org.objectweb.cjdbc.controller.core.Controller.refreshLogConfiguration  )  throws ControllerException
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.refreshLogConfiguration()

Definition at line 1053 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.logger.

Referenced by org.objectweb.cjdbc.controller.core.Controller.updateLogConfigurationFile().

01054   {
01055     try
01056     {
01057       LogManager.configure(URLDecoder.decode(this.getClass().getResource(
01058           ControllerConstants.LOG4J_RESOURCE).getFile()));
01059       if (logger.isDebugEnabled())
01060         logger.info(Translate.get("controller.refresh.log.success"));
01061     }
01062     catch (Exception e)
01063     {
01064       throw new ControllerException(Translate
01065           .get("controller.logconfigfile.not.found"));
01066     }
01067   }

String org.objectweb.cjdbc.controller.core.Controller.removeVirtualDatabase String  virtualname  )  throws ControllerException
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.removeVirtualDatabase(String)

Definition at line 346 of file Controller.java.

References org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.disableAllBackends(), org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.getAllBackendNames(), org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.getVirtualDatabaseName(), and org.objectweb.cjdbc.controller.core.Controller.hasVirtualDatabase().

00348   {
00349     if (hasVirtualDatabase(virtualname))
00350     {
00351       VirtualDatabase vdb = (VirtualDatabase) virtualDatabases.get(virtualname);
00352       try
00353       {
00354         vdb.disableAllBackends();
00355       }
00356       catch (VirtualDatabaseException e)
00357       {
00358         throw new ControllerException(e);
00359       }
00360       this.virtualDatabases.remove(virtualname);
00361 
00362       // Send notification
00363       if (MBeanServerManager.isJmxEnabled())
00364       {
00365         Hashtable databases = new Hashtable();
00366         try
00367         {
00368           databases.put("backends", vdb.getAllBackendNames());
00369         }
00370         catch (VirtualDatabaseException e)
00371         {
00372           // ignore
00373         }
00374         RmiConnector.broadcastNotification(this,
00375             CjdbcNotificationList.CONTROLLER_VIRTUALDATABASE_REMOVED,
00376             CjdbcNotificationList.NOTIFICATION_LEVEL_INFO, Translate.get(
00377                 "notification.virtualdatabase.removed", vdb
00378                     .getVirtualDatabaseName()), databases);
00379       }
00380     }
00381     return Translate.get("controller.removeVirtualDatabase.success",
00382         virtualname);
00383   }

String org.objectweb.cjdbc.controller.core.Controller.saveConfiguration  )  throws VirtualDatabaseException
 

Save current configuration of the controller to a default file

Returns:
Status message
Exceptions:
VirtualDatabaseException if an error occurs
See also:
org.objectweb.cjdbc.controller.core.ControllerConstants.getSaveFile

Definition at line 565 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.getXmlVirtualDatabases(), and org.objectweb.cjdbc.controller.core.Controller.logger.

00566   {
00567     String msg = Translate.get("controller.save.configuration");
00568     try
00569     {
00570       String configurationFile = ControllerConstants
00571           .getSaveFile(new SimpleDateFormat("EEE, MMM d, yy")
00572               .format(new Date()));
00573       DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(
00574           new FileOutputStream(configurationFile)));
00575       StringBuffer xml = new StringBuffer();
00576       xml.append(XmlTools.prettyXml(getXmlVirtualDatabases().toString()));
00577       dos.write(xml.toString().getBytes());
00578       dos.close();
00579     }
00580     catch (Exception e)
00581     {
00582       msg = Translate.get("controller.save.configuration.failed", e);
00583       logger.error(msg);
00584     }
00585     return msg;
00586   }

void org.objectweb.cjdbc.controller.core.Controller.setBacklogSize int  size  ) 
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.setBacklogSize(int)

Definition at line 814 of file Controller.java.

00815   {
00816     backlogSize = size;
00817   }

void org.objectweb.cjdbc.controller.core.Controller.setConfiguration Hashtable  configuration  ) 
 

Sets the configuration value.

Parameters:
configuration The configuration to set.

Definition at line 916 of file Controller.java.

00917   {
00918     this.configuration = configuration;
00919   }

void org.objectweb.cjdbc.controller.core.Controller.setIPAddress String  ipAddress  ) 
 

Set the IP address to bind the controller to

Parameters:
ipAddress the IP address to use

Definition at line 778 of file Controller.java.

00779   {
00780     this.ipAddress = ipAddress;
00781   }

void org.objectweb.cjdbc.controller.core.Controller.setJmxEnable boolean  enable  ) 
 

set enable JMX

Parameters:
enable true if jmx should be enable.

Definition at line 851 of file Controller.java.

00852   {
00853     configuration.put(ControllerFactory.JMX_ENABLE, "" + enable);
00854   }

void org.objectweb.cjdbc.controller.core.Controller.setPortNumber int  port  ) 
 

Set the controller backlog size.

Parameters:
port the port number to set

Definition at line 798 of file Controller.java.

00799   {
00800     portNumber = port;
00801   }

void org.objectweb.cjdbc.controller.core.Controller.setReport ReportManager  report  ) 
 

Sets the report value.

Parameters:
report The report to set.

Definition at line 1115 of file Controller.java.

01116   {
01117     this.report = report;
01118   }

void org.objectweb.cjdbc.controller.core.Controller.setSecurity ControllerSecurityManager  security  ) 
 

Parameters:
security The security to set.

Definition at line 897 of file Controller.java.

00898   {
00899     this.security = security;
00900   }

void org.objectweb.cjdbc.controller.core.Controller.shutdown int  level  )  throws ControllerException
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.shutdown(int)

Definition at line 631 of file Controller.java.

References org.objectweb.cjdbc.controller.core.shutdown.ShutdownThread.getShutdownGroup(), org.objectweb.cjdbc.controller.core.Controller.isSecurityEnabled(), org.objectweb.cjdbc.controller.core.Controller.isShuttingDown(), and org.objectweb.cjdbc.controller.core.Controller.logger.

00632   {
00633     ControllerShutdownThread shutdownThread = null;
00634     synchronized (this)
00635     {
00636       if (isShuttingDown())
00637       {
00638         logger.info(Translate.get("controller.already.shutting.down", this
00639             .getControllerName()));
00640         return;
00641       }
00642 
00643       if (isSecurityEnabled() && !security.getAllowConsoleShutdown())
00644         throw new ControllerException(Translate
00645             .get("controller.shutdown.refused"));
00646 
00647       switch (level)
00648       {
00649         case Constants.SHUTDOWN_WAIT :
00650           shutdownThread = new ControllerWaitShutdownThread(this);
00651           logger.info(Translate.get("controller.shutdown.type.wait", this
00652               .getControllerName()));
00653           break;
00654         case Constants.SHUTDOWN_SAFE :
00655           isShuttingDown = true;
00656           shutdownThread = new ControllerSafeShutdownThread(this);
00657           logger.info(Translate.get("controller.shutdown.type.safe", this
00658               .getControllerName()));
00659           break;
00660         case Constants.SHUTDOWN_FORCE :
00661           isShuttingDown = true;
00662           shutdownThread = new ControllerForceShutdownThread(this);
00663           logger.warn(Translate.get("controller.shutdown.type.force", this
00664               .getControllerName()));
00665           break;
00666         default :
00667           String msg = Translate
00668               .get("controller.shutdown.unknown.level", level);
00669           logger.error(msg);
00670           throw new RuntimeException(msg);
00671       }
00672     }
00673 
00674     Thread thread = new Thread(shutdownThread.getShutdownGroup(),
00675         shutdownThread, "Controller Shutdown Thread");
00676     thread.start();
00677 
00678     try
00679     {
00680       logger.info("Waiting for shutdown");
00681       thread.join();
00682       logger.info("Shutdown over");
00683     }
00684     catch (InterruptedException e)
00685     {
00686       e.printStackTrace();
00687     }
00688   }

void org.objectweb.cjdbc.controller.core.Controller.updateLogConfigurationFile String  newConfiguration  )  throws IOException, ControllerException
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.updateLogConfigurationFile(java.lang.String)

Definition at line 1072 of file Controller.java.

References org.objectweb.cjdbc.controller.core.Controller.refreshLogConfiguration(), and org.objectweb.cjdbc.controller.core.ReportManager.write().

01074   {
01075     File logFile = new File(URLDecoder.decode(getClass().getResource(
01076         ControllerConstants.LOG4J_RESOURCE).getFile()));
01077     BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
01078     writer.write(newConfiguration);
01079     writer.flush();
01080     writer.close();
01081     refreshLogConfiguration();
01082   }

String org.objectweb.cjdbc.controller.core.Controller.viewLogConfigurationFile  )  throws IOException
 

See also:
org.objectweb.cjdbc.common.jmx.mbeans.ControllerMBean.viewLogConfigurationFile()

Definition at line 1087 of file Controller.java.

01088   {
01089     File logFile = new File(URLDecoder.decode(getClass().getResource(
01090         ControllerConstants.LOG4J_RESOURCE).getFile()));
01091     BufferedReader reader = new BufferedReader(new FileReader(logFile));
01092     StringBuffer buffer = new StringBuffer();
01093     String line;
01094     while ((line = reader.readLine()) != null)
01095       buffer.append(line + System.getProperty("line.separator"));
01096     reader.close();
01097     return buffer.toString();
01098   }


Member Data Documentation

Trace org.objectweb.cjdbc.controller.core.Controller.logger [static, package]
 

Initial value:

 Trace
                                               .getLogger("org.objectweb.cjdbc.controller.core.Controller")
Logger instance.

Definition at line 108 of file Controller.java.

Referenced by org.objectweb.cjdbc.controller.core.Controller.addDriver(), org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabase(), org.objectweb.cjdbc.controller.core.Controller.addVirtualDatabases(), org.objectweb.cjdbc.controller.core.Controller.endOfController(), org.objectweb.cjdbc.controller.core.Controller.getXml(), org.objectweb.cjdbc.controller.core.Controller.getXmlVirtualDatabases(), org.objectweb.cjdbc.controller.core.Controller.launch(), org.objectweb.cjdbc.controller.core.Controller.loadXmlConfiguration(), org.objectweb.cjdbc.controller.core.Controller.main(), org.objectweb.cjdbc.controller.core.Controller.refreshLogConfiguration(), org.objectweb.cjdbc.controller.core.Controller.saveConfiguration(), and org.objectweb.cjdbc.controller.core.Controller.shutdown().


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