You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/02/13 00:27:08 UTC

svn commit: r377272 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/reference/Property.java impl/services/monitor/BaseMonitor.java

Author: djd
Date: Sun Feb 12 15:27:04 2006
New Revision: 377272

URL: http://svn.apache.org/viewcvs?rev=377272&view=rev
Log:
DERBY-927 (partial) Load sub-sub protocol implementations (derby.subSubProtocol.*)
from implementation locations using the same mechanism as modules (derby.module.*).
This allows sub-sub protocols to utilize the environment requirement variables
derby.env.jdk.* and derby.env.classes.* to control their booting.
Move some constants into Property.java with detailed comments.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java?rev=377272&r1=377271&r2=377272&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java Sun Feb 12 15:27:04 2006
@@ -486,6 +486,23 @@
 	 *<B>INTERNAL USE ONLY</B> 
 	 */
 	String LOG_DEVICE_AT_BACKUP = "derby.storage.logDeviceWhenBackedUp";
+    
+    /**
+     * derby.module.modulename
+     * <P>
+     * Defines a new module. Modulename is a name used when loading the definition
+     * of a module, it provides the linkage to other properties used to define the
+     * module, derby.env.jdk.modulename and derby.env.classes.modulename.
+     * 
+     * The value is a Java class name that implements functionality required by
+     * the other parts of a Derby system or database. The class can optionally implement
+     * these classes to control its use and startup.
+     * <UL>
+     * <LI> org.apache.derby.iapi.services.monitor.ModuleControl
+     * <LI> org.apache.derby.iapi.services.monitor.ModuleSupportable
+     * </UL>
+     */
+    String MODULE_PREFIX = "derby.module.";
 
     /**
      *  derby.subSubProtocol.xxx
@@ -510,8 +527,31 @@
      * Subsubprotocols "directory", "classpath", "jar", "http", and "https" are built in and may not be overridden.
      */
     String SUB_SUB_PROTOCOL_PREFIX = "derby.subSubProtocol.";
+    
+    
+    /**
+     * Declare a minimum JDK level the class for a module or sub sub protocol supports.
+     * Set to an integer value from the JVMInfo class to represent a JDK.
+     * If the JDK is running at a lower level than the class requires
+     * then the class will not be loaded and will not be used.
+     * 
+     * If there are multiple modules classes implementing the same functionality
+     * and supported by the JVM, then the one with the highest JDK
+     * requirements will be selected. This functionality is not present for
+     * sub sub protocol classes yet.
+     * 
+     * @see org.apache.derby.iapi.services.info.JVMInfo.JDK_ID
+     */
+    String MODULE_ENV_JDK_PREFIX = "derby.env.jdk.";
+
+    /**
+     * Declare a set of classes that the class for a module or sub sub protocol requires.
+     * Value is a comma separated list of classes. If the classes listed are not
+     * loadable by the virtual machine then the module class will not be loaded and will not be used.
+    */
+    String MODULE_ENV_CLASSES_PREFIX = "derby.env.classes.";
 
-	/*
+    /*
 	** derby.language.*
 	*/
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=377272&r1=377271&r2=377272&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java Sun Feb 12 15:27:04 2006
@@ -1065,162 +1065,154 @@
 		for (Enumeration e = moduleList.propertyNames(); e.hasMoreElements(); ) {
 
 			String key = (String) e.nextElement();
-			if (key.startsWith("derby.module.")) {
-				int keylength = "derby.module.".length();
-				String tag = key.substring(keylength);
-
-				// Check to see if it has any environment requirements
-
-				// derby.env.jdk.<tag> - Any JDK requirements.
-				String envKey = "derby.env.jdk.".concat(tag);
-				String envJDK = moduleList.getProperty(envKey);
-				int envJDKId = 0;
-				
-				if (envJDK != null) {
-					envJDKId = Integer.parseInt(envJDK.trim());
-					if (envJDKId > theJDKId) {
-						continue nextModule;
-					}
+            
+            // module tagged name in the modules.properties file.
+            // used as the tag  for dependent properties.
+            String tag;
+            
+            // Dynamically loaded code is defined by a property of
+            // the form:
+            // derby.module.<modulename>=<class name>
+            // or
+            // derby.subSubProtocol.<modulename>=<classname>
+            
+			if (key.startsWith(Property.MODULE_PREFIX)) {
+				tag = key.substring(Property.MODULE_PREFIX.length());
+            } else if (key.startsWith(Property.SUB_SUB_PROTOCOL_PREFIX)) {
+                tag = key.substring(Property.MODULE_PREFIX.length());
+            } else {
+                continue nextModule;
+            }
+            
+
+			// Check to see if it has any environment requirements
+
+			// derby.env.jdk.<modulename> - Any JDK requirements.
+			String envKey = Property.MODULE_ENV_JDK_PREFIX.concat(tag);
+			String envJDK = moduleList.getProperty(envKey);
+			int envJDKId = 0;
+			
+			if (envJDK != null) {
+				envJDKId = Integer.parseInt(envJDK.trim());
+				if (envJDKId > theJDKId) {
+					continue nextModule;
 				}
+			}
 
-				// derby.env.classes.<tag> - Any class requirements
-				envKey = "derby.env.classes.".concat(tag);
-				String envClasses = moduleList.getProperty(envKey);
-				if (envClasses != null) {
-
-					StringTokenizer st = new StringTokenizer(envClasses, ",");
-					for (; st.hasMoreTokens(); ) {
-						try {
-							Class.forName(st.nextToken().trim());
-						} catch (ClassNotFoundException cnfe) {
-							continue nextModule;
-						} catch (LinkageError le) {
-							continue nextModule;
-						}
+			// derby.env.classes.<tag> - Any class requirements
+			envKey = Property.MODULE_ENV_CLASSES_PREFIX.concat(tag);
+			String envClasses = moduleList.getProperty(envKey);
+			if (envClasses != null) {
+
+				StringTokenizer st = new StringTokenizer(envClasses, ",");
+				for (; st.hasMoreTokens(); ) {
+					try {
+						Class.forName(st.nextToken().trim());
+					} catch (ClassNotFoundException cnfe) {
+						continue nextModule;
+					} catch (LinkageError le) {
+						continue nextModule;
 					}
 				}
+			}
 
 
 
-				// we load the class and run its registerFormatC
-				// if we can't load the class or create an instance then
-				// we don't use this calls as a valid module implementation
-				String className = moduleList.getProperty(key);
+			// Try to load the class
+			// if we can't load the class or create an instance then
+			// we don't use this calls as a valid module implementation
+			String className = moduleList.getProperty(key);
 
-				if (SanityManager.DEBUG && reportOn) {
-					report("Accessing module " + className + " to run initializers at boot time");
-				}
+			if (SanityManager.DEBUG && reportOn) {
+				report("Accessing module " + className + " to run initializers at boot time");
+			}
 
-				try {
-					Class possibleModule = Class.forName(className);
+			try {
+				Class possibleModule = Class.forName(className);
 
-					// Look for the monitors special modules, PersistentService ones.
-					if (getPersistentServiceImplementation(possibleModule))
-                        continue;
-
-					// If this is a specific JDK version (environment) module
-					// then it must be ordered in the implementation list by envJDKId.
-					// Those with a higher number are at the front, e.g.
-					//
-					//	JDK 1.4 modules (envJDKId == 4)
-					//  JDK 1.2/1.3 modules (envJDKId == 2)
-					//  JDK 1.1 modules (envJDKId == 1)
-					//  generic modules (envJDKId == 0 (not set in modules.properties)
-					//
-					//  Note modules with envJDKId > theJDKId do not get here
-
-					if (envJDKId != 0) {
-
-						// total how many modules with a higher envJDKId are ahead of us
-						int offset = 0;
-						for (int eji = theJDKId; eji > envJDKId; eji--) {
-							offset += envModuleCount[eji];
-						}
+				// Look for the monitors special modules, PersistentService ones.
+				if (getPersistentServiceImplementation(possibleModule))
+                    continue;
+                
+                
+                if( StorageFactory.class.isAssignableFrom(possibleModule)) {
+                    storageFactories.put(tag, className);
+                    continue;
+                }
 
-						implementations.insertElementAt(possibleModule, offset);
-						envModuleCount[envJDKId]++;
 
+				// If this is a specific JDK version (environment) module
+				// then it must be ordered in the implementation list by envJDKId.
+				// Those with a higher number are at the front, e.g.
+				//
+				//	JDK 1.4 modules (envJDKId == 4)
+				//  JDK 1.2/1.3 modules (envJDKId == 2)
+				//  JDK 1.1 modules (envJDKId == 1)
+				//  generic modules (envJDKId == 0 (not set in modules.properties)
+				//
+				//  Note modules with envJDKId > theJDKId do not get here
+
+				if (envJDKId != 0) {
+
+					// total how many modules with a higher envJDKId are ahead of us
+					int offset = 0;
+					for (int eji = theJDKId; eji > envJDKId; eji--) {
+						offset += envModuleCount[eji];
 					}
-					else {
-						// just add to the end of the vector
-						implementations.addElement(possibleModule);
-					}
 
-					// Since ModuleControl and ModuleSupportable are not called directly
-					// check that if the have the methods then the class implements the
-					// interface.
-					if (SanityManager.DEBUG) {
-						// ModuleSupportable
-						Class[] csParams = { new java.util.Properties().getClass()};
-						try {
-							possibleModule.getMethod("canSupport", csParams);
-							if (!ModuleSupportable.class.isAssignableFrom(possibleModule)) {
-								SanityManager.THROWASSERT("Module does not implement ModuleSupportable but has canSupport() - " + className);
-							}
-						} catch (NoSuchMethodException nsme){/* ok*/}
-
-						// ModuleControl
-						boolean eitherMethod = false;
-
-						Class[] bootParams = {Boolean.TYPE, new java.util.Properties().getClass()};
-						try {
-							possibleModule.getMethod("boot", bootParams);
-							eitherMethod = true;
-						} catch (NoSuchMethodException nsme){/*ok*/}
-
-						Class[] stopParams = {};
-						try {
-							possibleModule.getMethod("stop", stopParams);
-							eitherMethod = true;
-						} catch (NoSuchMethodException nsme){/*ok*/}
-
-						if (eitherMethod) {
-							if (!ModuleControl.class.isAssignableFrom(possibleModule)) {
-								SanityManager.THROWASSERT("Module does not implement ModuleControl but has its methods - " + className);
-							}
+					implementations.insertElementAt(possibleModule, offset);
+					envModuleCount[envJDKId]++;
+
+				}
+				else {
+					// just add to the end of the vector
+					implementations.addElement(possibleModule);
+				}
+
+				// Since ModuleControl and ModuleSupportable are not called directly
+				// check that if the have the methods then the class implements the
+				// interface.
+				if (SanityManager.DEBUG) {
+					// ModuleSupportable
+					Class[] csParams = { new java.util.Properties().getClass()};
+					try {
+						possibleModule.getMethod("canSupport", csParams);
+						if (!ModuleSupportable.class.isAssignableFrom(possibleModule)) {
+							SanityManager.THROWASSERT("Module does not implement ModuleSupportable but has canSupport() - " + className);
 						}
+					} catch (NoSuchMethodException nsme){/* ok*/}
 
+					// ModuleControl
+					boolean eitherMethod = false;
 
-						
+					Class[] bootParams = {Boolean.TYPE, new java.util.Properties().getClass()};
+					try {
+						possibleModule.getMethod("boot", bootParams);
+						eitherMethod = true;
+					} catch (NoSuchMethodException nsme){/*ok*/}
+
+					Class[] stopParams = {};
+					try {
+						possibleModule.getMethod("stop", stopParams);
+						eitherMethod = true;
+					} catch (NoSuchMethodException nsme){/*ok*/}
+
+					if (eitherMethod) {
+						if (!ModuleControl.class.isAssignableFrom(possibleModule)) {
+							SanityManager.THROWASSERT("Module does not implement ModuleControl but has its methods - " + className);
+						}
 					}
-
-				}
-				catch (ClassNotFoundException cnfe) {
-					report("Class " + className + " " + cnfe.toString() + ", module ignored.");
 				}
-				catch (LinkageError le) {
-					report("Class " + className + " " + le.toString() + ", module ignored.");
-				}
-			}
-            else if( key.startsWith( Property.SUB_SUB_PROTOCOL_PREFIX)) {
-                String subSubProtocol = key.substring( Property.SUB_SUB_PROTOCOL_PREFIX.length());
-                String className = moduleList.getProperty(key);
-
-				if (SanityManager.DEBUG && reportOn) {
-					report("Accessing module " + className + " to run initializers at boot time");
-				}
-                try {
-                    Class possibleImplementation = Class.forName(className);
-					// Look for the monitors special classes, PersistentService and StorageFactory ones.
-                    if( getPersistentServiceImplementation( possibleImplementation))
-                        continue;
-                    if( StorageFactory.class.isAssignableFrom( possibleImplementation)) {
-                        if( newInstance( possibleImplementation) == null)
-                            report("Class " + className + " cannot create instance, StorageFactory ignored.");
-                        else
-                            storageFactories.put( subSubProtocol, className);
-                        continue;
-                    }
-                }
-				catch (ClassNotFoundException cnfe) {
-					report("Class " + className + " " + cnfe.toString() + ", module ignored.");
-				}
-				catch (LinkageError le) {
-					report("Class " + className + " " + le.toString() + ", module ignored.");
-				}
-            }
-        }
 
+			}
+			catch (ClassNotFoundException cnfe) {
+				report("Class " + className + " " + cnfe.toString() + ", module ignored.");
+			}
+			catch (LinkageError le) {
+				report("Class " + className + " " + le.toString() + ", module ignored.");
+			}
+		}
+        
 		if (implementations.isEmpty())
 			return null;
 		implementations.trimToSize();