📄 basemonitor.java
字号:
} /* ** Class methods */ /** Return a property set that has the runtime properties removed. */ protected static Properties removeRuntimeProperties(Properties properties) { Properties subset = new Properties(); for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); if (key.startsWith(Property.PROPERTY_RUNTIME_PREFIX)) continue; subset.put(key, properties.get(key)); } return subset; } /** Get InputStream for application properties file Returns nul if it does not exist. */ abstract InputStream applicationPropertiesStream() throws IOException; /** */ protected Properties readApplicationProperties() { InputStream is = null; try { // SECURITY PERMISSION - OP3 is = applicationPropertiesStream(); if (is == null) return null; Properties properties = new Properties(); // Trim off excess whitespace from properties file, if any, // and then load the properties into 'properties'. org.apache.derby.iapi.util.PropertyUtil.loadWithTrimmedValues( new BufferedInputStream(is), properties); return properties; } catch (SecurityException se) { return null; } catch (IOException ioe) { report(ioe.toString() + " (" + Property.PROPERTIES_FILE + ")"); reportException(ioe); return null; }finally { try { if (is != null) { is.close(); is = null; } } catch (IOException e) { } } } /* ** Methods related to service providers. ** ** A service provider implements PersistentService and ** abstracts out: ** ** Finding all serivces that should be started at boot time. ** Finding the service.properties file for a service ** Creating a service's root. ** ** A monitor can have any number of service providers installed, ** any module that implements PersistentService is treated specially ** and stored only in the serviceProviders hashtable, indexed by ** its getType() method. ** ** Once all the implementations have loaded the service providers ** are booted. If they fail to boot then they aare discarded. ** E.g. a marimba service provider may detect that its not in ** a channel so it refuses to boot. */ /** Boot all the service providers, ie. any module that implemented PersistentService. Upon entry to this call is the hashtable has PersistentService objects that have been created but not booted. */ protected void bootServiceProviders() { if (serviceProviders == null) { return; } for (Enumeration e = serviceProviders.keys(); e.hasMoreElements(); ) { String serviceType = (String) e.nextElement(); Object provider = serviceProviders.get(serviceType); // see if this provider can live in this environment if (!BaseMonitor.canSupport(provider, (Properties) null)) { serviceProviders.remove(serviceType); continue; } } } /** Boot all persistent services that can be located at run time. <BR> This method enumerates through all the service providers that are active and calls bootPersistentServices(PersistentService) to boot all the services that that provider knows about. */ protected void bootPersistentServices() { for (Enumeration e = new ProviderEnumeration( applicationProperties); ; ) { PersistentService provider = (PersistentService) e.nextElement(); bootProviderServices(provider); } } /** Boot all persistent services that can be located by a single service provider <BR> This method enumerates through all the service providers that are active and calls bootPersistentServices(PersistentService) to boot all the services that that provider knows about. */ protected void bootProviderServices(PersistentService provider) { if (SanityManager.DEBUG && reportOn) { report("Booting persistent services for provider: " + provider.getType()); } for (Enumeration e = provider.getBootTimeServices(); (e != null) && e.hasMoreElements(); ) { String serviceName = (String) e.nextElement(); Properties serviceProperties; try { serviceProperties = provider.getServiceProperties(serviceName, null); } catch (StandardException mse) { report("Failed to load service properties, name: " + serviceName + ", type = " + provider.getType()); reportException(mse); continue; } // see if this service does not want to be auto-booted. if (Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) continue; try { startProviderService(provider, serviceName, serviceProperties); } catch (StandardException mse) { report("Service failed to boot, name: " + serviceName + ", type = " + provider.getType()); reportException(mse); continue; } } } /** Find a provider and start a service. */ protected boolean findProviderAndStartService(String name, Properties properties, boolean bootTime) throws StandardException { PersistentService actualProvider = null; Properties serviceProperties = null; String serviceName = null; // see if the name already includes a service type int colon = name.indexOf(':'); if (colon != -1) { actualProvider = findProviderFromName(properties, name, colon); // if null is returned here then its a sub-sub protocol/provider // that we don't understand. Attempt to load it as an untyped name. // If we have a protool // that we do understand and we can't open the service we will // throw an exception if (actualProvider != null) { serviceName = actualProvider.getCanonicalServiceName(name); if (serviceName == null) return true; // we understand the type, but the service does not exist serviceProperties = actualProvider.getServiceProperties(serviceName, properties); if (serviceProperties == null) return true; // we understand the type, but the service does not exist // see if this service does not want to be auto-booted. if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) return true; startProviderService(actualProvider, serviceName, serviceProperties); return true; // we understand the type } } StandardException savedMse = null; for (Enumeration e = new ProviderEnumeration( properties); e.hasMoreElements(); ) { PersistentService provider = (PersistentService) e.nextElement(); String sn = provider.getCanonicalServiceName(name); if (sn == null) continue; Properties p = null; try { p = provider.getServiceProperties(sn, properties); // service does not exist. if (p == null) continue; } catch (StandardException mse) { savedMse = mse; } // yes we can attempt to boot this service if (actualProvider == null) { actualProvider = provider; serviceName = sn; serviceProperties = p; continue; } // we have an ambigious service name throw StandardException.newException(SQLState.AMBIGIOUS_PROTOCOL, name); } // no such service, if this was a name with no type, ie just name instead of type:name. // the monitor claims to always understand these. if (actualProvider == null) return colon == -1; if (savedMse != null) throw savedMse; // see if this service does not want to be auto-booted. if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) return true; startProviderService(actualProvider, serviceName, serviceProperties); return true; } protected PersistentService findProvider() throws StandardException { // This is a hack. This is called when we want to re-write // services.properties, and need the provider for the database // directory. return findProviderForCreate(null, ""); } protected PersistentService findProviderForCreate(Properties startParams, String name) throws StandardException { // RESOLVE - hard code creating databases in directories for now. return (PersistentService) findProviderFromName( startParams, name, name.indexOf(':')); } /** Find the service provider from a name that includes a service type, ie. is of the form 'type:name'. If type is less than 3 chanacters then it is assumed to be of type directory, i.e. a windows driver letter. */ private PersistentService findProviderFromName(Properties startParams, String name, int colon) throws StandardException { // empty type, treat as a unknown protocol if (colon == 0) return null; String serviceType; if (colon < 2) { // assume it's a windows path (a:/foo etc.) and set the type to be DIRECTORY serviceType = PersistentService.DIRECTORY; } else { serviceType = name.substring(0, colon); } return getServiceProvider( startParams, serviceType); } public PersistentService getServiceProvider( Properties startParams, String subSubProtocol) throws StandardException { if( subSubProtocol == null) return null; if( serviceProviders != null) { PersistentService ps = (PersistentService) serviceProviders.get( subSubProtocol); if( ps != null) return ps; } return getPersistentService( startParams, subSubProtocol); } // end of getServiceProvider private PersistentService getPersistentService( Properties properties, String subSubProtocol) throws StandardException { String className = getStorageFactoryClassName( properties, subSubProtocol); return getPersistentService( className, subSubProtocol); } private PersistentService getPersistentService( final String className, String subSubProtocol) throws StandardException { if( className == null) return null; Class storageFactoryClass = null; try { storageFactoryClass = Class.forName( className); } catch (Throwable e) { throw StandardException.newException( SQLState.INSTANTIATE_STORAGE_FACTORY_ERROR, e, subSubProtocol, className); } return new PersistentServiceImpl( subSubProtocol, storageFactoryClass); } // end of getPersistentService private String getStorageFactoryClassName( Properties properties, String subSubProtocol) { String propertyName = Property.SUB_SUB_PROTOCOL_PREFIX + subSubProtocol; String className = null; if( properties != null) className = properties.getProperty( propertyName); if( className == null) className = PropertyUtil.getSystemProperty( propertyName); if( className != null) return className; return (String) storageFactories.get( subSubProtocol); } // end of getStorageFactoryClassName private static final HashMap storageFactories = new HashMap(); static { String dirStorageFactoryClass; if( JVMInfo.JDK_ID >= JVMInfo.J2SE_14) dirStorageFactoryClass = "org.apache.derby.impl.io.DirStorageFactory4"; else dirStorageFactoryClass = "org.apache.derby.impl.io.DirStorageFactory"; storageFactories.put( PersistentService.DIRECTORY, dirStorageFactoryClass); storageFactories.put( PersistentService.CLASSPATH, "org.apache.derby.impl.io.CPStorageFactory"); storageFactories.put( PersistentService.JAR, "org.apache.derby.impl.io.JarStorageFactory"); storageFactories.put( PersistentService.HTTP, "org.apache.derby.impl.io.URLStorageFactory"); storageFactories.put( PersistentService.HTTPS, "org.apache.derby.impl.io.URLStorageFactory"); } /** Boot a service under the control of the provider */ protected void startProviderService(PersistentService provider, String serviceName, Properties serviceProperties) throws StandardException { String protocol = serviceProperties.getProperty(Property.SERVICE_PROTOCOL); if (protocol == null) { throw StandardException.newException(SQLState.PROPERTY_MISSING, Property.SERVICE_PROTOCOL); } bootService(provider, protocol, serviceName, serviceProperties, false); } /** Boot (start or create) a service (persistent or non-persistent). */ protected Object bootService(PersistentService provider, String factoryInterface, String serviceName, Properties properties, boolean create) throws StandardException { //reget the canonical service name in case if it was recreated //after we got service name.(like in case of restoring from backup). if(provider != null) serviceName = provider.getCanonicalServiceName(serviceName); ProtocolKey serviceKey = ProtocolKey.create(factoryInterface, serviceName); if (SanityManager.DEBUG && reportOn) { report("Booting service " + serviceKey + " create = " + create); } ContextManager previousCM = contextService.getCurrentContextManager(); ContextManager cm = previousCM; Object instance; TopService ts = null; Context sb = null; try { synchronized (this) { if (inShutdown) { throw StandardException.newException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN); } for (int i = 1; i < services.size(); i++) { TopService ts2 = (TopService) services.elementAt(i); if (ts2.isPotentialService(serviceKey)) { // if the service already exists then just return null return null; } } Locale serviceLocale = null; if (create) { // always wrap the property set in an outer set. // this ensures that any random attributes from // a JDBC URL are not written into the service.properties // file (e.g. like user and password :-) properties = new Properties(properties);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -