You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2010/06/10 16:22:50 UTC
svn commit: r953331 - in /incubator/lcf/trunk/modules/framework:
agents/org/apache/lcf/agents/ agents/org/apache/lcf/agents/system/
authority-service/org/apache/lcf/authorityservice/servlet/
core/org/apache/lcf/core/ core/org/apache/lcf/core/database/ ...
Author: kwright
Date: Thu Jun 10 14:22:50 2010
New Revision: 953331
URL: http://svn.apache.org/viewvc?rev=953331&view=rev
Log:
Revamp a pile of stuff having to do with how database connections are set up and torn down. Specifically, work hard to make sure Derby gets properly notified - exactly once - of a database shutdown situation.
Modified:
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java
incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/system/LCF.java
incubator/lcf/trunk/modules/framework/authority-service/org/apache/lcf/authorityservice/servlet/UserACLServlet.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/CheckAll.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/system/LCF.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java
incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/system/LCF.java
incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/agents/tests/TestBase.java
incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/core/tests/TestBase.java
incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestBase.java
incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentRun.java Thu Jun 10 14:22:50 2010
@@ -43,11 +43,11 @@ public class AgentRun
System.exit(1);
}
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
-
try
{
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
+
ILockManager lockManager = LockManagerFactory.make(tc);
// Clear the agents shutdown signal.
lockManager.clearGlobalFlag(agentShutdownSignal);
@@ -75,7 +75,7 @@ public class AgentRun
catch (LCFException e)
{
Logging.root.error("Exception: "+e.getMessage(),e);
- e.printStackTrace();
+ e.printStackTrace(System.err);
System.exit(1);
}
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/AgentStop.java Thu Jun 10 14:22:50 2010
@@ -41,16 +41,17 @@ public class AgentStop
System.exit(1);
}
- LCF.initializeEnvironment();
- IThreadContext tc = ThreadContextFactory.make();
try
{
+ LCF.initializeEnvironment();
+ IThreadContext tc = ThreadContextFactory.make();
ILockManager lockManager = LockManagerFactory.make(tc);
lockManager.setGlobalFlag(AgentRun.agentShutdownSignal);
+ System.err.println("Shutdown signal sent");
}
catch (LCFException e)
{
- e.printStackTrace();
+ e.printStackTrace(System.err);
System.exit(1);
}
}
Modified: incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/system/LCF.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/agents/org/apache/lcf/agents/system/LCF.java Thu Jun 10 14:22:50 2010
@@ -27,9 +27,9 @@ public class LCF extends org.apache.lcf.
{
public static final String _rcsid = "@(#)$Id$";
- protected static boolean initialized = false;
-
-
+ // Agents initialized flag
+ protected static boolean agentsInitialized = false;
+
/** This is the place we keep track of the agents we've started. */
protected static HashMap runningHash = new HashMap();
/** This flag prevents startAgents() from starting anything once stopAgents() has been called. */
@@ -37,20 +37,25 @@ public class LCF extends org.apache.lcf.
/** Initialize environment.
*/
- public static synchronized void initializeEnvironment()
+ public static void initializeEnvironment()
+ throws LCFException
{
- if (initialized)
- return;
+ synchronized (initializeFlagLock)
+ {
+ if (agentsInitialized)
+ return;
- // Do core initialization
- org.apache.lcf.core.system.LCF.initializeEnvironment();
-
- // Create the shutdown hook for agents. All activity will be keyed off of runningHash, so it is safe to do this under all conditions.
- org.apache.lcf.core.system.LCF.addShutdownHook(new AgentsShutdownHook());
-
- Logging.initializeLoggers();
- Logging.setLogLevels();
- initialized = true;
+ // Do core initialization
+ org.apache.lcf.core.system.LCF.initializeEnvironment();
+
+ // Create the shutdown hook for agents. All activity will be keyed off of runningHash, so it is safe to do this under all conditions.
+ org.apache.lcf.core.system.LCF.addShutdownHook(new AgentsShutdownHook());
+
+ // Initialize the local loggers
+ Logging.initializeLoggers();
+ Logging.setLogLevels();
+ agentsInitialized = true;
+ }
}
Modified: incubator/lcf/trunk/modules/framework/authority-service/org/apache/lcf/authorityservice/servlet/UserACLServlet.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/authority-service/org/apache/lcf/authorityservice/servlet/UserACLServlet.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/authority-service/org/apache/lcf/authorityservice/servlet/UserACLServlet.java (original)
+++ incubator/lcf/trunk/modules/framework/authority-service/org/apache/lcf/authorityservice/servlet/UserACLServlet.java Thu Jun 10 14:22:50 2010
@@ -98,45 +98,45 @@ public class UserACLServlet extends Http
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
- // Set up the environment
- LCF.initializeEnvironment();
+ try
+ {
+ // Set up the environment
+ LCF.initializeEnvironment();
- Logging.authorityService.debug("Received request");
+ Logging.authorityService.debug("Received request");
- String userID = request.getParameter("username");
- if (userID == null)
- {
- response.sendError(response.SC_BAD_REQUEST);
- return;
- }
+ String userID = request.getParameter("username");
+ if (userID == null)
+ {
+ response.sendError(response.SC_BAD_REQUEST);
+ return;
+ }
- boolean idneeded = false;
- boolean aclneeded = true;
+ boolean idneeded = false;
+ boolean aclneeded = true;
- String idneededValue = request.getParameter("idneeded");
- if (idneededValue != null)
- {
- if (idneededValue.equals("true"))
- idneeded = true;
- else if (idneededValue.equals("false"))
- idneeded = false;
- }
- String aclneededValue = request.getParameter("aclneeded");
- if (aclneededValue != null)
- {
- if (aclneededValue.equals("true"))
- aclneeded = true;
- else if (aclneededValue.equals("false"))
- aclneeded = false;
- }
+ String idneededValue = request.getParameter("idneeded");
+ if (idneededValue != null)
+ {
+ if (idneededValue.equals("true"))
+ idneeded = true;
+ else if (idneededValue.equals("false"))
+ idneeded = false;
+ }
+ String aclneededValue = request.getParameter("aclneeded");
+ if (aclneededValue != null)
+ {
+ if (aclneededValue.equals("true"))
+ aclneeded = true;
+ else if (aclneededValue.equals("false"))
+ aclneeded = false;
+ }
- if (Logging.authorityService.isDebugEnabled())
- {
- Logging.authorityService.debug("Received authority request for user '"+userID+"'");
- }
+ if (Logging.authorityService.isDebugEnabled())
+ {
+ Logging.authorityService.debug("Received authority request for user '"+userID+"'");
+ }
- try
- {
RequestQueue queue = LCF.getRequestQueue();
if (queue == null)
{
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBCreate.java Thu Jun 10 14:22:50 2010
@@ -47,7 +47,7 @@ public class DBCreate
{
LCF.initializeEnvironment();
IThreadContext tc = ThreadContextFactory.make();
- LCF.createSystemDatabase(tc,null,userName,password);
+ LCF.createSystemDatabase(tc,userName,password);
System.err.println("LCF database created");
}
catch (LCFException e)
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/DBDrop.java Thu Jun 10 14:22:50 2010
@@ -48,7 +48,7 @@ public class DBDrop
{
LCF.initializeEnvironment();
IThreadContext tc = ThreadContextFactory.make();
- LCF.dropSystemDatabase(tc,null,userName,password);
+ LCF.dropSystemDatabase(tc,userName,password);
System.err.println("LCF database dropped");
}
catch (LCFException e)
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/LockClean.java Thu Jun 10 14:22:50 2010
@@ -38,27 +38,35 @@ public class LockClean
System.exit(1);
}
- LCF.initializeEnvironment();
- String synchDir = LCF.getProperty(org.apache.lcf.core.lockmanager.LockManager.synchDirectoryProperty);
- if (synchDir != null)
+ try
{
- // Recursively clean up the contents of the synch directory.
- File dir = new File(synchDir);
- if (dir.isDirectory())
+ LCF.initializeEnvironment();
+ String synchDir = LCF.getProperty(org.apache.lcf.core.lockmanager.LockManager.synchDirectoryProperty);
+ if (synchDir != null)
{
- File[] files = dir.listFiles();
- int i = 0;
- while (i < files.length)
+ // Recursively clean up the contents of the synch directory.
+ File dir = new File(synchDir);
+ if (dir.isDirectory())
{
- if (files[i].isDirectory())
- removeDirectory(files[i]);
- else
- files[i].delete();
- i++;
+ File[] files = dir.listFiles();
+ int i = 0;
+ while (i < files.length)
+ {
+ if (files[i].isDirectory())
+ removeDirectory(files[i]);
+ else
+ files[i].delete();
+ i++;
+ }
}
}
+ System.err.println("Synchronization storage cleaned up");
+ }
+ catch (LCFException e)
+ {
+ e.printStackTrace(System.err);
+ System.exit(2);
}
- System.err.println("Synchronization storage cleaned up");
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java Thu Jun 10 14:22:50 2010
@@ -23,6 +23,7 @@ import org.apache.lcf.core.system.LCF;
import org.apache.lcf.core.system.Logging;
import java.util.*;
import java.io.*;
+import java.sql.*;
public class DBInterfaceDerby extends Database implements IDBInterface
{
@@ -33,6 +34,7 @@ public class DBInterfaceDerby extends Da
public final static String databasePathProperty = "org.apache.lcf.derbydatabasepath";
+
protected String userName;
protected String password;
@@ -47,7 +49,7 @@ public class DBInterfaceDerby extends Da
String path = LCF.getProperty(databasePathProperty);
if (path == null)
throw new LCFException("Derby database requires '"+databasePathProperty+"' property, containing a full path");
- path = path.replace("\\","/");
+ path = path.replace("\\\\","/");
if (!path.endsWith("/"))
path = path + "/";
return path + databaseName;
@@ -56,12 +58,57 @@ public class DBInterfaceDerby extends Da
public DBInterfaceDerby(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- super(tc,_url+getFullDatabasePath((databaseName==null)?"default":databaseName)+";create=true;user="+userName+";password="+password,_driver,getFullDatabasePath((databaseName==null)?"default":databaseName),userName,password);
+ super(tc,_url+getFullDatabasePath(databaseName)+";user="+userName+";password="+password,_driver,getFullDatabasePath(databaseName),userName,password);
cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
this.userName = userName;
this.password = password;
}
+ /** Initialize. This method is called once per JVM instance, in order to set up
+ * database communication.
+ */
+ public void openDatabase()
+ throws LCFException
+ {
+ try
+ {
+ // Force a load of the appropriate JDBC driver
+ Class.forName(_driver).newInstance();
+ DriverManager.getConnection(_url+databaseName+";create=true;user="+userName+";password="+password,userName,password).close();
+ }
+ catch (Exception e)
+ {
+ throw new LCFException(e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
+ }
+
+ /** Uninitialize. This method is called during JVM shutdown, in order to close
+ * all database communication.
+ */
+ public void closeDatabase()
+ throws LCFException
+ {
+ try
+ {
+ // Force a load of the appropriate JDBC driver
+ Class.forName(_driver).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new LCFException(e.getMessage(),e);
+ }
+
+ // For the shutdown itself, eat the exception
+ try
+ {
+ DriverManager.getConnection(_url+databaseName+";shutdown=true;user="+userName+";password="+password,userName,password).close();
+ }
+ catch (Exception e)
+ {
+ // Never any exception!
+ }
+ }
+
/** Get the database general cache key.
*@return the general cache key for the database.
*/
@@ -471,121 +518,42 @@ public class DBInterfaceDerby extends Da
}
/** Create user and database.
- *@param userName is the user name.
- *@param password is the user's desired password.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void createUserAndDatabase(String userName, String password, String databaseName,
- StringSet invalidateKeys)
+ public void createUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- if (lookupUser(userName,null,null) == false)
- {
- performCreateUser(userName,password,invalidateKeys);
- }
-
- if (lookupDatabase(databaseName,null,null) == false)
+ Database rootDatabase = new Database(context,_url+databaseName,_driver,databaseName,"","");
+ IResultSet set = rootDatabase.executeQuery("VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('derby.user."+userName+"')",null,null,null,null,true,-1,null,null);
+ if (set.getRowCount() == 0)
{
- performCreateDatabase(databaseName,userName,password,invalidateKeys);
+ rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"', '"+password+"')",null,invalidateKeys,null,null,false,0,null,null);
+ rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,invalidateKeys,null,null,false,0,null,null);
}
-
}
/** Drop user and database.
- *@param userName is the user name.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
+ public void dropUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- if (lookupDatabase(databaseName,null,null))
+ File f = new File(databaseName);
+ if (f.exists())
{
- performDropDatabase(databaseName,invalidateKeys);
+ // Try to guarantee that all connections are discarded before we shut the database down. Otherwise we get pool warnings from bitstream.
+ ConnectionFactory.releaseAll();
+ // Make sure database is shut down.
+ closeDatabase();
+ // Now, it's OK to delete
+ recursiveDelete(f);
}
}
- /** Perform user lookup.
- *@param userName is the user name to lookup.
- *@return true if the user exists.
- */
- protected boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
- throws LCFException
- {
- Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
- IResultSet set = rootDatabase.executeQuery("VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('derby.user."+userName+"')",null,cacheKeys,null,queryClass,true,-1,null,null);
- if (set.getRowCount() == 0)
- return false;
- return true;
- }
-
- /** Perform user create.
- *@param userName is the user name.
- *@param password is the user's password.
- */
- protected void performCreateUser(String userName, String password, StringSet invalidateKeys)
- throws LCFException
- {
- Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
- rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"', '"+password+"')",null,invalidateKeys,null,null,false,0,null,null);
- rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,invalidateKeys,null,null,false,0,null,null);
- }
-
- /** Perform user delete.
- *@param userName is the user name.
- */
- public void performDropUser(String userName, StringSet invalidateKeys)
- throws LCFException
- {
- Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
- rootDatabase.executeQuery("DROP SCHEMA "+userName+" RESTRICT",null,invalidateKeys,null,null,false,0,null,null);
- rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"', null)",null,invalidateKeys,null,null,false,0,null,null);
- }
-
- /** Perform database lookup.
- *@param databaseName is the database name.
- *@param cacheKeys are the cache keys, if any.
- *@return true if the database exists.
- */
- protected boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
- throws LCFException
- {
- File f = new File(databaseName);
- return f.exists();
- }
-
- /** Perform database create.
- *@param databaseName is the database name.
- *@param databaseUser is the user to grant access to the database.
- *@param databasePassword is the password of the user to grant access to the database.
- *@param invalidateKeys are the cache keys that should be invalidated, if any.
- */
- protected void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
- StringSet invalidateKeys)
- throws LCFException
- {
- // Do nothing here; we create the database automatically whenever we go try to do stuff.
- //DatabaseFactory.make(context,_url+databaseName+";create=true",_driver,
- // database.getDatabaseName(),userName,password);
- }
-
- /** Perform database drop.
- *@param databaseName is the database name.
- *@param invalidateKeys are the cache keys that should be invalidated, if any.
- */
- protected void performDropDatabase(String databaseName, StringSet invalidateKeys)
- throws LCFException
- {
- // Cause database to shut down
- new Database(context,_url+databaseName+";shutdown=true",_driver,databaseName,"","");
- // DO NOT delete user or shutdown database, since this is in fact impossible under java 1.5 (since Derby makes its directories read-only, and
- // there's no way to undo that...
- // rm -rf <databasename>
- //File f = new File(databaseName);
- //recursiveDelete(f);
- }
-
protected static void recursiveDelete(File f)
{
File[] files = f.listFiles();
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java Thu Jun 10 14:22:50 2010
@@ -34,10 +34,28 @@ public class DBInterfaceMySQL extends Da
public DBInterfaceMySQL(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- super(tc,_url+databaseName,_driver,(databaseName==null)?"mysql":databaseName,userName,password);
+ super(tc,_url+databaseName,_driver,databaseName,userName,password);
cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
}
+ /** Initialize. This method is called once per JVM instance, in order to set up
+ * database communication.
+ */
+ public void openDatabase()
+ throws LCFException
+ {
+ // Nothing to do.
+ }
+
+ /** Uninitialize. This method is called during JVM shutdown, in order to close
+ * all database communication.
+ */
+ public void closeDatabase()
+ throws LCFException
+ {
+ // Nothing to do.
+ }
+
/** Get the database general cache key.
*@return the general cache key for the database.
*/
@@ -360,53 +378,37 @@ public class DBInterfaceMySQL extends Da
}
/** Create user and database.
- *@param userName is the user name.
- *@param password is the user's desired password.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void createUserAndDatabase(String userName, String password, String databaseName,
- StringSet invalidateKeys)
+ public void createUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- beginTransaction();
- try
- {
- performModification("CREATE DATABASE "+databaseName+" CHARACTER SET "+
- quoteSQLString("utf8"),null,invalidateKeys);
- if (userName != null)
- {
- performModification("GRANT ALL ON "+databaseName+".* TO "+
- quoteSQLString(userName)+"@"+
- quoteSQLString("localhost")+" IDENTIFIED BY "+
- quoteSQLString(password),null,invalidateKeys);
- }
- }
- catch (LCFException e)
- {
- signalRollback();
- throw e;
- }
- catch (Error e)
- {
- signalRollback();
- throw e;
- }
- finally
- {
- endTransaction();
+ // Connect to super database
+ Database masterDatabase = new Database(context,_url+"mysql",_driver,"mysql",adminUserName,adminPassword);
+ masterDatabase.executeQuery("CREATE DATABASE "+databaseName+" CHARACTER SET "+
+ quoteSQLString("utf8"),null,null,invalidateKeys,null,false,0,null,null);
+ if (userName != null)
+ {
+ masterDatabase.executeQuery("GRANT ALL ON "+databaseName+".* TO "+
+ quoteSQLString(userName)+"@"+
+ quoteSQLString("localhost")+" IDENTIFIED BY "+
+ quoteSQLString(password),null,null,invalidateKeys,null,false,0,null,null);
}
}
/** Drop user and database.
- *@param userName is the user name.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
+ public void dropUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- performModification("DROP DATABASE "+databaseName,null,invalidateKeys);
+ // Connect to super database
+ Database masterDatabase = new Database(context,_url+"mysql",_driver,"mysql",adminUserName,adminPassword);
+ masterDatabase.executeQuery("DROP DATABASE "+databaseName,null,null,invalidateKeys,null,false,0,null,null);
}
/** Perform a general database modification query.
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java Thu Jun 10 14:22:50 2010
@@ -43,10 +43,28 @@ public class DBInterfacePostgreSQL exten
public DBInterfacePostgreSQL(IThreadContext tc, String databaseName, String userName, String password)
throws LCFException
{
- super(tc,_url+((databaseName==null)?"template1":databaseName),_driver,((databaseName==null)?"template1":databaseName),userName,password);
+ super(tc,_url+databaseName,_driver,databaseName,userName,password);
cacheKey = CacheKeyFactory.makeDatabaseKey(this.databaseName);
}
+ /** Initialize. This method is called once per JVM instance, in order to set up
+ * database communication.
+ */
+ public void openDatabase()
+ throws LCFException
+ {
+ // Nothing to do
+ }
+
+ /** Uninitialize. This method is called during JVM shutdown, in order to close
+ * all database communication.
+ */
+ public void closeDatabase()
+ throws LCFException
+ {
+ // Nothing to do
+ }
+
/** Get the database general cache key.
*@return the general cache key for the database.
*/
@@ -460,113 +478,64 @@ public class DBInterfacePostgreSQL exten
}
/** Create user and database.
- *@param userName is the user name.
- *@param password is the user's desired password.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void createUserAndDatabase(String userName, String password, String databaseName,
- StringSet invalidateKeys)
+ public void createUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- if (lookupUser(userName,null,null) == false)
+ // Create a connection to the master database, using the credentials supplied
+ Database masterDatabase = new Database(context,_url+"template1",_driver,"template1",adminUserName,adminPassword);
+ try
{
- performCreateUser(userName,password,invalidateKeys);
+ // Create user
+ ArrayList params = new ArrayList();
+ params.add(userName);
+ IResultSet set = masterDatabase.executeQuery("SELECT * FROM pg_user WHERE usename=?",params,null,null,null,true,-1,null,null);
+ if (set.getRowCount() == 0)
+ {
+ masterDatabase.executeQuery("CREATE USER "+userName+" PASSWORD "+
+ quoteSQLString(password),null,null,invalidateKeys,null,false,0,null,null);
+ }
+
+ // Create database
+ params = new ArrayList();
+ params.add(userName);
+ set = masterDatabase.executeQuery("SELECT * FROM pg_database WHERE datname=?",params,null,null,null,true,-1,null,null);
+ if (set.getRowCount() == 0)
+ {
+ masterDatabase.executeQuery("CREATE DATABASE "+databaseName+" OWNER="+
+ userName+" ENCODING="+quoteSQLString("utf8"),null,null,invalidateKeys,null,false,0,null,null);
+ }
}
-
- if (lookupDatabase(databaseName,null,null) == false)
+ catch (LCFException e)
{
- performCreateDatabase(databaseName,userName,password,invalidateKeys);
+ throw reinterpretException(e);
}
-
}
/** Drop user and database.
- *@param userName is the user name.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
- throws LCFException
- {
- performDropDatabase(databaseName,invalidateKeys);
- performDropUser(userName,invalidateKeys);
- }
-
- /** Perform user lookup.
- *@param userName is the user name to lookup.
- *@return true if the user exists.
- */
- protected boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
+ public void dropUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException
{
- ArrayList params = new ArrayList();
- params.add(userName);
- IResultSet set = performQuery("SELECT * FROM pg_user WHERE usename=?",params,cacheKeys,queryClass);
- if (set.getRowCount() == 0)
- return false;
- return true;
- }
-
- /** Perform user create.
- *@param userName is the user name.
- *@param password is the user's password.
- */
- protected void performCreateUser(String userName, String password, StringSet invalidateKeys)
- throws LCFException
- {
- performModification("CREATE USER "+userName+" PASSWORD "+
- quoteSQLString(password),null,invalidateKeys);
- }
-
- /** Perform user delete.
- *@param userName is the user name.
- */
- protected void performDropUser(String userName, StringSet invalidateKeys)
- throws LCFException
- {
- performModification("DROP USER "+userName,null,invalidateKeys);
- }
-
- /** Perform database lookup.
- *@param databaseName is the database name.
- *@param cacheKeys are the cache keys, if any.
- *@return true if the database exists.
- */
- protected boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
- throws LCFException
- {
- ArrayList params = new ArrayList();
- params.add(databaseName);
- IResultSet set = performQuery("SELECT * FROM pg_database WHERE datname=?",params,cacheKeys,queryClass);
- if (set.getRowCount() == 0)
- return false;
- return true;
- }
-
- /** Perform database create.
- *@param databaseName is the database name.
- *@param databaseUser is the user to grant access to the database.
- *@param databasePassword is the password of the user to grant access to the database.
- *@param invalidateKeys are the cache keys that should be invalidated, if any.
- */
- protected void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
- StringSet invalidateKeys)
- throws LCFException
- {
- performModification("CREATE DATABASE "+databaseName+" OWNER="+
- databaseUser+" ENCODING="+
- quoteSQLString("utf8"),null,invalidateKeys);
- }
-
- /** Perform database drop.
- *@param databaseName is the database name.
- *@param invalidateKeys are the cache keys that should be invalidated, if any.
- */
- protected void performDropDatabase(String databaseName, StringSet invalidateKeys)
- throws LCFException
- {
- performModification("DROP DATABASE "+databaseName,null,invalidateKeys);
+ // Create a connection to the master database, using the credentials supplied
+ Database masterDatabase = new Database(context,_url+"template1",_driver,"template1",adminUserName,adminPassword);
+ try
+ {
+ // Drop database
+ masterDatabase.executeQuery("DROP DATABASE "+databaseName,null,null,invalidateKeys,null,false,0,null,null);
+ // Drop user
+ masterDatabase.executeQuery("DROP USER "+userName,null,null,invalidateKeys,null,false,0,null,null);
+ }
+ catch (LCFException e)
+ {
+ throw reinterpretException(e);
+ }
}
/** Reinterpret an exception tossed by the database layer. We need to disambiguate the various kinds of exception that
@@ -923,7 +892,7 @@ public class DBInterfacePostgreSQL exten
public void beginTransaction()
throws LCFException
{
- super.beginTransaction(TRANSACTION_ENCLOSING);
+ beginTransaction(TRANSACTION_ENCLOSING);
}
/** Begin a database transaction. This method call MUST be paired with an endTransaction() call,
@@ -974,7 +943,7 @@ public class DBInterfacePostgreSQL exten
}
break;
default:
- throw new LCFException("Bad transaction type");
+ throw new LCFException("Bad transaction type: "+Integer.toString(transactionType));
}
}
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java Thu Jun 10 14:22:50 2010
@@ -39,6 +39,18 @@ public interface IDBInterface
public static int TRANSACTION_READCOMMITTED = 1;
public static int TRANSACTION_SERIALIZED = 2;
+ /** Initialize. This method is called once per JVM instance, in order to set up
+ * database communication.
+ */
+ public void openDatabase()
+ throws LCFException;
+
+ /** Uninitialize. This method is called during JVM shutdown, in order to close
+ * all database communication.
+ */
+ public void closeDatabase()
+ throws LCFException;
+
/** Get the database name.
*@return the database name.
*/
@@ -155,21 +167,19 @@ public interface IDBInterface
throws LCFException;
/** Create user and database.
- *@param userName is the user name.
- *@param password is the user's desired password.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void createUserAndDatabase(String userName, String password, String databaseName,
- StringSet invalidateKeys)
+ public void createUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException;
/** Drop user and database.
- *@param userName is the user name.
- *@param databaseName is the database name.
+ *@param adminUserName is the admin user name.
+ *@param adminPassword is the admin password.
*@param invalidateKeys are the cache keys that should be invalidated, if any.
*/
- public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
+ public void dropUserAndDatabase(String adminUserName, String adminPassword, StringSet invalidateKeys)
throws LCFException;
/** Get a table's schema.
Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java Thu Jun 10 14:22:50 2010
@@ -30,28 +30,22 @@ public class LCF
// Shutdown hooks
/** Temporary file collector */
- protected static FileTrack tracker;
+ protected static FileTrack tracker = null;
/** Database handle cleanup */
- protected static DatabaseShutdown dbShutdown;
+ protected static DatabaseShutdown dbShutdown = null;
/** Array of cleanup hooks (for managing shutdown) */
- protected static ArrayList cleanupHooks;
+ protected static ArrayList cleanupHooks = new ArrayList();
+
/** Shutdown thread */
protected static Thread shutdownThread;
- /** Static initializer for setting up shutdown thread etc. */
+ /** Static initializer for setting up shutdown thread */
static
{
- cleanupHooks = new ArrayList();
- shutdownThread = new ShutdownThread(cleanupHooks);
- tracker = new FileTrack();
- dbShutdown = new DatabaseShutdown();
+ shutdownThread = new ShutdownThread();
try
{
Runtime.getRuntime().addShutdownHook(shutdownThread);
- // Register the file tracker for cleanup on shutdown
- addShutdownHook(tracker);
- // Register the database cleanup hook
- addShutdownHook(dbShutdown);
}
catch (Exception e)
{
@@ -63,6 +57,11 @@ public class LCF
e.printStackTrace();
}
}
+
+ // Flag indicating whether system initialized or not, and synchronizer to protect that flag.
+ protected static boolean isInitialized = false;
+ protected static boolean alreadyClosed = false;
+ protected static Integer initializeFlagLock = new Integer(0);
// Local member variables
protected static String masterDatabaseName = null;
@@ -112,62 +111,74 @@ public class LCF
/** Initialize environment.
*/
- public static synchronized void initializeEnvironment()
+ public static void initializeEnvironment()
+ throws LCFException
{
- if (localProperties != null)
- return;
-
- try
+ synchronized (initializeFlagLock)
{
- // Get system properties
- java.util.Properties props = System.getProperties();
- // First, look for a define that might indicate where to look
-
- propertyFilePath = (String)props.get(lcfConfigFileProperty);
- if (propertyFilePath == null)
- {
- System.err.println("Couldn't find "+lcfConfigFileProperty+" property; using default");
- String configPath = (String)props.get("user.home") + "/"+applicationName;
- configPath = configPath.replace('\\', '/');
- propertyFilePath = new File(configPath,"properties.ini").toString();
- }
-
- // Read .ini parameters
- localProperties = new java.util.Properties();
- checkProperties();
+ if (isInitialized)
+ return;
- String logConfigFile = getProperty(logConfigFileProperty);
- if (logConfigFile == null)
+ try
{
- System.err.println("Couldn't find "+logConfigFileProperty+" property; using default");
- String configPath = (String)props.get("user.home") + "/"+applicationName;
- configPath = configPath.replace('\\', '/');
- logConfigFile = new File(configPath,"logging.ini").toString();
- }
-
- masterDatabaseName = getProperty(masterDatabaseNameProperty);
- if (masterDatabaseName == null)
- masterDatabaseName = "dbname";
- masterDatabaseUsername = getProperty(masterDatabaseUsernameProperty);
- if (masterDatabaseUsername == null)
- masterDatabaseUsername = "lcf";
- masterDatabasePassword = getProperty(masterDatabasePasswordProperty);
- if (masterDatabasePassword == null)
- masterDatabasePassword = "local_pg_passwd";
+ // Get system properties
+ java.util.Properties props = System.getProperties();
+ // First, look for a define that might indicate where to look
+
+ propertyFilePath = (String)props.get(lcfConfigFileProperty);
+ if (propertyFilePath == null)
+ {
+ System.err.println("Couldn't find "+lcfConfigFileProperty+" property; using default");
+ String configPath = (String)props.get("user.home") + "/"+applicationName;
+ configPath = configPath.replace('\\', '/');
+ propertyFilePath = new File(configPath,"properties.ini").toString();
+ }
+
+ // Read .ini parameters
+ localProperties = new java.util.Properties();
+ checkProperties();
- Logging.initializeLoggingSystem(logConfigFile);
+ String logConfigFile = getProperty(logConfigFileProperty);
+ if (logConfigFile == null)
+ {
+ System.err.println("Couldn't find "+logConfigFileProperty+" property; using default");
+ String configPath = (String)props.get("user.home") + "/"+applicationName;
+ configPath = configPath.replace('\\', '/');
+ logConfigFile = new File(configPath,"logging.ini").toString();
+ }
- // Set up local loggers
- Logging.initializeLoggers();
- Logging.setLogLevels();
+ Logging.initializeLoggingSystem(logConfigFile);
- }
- catch (LCFException e)
- {
- e.printStackTrace();
+ // Set up local loggers
+ Logging.initializeLoggers();
+ Logging.setLogLevels();
+
+ masterDatabaseName = getProperty(masterDatabaseNameProperty);
+ if (masterDatabaseName == null)
+ masterDatabaseName = "dbname";
+ masterDatabaseUsername = getProperty(masterDatabaseUsernameProperty);
+ if (masterDatabaseUsername == null)
+ masterDatabaseUsername = "lcf";
+ masterDatabasePassword = getProperty(masterDatabasePasswordProperty);
+ if (masterDatabasePassword == null)
+ masterDatabasePassword = "local_pg_passwd";
+
+ // Register the file tracker for cleanup on shutdown
+ addShutdownHook(new FileTrack());
+ // Register the database cleanup hook
+ addShutdownHook(new DatabaseShutdown());
+
+ // Open the database. Done once per JVM.
+ IThreadContext threadcontext = ThreadContextFactory.make();
+ DBInterfaceFactory.make(threadcontext,masterDatabaseName,masterDatabaseUsername,masterDatabasePassword).openDatabase();
+ isInitialized = true;
+ }
+ catch (LCFException e)
+ {
+ throw new LCFException("Initialization failed: "+e.getMessage(),e,LCFException.SETUP_ERROR);
+ }
}
-
}
/** Reloads properties as needed.
@@ -534,34 +545,34 @@ public class LCF
/** Install system database.
*@param threadcontext is the thread context.
- *@param masterName is the master database name ("mysql" for mysql).
*@param masterUsername is the master database user name.
*@param masterPassword is the master database password.
*/
- public static void createSystemDatabase(IThreadContext threadcontext, String masterName,
- String masterUsername, String masterPassword)
+ public static void createSystemDatabase(IThreadContext threadcontext, String masterUsername, String masterPassword)
throws LCFException
{
String databaseName = getMasterDatabaseName();
String databaseUsername = getMasterDatabaseUsername();
String databasePassword = getMasterDatabasePassword();
- IDBInterface master = DBInterfaceFactory.make(threadcontext,masterName,masterUsername,masterPassword);
- master.createUserAndDatabase(databaseUsername,databasePassword,databaseName,null);
+ IDBInterface master = DBInterfaceFactory.make(threadcontext,databaseName,databaseUsername,databasePassword);
+ master.createUserAndDatabase(masterUsername,masterPassword,null);
}
/** Drop system database.
*@param threadcontext is the thread context.
- *@param masterName is the master database name ("mysql" for mysql).
*@param masterUsername is the master database user name.
*@param masterPassword is the master database password.
*/
- public static void dropSystemDatabase(IThreadContext threadcontext, String masterName,
- String masterUsername, String masterPassword)
+ public static void dropSystemDatabase(IThreadContext threadcontext, String masterUsername, String masterPassword)
throws LCFException
{
- IDBInterface master = DBInterfaceFactory.make(threadcontext,masterName,masterUsername,masterPassword);
- master.dropUserAndDatabase(getMasterDatabaseUsername(),getMasterDatabaseName(),null);
+ String databaseName = getMasterDatabaseName();
+ String databaseUsername = getMasterDatabaseUsername();
+ String databasePassword = getMasterDatabasePassword();
+
+ IDBInterface master = DBInterfaceFactory.make(threadcontext,databaseName,databaseUsername,databasePassword);
+ master.dropUserAndDatabase(masterUsername,masterPassword,null);
}
/** Add a file to the tracking system. */
@@ -1089,16 +1100,52 @@ public class LCF
catch (InterruptedException e)
{
}
+ closeDatabase();
+ }
+
+ protected void closeDatabase()
+ throws LCFException
+ {
+ synchronized (initializeFlagLock)
+ {
+ if (isInitialized && !alreadyClosed)
+ {
+ IThreadContext threadcontext = ThreadContextFactory.make();
+
+ String databaseName = getMasterDatabaseName();
+ String databaseUsername = getMasterDatabaseUsername();
+ String databasePassword = getMasterDatabasePassword();
+
+ DBInterfaceFactory.make(threadcontext,databaseName,databaseUsername,databasePassword).closeDatabase();
+ alreadyClosed = true;
+ }
+ }
+ }
+
+ /** Finalizer, which is designed to catch class unloading that tomcat 5.5 does.
+ */
+ protected void finalize()
+ throws Throwable
+ {
+ try
+ {
+ // The database handle cleanup is handled inside the finalizers for the pools that hold onto connections.
+ closeDatabase();
+ }
+ finally
+ {
+ super.finalize();
+ }
}
+
}
/** Finisher thread, to be registered with the runtime */
protected static class ShutdownThread extends Thread
{
- protected ArrayList cleanupHooks;
/** Constructor.
*/
- public ShutdownThread(ArrayList cleanupHooks)
+ public ShutdownThread()
{
super();
setName("Shutdown thread");
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/CheckAll.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/CheckAll.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/CheckAll.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/CheckAll.java Thu Jun 10 14:22:50 2010
@@ -42,9 +42,9 @@ public class CheckAll
System.exit(1);
}
- LCF.initializeEnvironment();
try
{
+ LCF.initializeEnvironment();
IThreadContext tc = ThreadContextFactory.make();
// Now, get a list of the authority connections
IAuthorityConnectionManager mgr = AuthorityConnectionManagerFactory.make(tc);
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/system/LCF.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/authorities/system/LCF.java Thu Jun 10 14:22:50 2010
@@ -25,8 +25,9 @@ import java.util.*;
public class LCF extends org.apache.lcf.core.system.LCF
{
- protected static boolean needInit = true;
-
+ // Initialization needed flag
+ protected static boolean authoritiesInitialized = false;
+
// Threads
protected static IdleCleanupThread idleCleanupThread = null;
protected static AuthCheckThread[] authCheckThreads = null;
@@ -41,16 +42,19 @@ public class LCF extends org.apache.lcf.
/** Initialize environment.
*/
- public static synchronized void initializeEnvironment()
+ public static void initializeEnvironment()
+ throws LCFException
{
- if (needInit == false)
- return;
-
- org.apache.lcf.core.system.LCF.initializeEnvironment();
- Logging.initializeLoggers();
- Logging.setLogLevels();
- needInit = false;
+ synchronized (initializeFlagLock)
+ {
+ if (authoritiesInitialized)
+ return;
+ org.apache.lcf.core.system.LCF.initializeEnvironment();
+ Logging.initializeLoggers();
+ Logging.setLogLevels();
+ authoritiesInitialized = true;
+ }
}
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/jobs/ScheduleManager.java Thu Jun 10 14:22:50 2010
@@ -88,7 +88,7 @@ public class ScheduleManager extends org
HashMap map = new HashMap();
map.put(yearField,new ColumnDescription("VARCHAR(255)",false,true,null,null,false));
performAlter(map,null,null,null);
- performModification("UPDATE "+getTableName()+" SET ("+yearField+"=year)",null,null);
+ performModification("UPDATE "+getTableName()+" SET "+yearField+"=year",null,null);
ArrayList list = new ArrayList();
list.add("year");
performAlter(null,null,list,null);
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/repository/ThrottleSpecManager.java Thu Jun 10 14:22:50 2010
@@ -75,7 +75,7 @@ public class ThrottleSpecManager extends
HashMap map = new HashMap();
map.put(matchField,new ColumnDescription("VARCHAR(255)",false,true,null,null,false));
performAlter(map,null,null,null);
- performModification("UPDATE "+getTableName()+" SET ("+matchField+"=match)",null,null);
+ performModification("UPDATE "+getTableName()+" SET "+matchField+"=match",null,null);
ArrayList list = new ArrayList();
list.add("match");
performAlter(null,null,list,null);
Modified: incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/system/LCF.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/org/apache/lcf/crawler/system/LCF.java Thu Jun 10 14:22:50 2010
@@ -29,9 +29,9 @@ public class LCF extends org.apache.lcf.
{
public static final String _rcsid = "@(#)$Id$";
- // Track whether initialized or not
- protected static Integer isInitialized = null;
-
+ // Initialization flag.
+ protected static boolean crawlerInitialized = false;
+
// Thread objects.
// These get filled in as threads are created.
protected static InitializationThread initializationThread = null;
@@ -78,18 +78,21 @@ public class LCF extends org.apache.lcf.
/** Initialize environment.
*/
- public static synchronized void initializeEnvironment()
+ public static void initializeEnvironment()
+ throws LCFException
{
- org.apache.lcf.authorities.system.LCF.initializeEnvironment();
-
- if (isInitialized != null)
- return;
-
- isInitialized = new Integer(0);
- org.apache.lcf.agents.system.LCF.initializeEnvironment();
- Logging.initializeLoggers();
- Logging.setLogLevels();
-
+ synchronized (initializeFlagLock)
+ {
+ org.apache.lcf.authorities.system.LCF.initializeEnvironment();
+
+ if (crawlerInitialized)
+ return;
+
+ org.apache.lcf.agents.system.LCF.initializeEnvironment();
+ Logging.initializeLoggers();
+ Logging.setLogLevels();
+ crawlerInitialized = true;
+ }
}
Modified: incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/agents/tests/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/agents/tests/TestBase.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/agents/tests/TestBase.java (original)
+++ incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/agents/tests/TestBase.java Thu Jun 10 14:22:50 2010
@@ -42,7 +42,15 @@ public class TestBase extends org.apache
{
System.out.println("Warning: Preclean failed: "+e.getMessage());
}
- localSetUp();
+ try
+ {
+ localSetUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localSetUp()
@@ -61,7 +69,15 @@ public class TestBase extends org.apache
public void cleanUp()
throws Exception
{
- localCleanUp();
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localCleanUp()
Modified: incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/core/tests/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/core/tests/TestBase.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/core/tests/TestBase.java (original)
+++ incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/core/tests/TestBase.java Thu Jun 10 14:22:50 2010
@@ -62,7 +62,15 @@ public class TestBase
{
System.out.println("Warning: Preclean error: "+e.getMessage());
}
- localSetUp();
+ try
+ {
+ localSetUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
@@ -86,7 +94,7 @@ public class TestBase
IThreadContext tc = ThreadContextFactory.make();
// Create the database
- LCF.createSystemDatabase(tc,null,"","");
+ LCF.createSystemDatabase(tc,"","");
}
@@ -94,7 +102,15 @@ public class TestBase
public void cleanUp()
throws Exception
{
- localCleanUp();
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localCleanUp()
@@ -107,7 +123,7 @@ public class TestBase
IThreadContext tc = ThreadContextFactory.make();
// Remove the database
- LCF.dropSystemDatabase(tc,null,"","");
+ LCF.dropSystemDatabase(tc,"","");
// Get rid of the property and logging files.
logOutputFile.delete();
Modified: incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestBase.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestBase.java (original)
+++ incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestBase.java Thu Jun 10 14:22:50 2010
@@ -43,7 +43,15 @@ public class TestBase extends org.apache
{
System.out.println("Warning: Preclean failed: "+e.getMessage());
}
- localSetUp();
+ try
+ {
+ localSetUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localSetUp()
@@ -63,7 +71,15 @@ public class TestBase extends org.apache
public void cleanUp()
throws Exception
{
- localCleanUp();
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localCleanUp()
Modified: incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java?rev=953331&r1=953330&r2=953331&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java (original)
+++ incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java Thu Jun 10 14:22:50 2010
@@ -74,7 +74,15 @@ public class TestConnectorBase extends o
{
System.out.println("Warning: Preclean failed: "+e.getMessage());
}
- localSetUp();
+ try
+ {
+ localSetUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localSetUp()
@@ -169,7 +177,15 @@ public class TestConnectorBase extends o
public void cleanUp()
throws Exception
{
- localCleanUp();
+ try
+ {
+ localCleanUp();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
}
protected void localCleanUp()