vgritsenko 02/01/15 09:05:20
Modified: src/java/org/apache/cocoon/components/hsqldb ServerImpl.java
Log:
Reformat code, add TODO for HSQLDB shutdown
Revision Changes Path
1.3 +104 -63
xml-cocoon2/src/java/org/apache/cocoon/components/hsqldb/ServerImpl.java
Index: ServerImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/hsqldb/ServerImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServerImpl.java 10 Jan 2002 15:27:37 -0000 1.2
+++ ServerImpl.java 15 Jan 2002 17:05:20 -0000 1.3
@@ -20,11 +20,17 @@
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.sql.SQLException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Enumeration;
/**
* This class runs an instance of HSQLDB Server.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
*/
public class ServerImpl
extends AbstractLoggable
@@ -35,73 +41,108 @@
Runnable,
Startable {
- /** Arguments for running the server */
- private String arguments[] = new String[8];
+ /** Port which HSQLDB server will listen to */
+ private String port;
- /** Check if the server has already been started */
- private boolean started = false;
+ /** Arguments for running the server */
+ private String arguments[] = new String[8];
- /**
- * Initialize the ServerImpl.
- * A few options can be used :
- * <UL>
- * <LI>port = port where the server is listening</LI>
- * <LI>silent = display all queries</LI>
- * <LI>trace = print JDBC trace messages</LI>
- * </UL>
- */
- public void parameterize(Parameters params) {
- arguments[0] = "-port";
- arguments[1] = params.getParameter("port","9002");
- arguments[2] = "-silent";
- arguments[3] = params.getParameter("silent","true");
- arguments[4] = "-trace";
- arguments[5] = params.getParameter("trace","false");
- if ( this.getLogger().isDebugEnabled() == true ) {
- this.getLogger().debug("Configure ServerImpl with port: " +
arguments[1]
- +", silent: " + arguments[3]
- +", trace: " +arguments[5]);
+ /** Check if the server has already been started */
+ private boolean started = false;
+
+ /**
+ * Initialize the ServerImpl.
+ * A few options can be used :
+ * <UL>
+ * <LI>port = port where the server is listening</LI>
+ * <LI>silent = display all queries</LI>
+ * <LI>trace = print JDBC trace messages</LI>
+ * </UL>
+ */
+ public void parameterize(Parameters params) {
+ this.getLogger().debug("Parameterize ServerImpl");
+
+ arguments[0] = "-port";
+ arguments[1] = this.port = params.getParameter("port", "9002");
+ arguments[2] = "-silent";
+ arguments[3] = params.getParameter("silent","true");
+ arguments[4] = "-trace";
+ arguments[5] = params.getParameter("trace","false");
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("Configure ServerImpl with port: " +
arguments[1]
+ + ", silent: " + arguments[3]
+ + ", trace: " +arguments[5]);
+ }
+ }
+
+ /** Contextualize this class */
+ public void contextualize(Context context) throws ContextException {
+ org.apache.cocoon.environment.Context ctx =
+ (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ try {
+ arguments[6] = "-database";
+ arguments[7] = new
File(ctx.getRealPath("/WEB-INF/db")).getCanonicalPath();
+ arguments[7] += File.separator + "cocoondb";
+ getLogger().debug("database is " + arguments[7]);
+ } catch (MalformedURLException e) {
+ getLogger().error("MalformedURLException - Could not get
database directory ", e);
+ } catch (IOException e) {
+ getLogger().error("IOException - Could not get database
directory ", e);
+ }
}
- }
- /** Contextualize this class */
- public void contextualize(Context context) throws ContextException {
- org.apache.cocoon.environment.Context ctx =
- (org.apache.cocoon.environment.Context)
context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
- try {
- arguments[6] = "-database";
- arguments[7] = new
File(ctx.getRealPath("/WEB-INF/db")).getCanonicalPath();
- arguments[7] += File.separator + "cocoondb";
- getLogger().debug("database is " + arguments[7]);
- } catch (MalformedURLException e) {
- getLogger().error("MalformedURLException - Could not get database
directory ", e);
- } catch (IOException e) {
- getLogger().error("IOException - Could not get database directory ",
e);
+ /** Start the server */
+ public void start() {
+ Thread server = new Thread(this);
+ this.getLogger().debug("Intializing hsqldb server thread");
+ server.setPriority(Thread.currentThread().getPriority());
+ server.setDaemon(true);
+ server.setName("hsqldb server");
+ server.start();
}
- }
- /** Start the server */
- public void start() {
- Thread server = new Thread(this);
- this.getLogger().debug("Intializing hsqldb server thread");
- server.setPriority(Thread.currentThread().getPriority());
- server.setDaemon(true);
- server.setName("hsqldb server");
- server.start();
- }
-
- /** Stop the server */
- public void stop() {
- }
-
- public void run() {
- if(!started) {
- started = true;
- getLogger().debug("HSQLDB Server arguments are as follows:");
- for(int i=0;i<8;i++) {
- getLogger().debug(i + " : " + arguments[i]);
- }
- org.hsqldb.Server.main(arguments);
- }
- }
+ /** Stop the server */
+ public void stop() {
+ if (started) {
+ // TODO: Execute shutdown. Now HSQLDB have a System.exit() call
+/*
+ try {
+ System.out.println("Shutting down HSQLDB");
+ getLogger().debug("Shutting down HSQLDB");
+ Connection connection =
DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:" + this.port, "sa",
"");
+ Statement statement = connection.createStatement();
+ statement.executeQuery("SHUTDOWN");
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ System.out.println("Shutting down HSQLDB: Ignoring
exception: " + e);
+ }
+ } catch (Exception e){
+ System.out.println("Shutting down HSQLDB: Exception.");
+ e.printStackTrace();
+ }
+ System.out.println("Shutting down HSQLDB: Done");
+*/
+ }
+ }
+
+ public void run() {
+ if(!started) {
+ started = true;
+
+ try {
+ getLogger().debug("HSQLDB Server arguments are as follows:");
+ for(int i=0;i<8;i++) {
+ getLogger().debug(i + " : " + arguments[i]);
+ }
+
+ org.hsqldb.Server.main(arguments);
+ } catch(Exception e){
+ System.out.println("run got exception: ");
+ e.printStackTrace();
+ } finally {
+ started = false;
+ }
+ }
+ }
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]