📄 basemonitor.java
字号:
} } report("-- end --"); } } /** Should only be called if reportOn is true apart from report/Exception(). */ protected void report(String message) { PrintWriter tpw = getTempWriter(); if (tpw != null) tpw.println(message); if (systemStreams != null) systemStreams.stream().printlnWithHeader(message); } protected void reportException(Throwable t) { PrintWriterGetHeader pwgh = null; if (systemStreams != null) pwgh = systemStreams.stream().getHeader(); ErrorStringBuilder esb = new ErrorStringBuilder(pwgh); esb.appendln(t.getMessage()); esb.stackTrace(t); report(esb.get().toString()); } private void addDebugFlags(String flags, boolean set) { if (SanityManager.DEBUG) { if (flags == null) return; StringTokenizer st = new StringTokenizer(flags, ","); for (; st.hasMoreTokens(); ) { String flag = st.nextToken(); if (set) SanityManager.DEBUG_SET(flag); else SanityManager.DEBUG_CLEAR(flag); } } } /** Look for any services in the a properties set and the application property set and then start them. A service is defined by derby.service.name=protocol */ private static final String SERVICE = "derby.service."; public void startServices(Properties properties, boolean bootAll) { if (properties == null) return; for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); if (key.startsWith(SERVICE)) { String name = key.substring(SERVICE.length()); String protocolOrType = properties.getProperty(key); try { if (protocolOrType.equals(Monitor.SERVICE_TYPE_DIRECTORY)) { if (bootAll) // only if automatic booting is required startPersistentService(name, properties, true); } else { bootService((PersistentService) null, protocolOrType, name, (Properties)null, false); } } catch (StandardException se) { // error already in error log, just continue booting // for persistent services, but non-persistent ones // will not have put the error in the log if (!protocolOrType.equals(Monitor.SERVICE_TYPE_DIRECTORY)) reportException(se); } } } } /** Start a peristent service. @see ModuleFactory#startPersistentService @see Monitor#startPersistentService */ public boolean startPersistentService(String name, Properties properties) throws StandardException { return startPersistentService(name, properties, false); } protected boolean startPersistentService(String name, Properties properties, boolean bootTime) throws StandardException { return findProviderAndStartService(name, properties, bootTime); } /** Create a persistent service. @return The module from the service if it was created successfully, null if a service already existed. @exception StandardException An exception was thrown trying to create the service. @see Monitor#createPersistentService */ public Object createPersistentService(String factoryInterface, String name, Properties properties) throws StandardException { PersistentService provider = findProviderForCreate(properties, name); if (provider == null) { throw StandardException.newException(SQLState.PROTOCOL_UNKNOWN, name); } return bootService(provider, factoryInterface, name, properties, true); } /* Removes a PersistentService @param name : Service name to be removed. Note : Currently needed by dropPublisher. But this can be used to remove any PersistentService. */ public void removePersistentService(String name) throws StandardException { PersistentService provider=null; provider = findProviderForCreate(null, name); String serviceName = provider.getCanonicalServiceName(name); boolean removed = provider.removeServiceRoot(serviceName); if (removed == false) throw StandardException.newException(SQLState.SERVICE_DIRECTORY_REMOVE_ERROR,serviceName); } /** Start a non-persistent service. @see Monitor#startNonPersistentService @see ModuleFactory#startNonPersistentService */ public Object startNonPersistentService(String factoryInterface, String serviceName, Properties properties) throws StandardException { return bootService((PersistentService) null, factoryInterface, serviceName, properties, false); } /** Create an implementation set. Look through the properties object for all properties that start with derby.module and add the value into the vector. If no implementations are listed in the properties object then null is returned. */ private Vector getImplementations(Properties moduleList, boolean actualModuleList) { if (moduleList == null) return null; Vector implementations = actualModuleList ? new Vector(moduleList.size()) : new Vector(0,1); // Get my current JDK environment int theJDKId = JVMInfo.JDK_ID; int[] envModuleCount = new int[theJDKId + 1];nextModule: 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; } } // 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; } } } // 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); if (SanityManager.DEBUG && reportOn) { report("Accessing module " + className + " to run initializers at boot time"); } 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]; } 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."); } } } if (implementations.isEmpty()) return null; implementations.trimToSize(); return implementations; } private boolean getPersistentServiceImplementation( Class possibleModule) { if( ! PersistentService.class.isAssignableFrom(possibleModule)) return false; PersistentService ps = (PersistentService) newInstance(possibleModule); if (ps == null) { report("Class " + possibleModule.getName() + " cannot create instance, module ignored."); } else { if (serviceProviders == null) serviceProviders = new Hashtable(3, (float) 1.0); serviceProviders.put(ps.getType(), ps); } return true; } // end of getPersistentServiceImplementation private Vector getDefaultImplementations() { Properties moduleList = getDefaultModuleProperties(); return getImplementations(moduleList, true); } // end of getDefaultImplementations /** * Get the complete set of module properties by * loading in contents of all the org/apache/derby/modules.properties * files. This must be executed in a privileged block otherwise * when running in a security manager environment no properties will * be returned. * @return */ Properties getDefaultModuleProperties() { // SECURITY PERMISSION - IP1 for modules in this jar // or other jars shipped with the Derby release. Properties moduleList = new Properties(); boolean firstList = true; ClassLoader cl = getClass().getClassLoader(); try { Enumeration e = cl == null ? ClassLoader.getSystemResources("org/apache/derby/modules.properties") : cl.getResources("org/apache/derby/modules.properties"); while (e.hasMoreElements()) { URL modulesPropertiesURL = (URL) e.nextElement(); InputStream is = null; try { is = modulesPropertiesURL.openStream(); if( firstList) { moduleList.load( is); firstList = false; } else { // Check for duplicates Properties otherList = new Properties(); otherList.load( is); for( Enumeration newKeys = otherList.keys(); newKeys.hasMoreElements() ;) { String key = (String) newKeys.nextElement(); if( moduleList.contains( key)) // RESOLVE how do we localize messages before we have finished initialization? report( "Ignored duplicate property " + key + " in " + modulesPropertiesURL.toString()); else moduleList.setProperty( key, otherList.getProperty( key)); } } } catch (IOException ioe) { if (SanityManager.DEBUG) report("Can't load implementation list " + modulesPropertiesURL.toString() + ": " + ioe.toString()); } finally { try { if( is != null) is.close(); } catch (IOException ioe2) { } } } } catch (IOException ioe) { if (SanityManager.DEBUG) report("Can't load implementation list: " + ioe.toString()); } if (SanityManager.DEBUG) { if (firstList) report("Default implementation list not found"); } return moduleList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -