📄 basemonitor.java
字号:
serviceLocale = setLocale(properties); properties.put(Property.SERVICE_PROTOCOL, factoryInterface); serviceName = provider.createServiceRoot(serviceName, Boolean.valueOf(properties.getProperty(Property.DELETE_ON_CREATE)).booleanValue()); serviceKey = ProtocolKey.create(factoryInterface, serviceName); } else if (properties != null) { String serverLocaleDescription = properties.getProperty(Property.SERVICE_LOCALE); if ( serverLocaleDescription != null) serviceLocale = staticGetLocaleFromString(serverLocaleDescription); } ts = new TopService(this, serviceKey, provider, serviceLocale); services.addElement(ts); } if (SanityManager.DEBUG) { if (provider != null) { SanityManager.ASSERT(provider.getCanonicalServiceName(serviceName).equals(serviceName), "mismatched canonical names " + provider.getCanonicalServiceName(serviceName) + " != " + serviceName); SanityManager.ASSERT(serviceName.equals(serviceKey.getIdentifier()), "mismatched names " + serviceName + " != " + serviceKey.getIdentifier()); } } if (properties != null) { // these properties must not be stored in the persistent properties, // otherwise moving databases from one directory to another // will not work. Thus they all have a fixed prefix // the root of the data properties.put(PersistentService.ROOT, serviceName); // the type of the service properties.put(PersistentService.TYPE, provider.getType()); } if (SanityManager.DEBUG && reportOn) { dumpProperties("Service Properties: " + serviceKey.toString(), properties); } // push a new context manager if (previousCM == null) { cm = contextService.newContextManager(); contextService.setCurrentContextManager(cm); } sb = new ServiceBootContext(cm); UpdateServiceProperties usProperties; Properties serviceProperties; //while doing restore from backup, we don't want service properties to be //updated until all the files are copied from backup. boolean inRestore = (properties !=null ? properties.getProperty(Property.IN_RESTORE_FROM_BACKUP) != null:false); if ((provider != null) && (properties != null)) { // we need to track to see if the properties have // been updated or not. If the database is not created yet, we don't create the // services.properties file yet. We let the following if (create) statement do //that at the end of the database creation. After that, the changes in // services.properties file will be tracked by UpdateServiceProperties. usProperties = new UpdateServiceProperties(provider, serviceName, properties, !(create || inRestore)); serviceProperties = usProperties; } else { usProperties = null; serviceProperties = properties; } instance = ts.bootModule(create, null, serviceKey, serviceProperties); if (create || inRestore) { // remove all the in-memory properties provider.saveServiceProperties(serviceName, usProperties.getStorageFactory(), BaseMonitor.removeRuntimeProperties(properties), false); usProperties.setServiceBooted(); } } catch (Throwable t) { // ensure that the severity will shutdown the service if ((t instanceof StandardException) && (((StandardException) t).getSeverity() == ExceptionSeverity.DATABASE_SEVERITY)) ; else t = Monitor.exceptionStartingModule(t); if (cm != previousCM) { cm.cleanupOnError(t); } if (ts != null) { ts.shutdown(); synchronized (this) { services.removeElement(ts); } // Service root will only have been created if // ts is non-null. boolean deleteOnError = (properties !=null ? properties.getProperty(Property.DELETE_ROOT_ON_ERROR) !=null:false); if (create || deleteOnError) provider.removeServiceRoot(serviceName); } Throwable nested = ((StandardException) t).getNestedException(); // never hide ThreadDeath if (nested instanceof ThreadDeath) throw (ThreadDeath) t; if (nested instanceof StandardException) throw (StandardException) t; throw (StandardException) t; } finally { if ((previousCM == cm) && (sb != null)) sb.popMe(); if (previousCM == null) contextService.resetCurrentContextManager(cm); } // from this point onwards the service is open for business ts.setTopModule(instance); // // The following yield allows our background threads to // execute their run methods. This is needed due to // bug 4081540 on Solaris. When the bug is fixed we can // remove this yield. Thread.yield(); return instance; } /* ** Methods of com.ibm.db2j.system.System */ /** Return the UUID factory for this system. Returns null if there isn't one. @see com.ibm.db2j.system.System */ public UUIDFactory getUUIDFactory() { return uuidFactory; } /* ** Methods to deal with storing error messages until an InfoStreams is available. */ private PrintWriter tmpWriter; private AccessibleByteArrayOutputStream tmpArray; private boolean dumpedTempWriter; private PrintWriter getTempWriter() { if (tmpWriter == null && !dumpedTempWriter) { tmpArray = new AccessibleByteArrayOutputStream(); tmpWriter = new PrintWriter(tmpArray); } return tmpWriter; } private void dumpTempWriter(boolean bothPlaces) { if (tmpWriter == null) return; tmpWriter.flush(); BufferedReader lnr = new BufferedReader( new InputStreamReader( new ByteArrayInputStream(tmpArray.getInternalByteArray()))); try { String s; while ((s = lnr.readLine()) != null) { if (systemStreams != null) systemStreams.stream().printlnWithHeader(s); if ((systemStreams == null) || bothPlaces) logging.println(s); } } catch (IOException ioe) { } if ((systemStreams == null) || bothPlaces) logging.flush(); tmpWriter = null; tmpArray = null; dumpedTempWriter = true; logging = null; } /** If the module implements ModuleSupportable then call its canSupport() method to see if it can or should run in this setup. If it doesn't then it can always run. */ static boolean canSupport(Object instance, Properties properties) { if (instance instanceof ModuleSupportable) { // see if the instance can support the properties if (!((ModuleSupportable) instance).canSupport(properties)) return false; } return true; } /** Boot a module. If the module implements ModuleControl then its boot() method is called. Otherwise all the boot code is assumed to take place in its constructor. */ static void boot(Object module, boolean create, Properties properties) throws StandardException { if (module instanceof ModuleControl) ((ModuleControl) module).boot(create, properties); } /* ** Locale handling */ private static Locale staticGetLocaleFromString(String localeDescription) throws StandardException { // Check String is of expected format // even though country should not be optional // some jvm's support this, so go with the flow. // xx[_YY[_variant]] int len = localeDescription.length(); boolean isOk = (len == 2) || (len == 5) || (len > 6); // must have underscores at position 2 if (isOk && (len != 2)) isOk = localeDescription.charAt(2) == '_'; // must have underscores at position 2 if (isOk && (len > 5)) isOk = localeDescription.charAt(5) == '_'; if (!isOk) throw StandardException.newException(SQLState.INVALID_LOCALE_DESCRIPTION, localeDescription); String language = localeDescription.substring(0, 2); String country = len == 2 ? "" : localeDescription.substring(3, 5); if (len < 6) { return new Locale(language, country); } String variant = (len > 6) ? localeDescription.substring(6, len) : null; return new Locale(language, country, variant); } private static Locale setLocale(Properties properties) throws StandardException { String userDefinedLocale = properties.getProperty(Attribute.TERRITORY); Locale locale; if (userDefinedLocale == null) locale = Locale.getDefault(); else { // validate the passed in string locale = staticGetLocaleFromString(userDefinedLocale); } properties.put(Property.SERVICE_LOCALE, locale.toString()); return locale; } /* ** BundleFinder */ //private Hashtable localeBundles; /** Get the locale from the ContextManager and then find the bundle based upon that locale. */ public ResourceBundle getBundle(String messageId) { ContextManager cm; try { cm = ContextService.getFactory().getCurrentContextManager(); } catch (ShutdownException se) { cm = null; } if (cm != null) { return MessageService.getBundleForLocale(cm.getMessageLocale(), messageId); } return null; } public Thread getDaemonThread(Runnable task, String name, boolean setMinPriority) { Thread t = new Thread(daemonGroup, task, "derby.".concat(name)); t.setDaemon(true); if (setMinPriority) { t.setPriority(Thread.MIN_PRIORITY); } return t; } public void setThreadPriority(int priority) { Thread t = Thread.currentThread(); if (t.getThreadGroup() == daemonGroup) { t.setPriority(priority); } } /** Initialize the monitor wrt the current environemnt. Returns false if the monitor cannot be initialized, true otherwise. */ abstract boolean initialize(boolean lite); class ProviderEnumeration implements Enumeration { private Enumeration serviceProvidersKeys = (serviceProviders == null) ? null : serviceProviders.keys(); private Properties startParams; private Enumeration paramEnumeration; private boolean enumeratedDirectoryProvider; private PersistentService storageFactoryPersistentService; ProviderEnumeration( Properties startParams) { this.startParams = startParams; if( startParams != null) paramEnumeration = startParams.keys(); } public Object nextElement() throws NoSuchElementException { if( serviceProvidersKeys != null && serviceProvidersKeys.hasMoreElements()) return serviceProviders.get( serviceProvidersKeys.nextElement()); getNextStorageFactory(); Object ret = storageFactoryPersistentService; storageFactoryPersistentService = null; return ret; } private void getNextStorageFactory() { if( storageFactoryPersistentService != null) return; if( paramEnumeration != null) { while( paramEnumeration.hasMoreElements()) { String prop = (String) paramEnumeration.nextElement(); if( prop.startsWith( Property.SUB_SUB_PROTOCOL_PREFIX)) { try { String storageFactoryClassName = (String) startParams.get( prop); if( storageFactoryClassName != null) { storageFactoryPersistentService = getPersistentService( (String) startParams.get( prop), prop.substring( Property.SUB_SUB_PROTOCOL_PREFIX.length())); if( storageFactoryPersistentService != null) return; } } catch( StandardException se){}; } } } if( ! enumeratedDirectoryProvider) { try { storageFactoryPersistentService = getPersistentService( getStorageFactoryClassName( null, PersistentService.DIRECTORY), PersistentService.DIRECTORY); } catch( StandardException se){ storageFactoryPersistentService = null; } enumeratedDirectoryProvider = true; } } // end of getNextStorageFactory public boolean hasMoreElements() { if( serviceProvidersKeys != null && serviceProvidersKeys.hasMoreElements()) return true; getNextStorageFactory(); return storageFactoryPersistentService != null; } } // end of class ProviderEnumeration} // end of class BaseMonitorclass AntiGC implements Runnable { boolean goAway; private Object keep1; AntiGC(Object a) { keep1 = a; } public void run() { goAway = false; while (true) { synchronized (this) { if (goAway) return; try { wait(); } catch (InterruptedException ie) { } } } }} // end of class AntiGC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -