Author: vgritsenko
Date: Wed Mar 9 09:17:52 2005
New Revision: 156660
URL: http://svn.apache.org/viewcvs?view=rev&rev=156660
Log:
cleanups
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
URL:
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java?view=diff&r1=156659&r2=156660
==============================================================================
---
cocoon/branches/BRANCH_2_1_X/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
(original)
+++
cocoon/branches/BRANCH_2_1_X/src/blocks/hsqldb/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Wed Mar 9 09:17:52 2005
@@ -27,6 +27,7 @@
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameterizable;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
@@ -43,24 +44,19 @@
* @version CVS $Id$
*/
public class ServerImpl extends AbstractLogEnabled
- implements Server,
- Parameterizable,
- Contextualizable,
- ThreadSafe,
- Runnable,
- Serviceable,
- Startable {
+ implements Server, Parameterizable, Contextualizable,
+ ThreadSafe, Runnable, Serviceable,
Startable {
private static final boolean DEFAULT_TRACE = false;
private static final boolean DEFAULT_SILENT = true;
private static final int DEFAULT_PORT = 9002;
- private static final String CONTEXT_PROTOCOL = "context:/";
+ private static final String CONTEXT_PROTOCOL = "context:/";
private static final String DEFAULT_DB_NAME = "cocoondb";
private static final String DEFAULT_DB_PATH = "context://WEB-INF/db";
/** Cocoon context **/
private org.apache.cocoon.environment.Context cocoonContext;
-
+
/** The HSQLDB HSQL protocol network database server instance **/
private org.hsqldb.Server hsqlServer = new org.hsqldb.Server();
@@ -69,7 +65,12 @@
/** The [EMAIL PROTECTED] ServiceManager} instance */
private ServiceManager m_serviceManager;
-
+
+ /** Contextualize this class */
+ public void contextualize(Context context) throws ContextException {
+ cocoonContext = (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ }
+
/**
* Initialize the ServerImpl.
* Posible options:
@@ -81,47 +82,43 @@
* <li>path = path to the database - context-protocol is resolved</li>
* </ul>
*/
- public void parameterize(Parameters params) {
- this.getLogger().debug("Parameterize ServerImpl");
+ public void parameterize(Parameters params) throws ParameterException {
hsqlServer.setLogWriter(null); /* Remove console log */
hsqlServer.setErrWriter(null); /* Remove console log */
hsqlServer.setPort(params.getParameterAsInteger("port", DEFAULT_PORT));
hsqlServer.setSilent(params.getParameterAsBoolean("silent",
DEFAULT_SILENT));
hsqlServer.setTrace(params.getParameterAsBoolean("trace",
DEFAULT_TRACE));
hsqlServer.setNoSystemExit(true);
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("Configure ServerImpl with port: " +
hsqlServer.getPort()
- + ", silent: " + hsqlServer.isSilent()
- + ", trace: " + hsqlServer.isTrace());
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Configure HSQLDB with port: " +
hsqlServer.getPort() +
+ ", silent: " + hsqlServer.isSilent() +
+ ", trace: " + hsqlServer.isTrace());
}
+
m_daemonThreadPoolName = params.getParameter("thread-pool-name",
m_daemonThreadPoolName);
String dbPath = params.getParameter("path", DEFAULT_DB_PATH);
-
- // test if we are running inside a WAR file
+ // Test if we are running inside a WAR file
if(dbPath.startsWith(ServerImpl.CONTEXT_PROTOCOL)) {
dbPath =
this.cocoonContext.getRealPath(dbPath.substring(ServerImpl.CONTEXT_PROTOCOL.length()));
- }
+ }
if (dbPath == null) {
- throw new RuntimeException("The hsqldb cannot be used inside a WAR
file.");
- }
+ throw new ParameterException("The hsqldb cannot be used inside a
WAR file. " +
+ "Real path for <" + dbPath + "> is
null.");
+ }
+ String dbName = params.getParameter("name", DEFAULT_DB_NAME);
try {
- hsqlServer.setDatabasePath(0, new File(dbPath).getCanonicalPath()
+ File.separator + params.getParameter("name", DEFAULT_DB_NAME));
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("database path is " +
hsqlServer.getDatabasePath(0,true));
- }
- } catch (MalformedURLException e) {
- getLogger().error("MalformedURLException - Could not get database
directory ", e);
+ hsqlServer.setDatabasePath(0, new File(dbPath).getCanonicalPath()
+ File.separator + dbName);
} catch (IOException e) {
- getLogger().error("IOException - Could not get database directory
", e);
- }
- }
+ throw new ParameterException("Could not get database directory <"
+ dbPath + ">", e);
+ }
- /** Contextualize this class */
- public void contextualize(Context context) throws ContextException {
- cocoonContext = (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Database path is <" +
hsqlServer.getDatabasePath(0, true) + ">");
+ }
}
+
/**
* @param serviceManager The <@link ServiceManager} instance
* @throws ServiceException In case we cannot find a service needed
@@ -134,11 +131,10 @@
public void start() {
RunnableManager runnableManager = null;
try {
- this.getLogger().debug("Intializing hsqldb server thread");
- runnableManager =
(RunnableManager)m_serviceManager.lookup(RunnableManager.ROLE);
+ runnableManager = (RunnableManager)
m_serviceManager.lookup(RunnableManager.ROLE);
runnableManager.execute(m_daemonThreadPoolName, this);
- } catch(final ServiceException se) {
- throw new CascadingRuntimeException("Cannot get RunnableManager",
se);
+ } catch(final ServiceException e) {
+ throw new CascadingRuntimeException("Cannot get RunnableManager",
e);
} finally {
if (null != runnableManager) {
m_serviceManager.release(runnableManager);
@@ -156,13 +152,8 @@
/** Run the server */
public void run() {
if (getLogger().isDebugEnabled()) {
- this.getLogger().debug("Starting HSQLDB");
- getLogger().debug(hsqlServer.getProductName() + " " +
hsqlServer.getProductVersion() + " arguments are:");
- getLogger().debug("port: " + hsqlServer.getPort());
- getLogger().debug("silent: " + hsqlServer.isSilent());
- getLogger().debug("DB path: " +
hsqlServer.getDatabasePath(0,true));
+ getLogger().debug("Starting " + hsqlServer.getProductName() + " "
+ hsqlServer.getProductVersion() + " with parameters:");
}
this.hsqlServer.start();
- this.getLogger().debug("Starting HSQLDB: Done");
}
}