1 21 22 package org.apache.derby.impl.services.monitor; 23 24 import org.apache.derby.iapi.services.monitor.Monitor; 25 import org.apache.derby.iapi.services.monitor.ModuleFactory; 26 import org.apache.derby.iapi.services.monitor.ModuleControl; 27 import org.apache.derby.iapi.services.monitor.ModuleSupportable; 28 29 import org.apache.derby.iapi.services.monitor.PersistentService; 30 31 import org.apache.derby.iapi.services.io.FormatIdUtil; 32 import org.apache.derby.iapi.services.io.RegisteredFormatIds; 33 import org.apache.derby.iapi.services.io.StoredFormatIds; 34 35 import org.apache.derby.iapi.services.context.ContextManager; 36 import org.apache.derby.iapi.services.context.Context; 37 import org.apache.derby.iapi.services.context.ContextService; 38 import org.apache.derby.iapi.services.context.ShutdownException; 39 40 import org.apache.derby.iapi.services.stream.InfoStreams; 41 import org.apache.derby.iapi.services.stream.PrintWriterGetHeader; 42 43 import org.apache.derby.iapi.services.sanity.SanityManager; 44 import org.apache.derby.iapi.error.StandardException; 45 import org.apache.derby.iapi.services.uuid.UUIDFactory; 46 import org.apache.derby.iapi.services.timer.TimerFactory; 47 import org.apache.derby.iapi.reference.Property; 48 import org.apache.derby.iapi.reference.SQLState; 49 import org.apache.derby.iapi.reference.Attribute; 50 import org.apache.derby.iapi.services.property.PropertyUtil; 51 52 import org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream; 53 import org.apache.derby.iapi.services.loader.ClassInfo; 54 import org.apache.derby.iapi.services.loader.InstanceGetter; 55 import org.apache.derby.iapi.services.io.FormatableInstanceGetter; 56 import org.apache.derby.iapi.error.ExceptionSeverity; 57 58 import org.apache.derby.io.StorageFactory; 59 60 import org.apache.derby.iapi.services.context.ErrorStringBuilder; 61 62 import org.apache.derby.iapi.services.info.JVMInfo; 63 import org.apache.derby.iapi.services.i18n.BundleFinder; 64 import org.apache.derby.iapi.services.i18n.MessageService; 65 66 import org.apache.derby.impl.services.monitor.StorageFactoryService; 67 68 import java.io.IOException ; 69 import java.io.InputStream ; 70 import java.io.StringWriter ; 71 import java.io.BufferedInputStream ; 72 import java.io.PrintWriter ; 73 import java.io.BufferedReader ; 74 import java.io.InputStreamReader ; 75 import java.io.ByteArrayInputStream ; 76 import java.io.PrintStream ; 77 78 import java.util.Hashtable ; 79 import java.util.HashMap ; 80 import java.util.Properties ; 81 import java.util.Enumeration ; 82 import java.util.StringTokenizer ; 83 import java.util.Vector ; 84 import java.util.Locale ; 85 import java.util.ResourceBundle ; 86 import java.util.NoSuchElementException ; 87 88 import java.lang.reflect.Method ; 89 import java.lang.reflect.Modifier ; 90 import java.lang.reflect.InvocationTargetException ; 91 92 import java.security.AccessController ; 93 import java.security.PrivilegedExceptionAction ; 94 import java.security.PrivilegedActionException ; 95 96 import java.net.URL ; 97 98 103 104 abstract class BaseMonitor 105 implements ModuleFactory, BundleFinder { 106 107 108 109 112 Hashtable serviceProviders; 113 114 117 Vector [] implementationSets; 118 119 private Vector services; 121 Properties bootProperties; Properties applicationProperties; 123 124 boolean inShutdown; 125 126 private InfoStreams systemStreams; 128 private ContextService contextService; 129 private UUIDFactory uuidFactory; 130 private TimerFactory timerFactory; 131 132 boolean reportOn; 133 private PrintStream logging; 134 135 ThreadGroup daemonGroup; 136 137 AntiGC dontGC; 139 140 144 private InstanceGetter[] rc2; 145 147 148 BaseMonitor() { 149 super(); 150 151 services = new Vector (0, 1); 152 services.addElement(new TopService(this)); } 154 155 156 157 public InfoStreams getSystemStreams() { 158 return systemStreams; 159 } 160 161 public void shutdown() { 162 163 synchronized (this) { 165 if (inShutdown) 166 return; 167 inShutdown = true; 168 } 169 170 if (SanityManager.DEBUG && reportOn) { 171 report("Shutdown request"); 172 } 173 174 contextService.notifyAllActiveThreads((Context) null); 176 177 for (;;) { 178 179 TopService ts; 180 int position; 181 synchronized (this) { 182 position = services.size() - 1; 183 if (position == 0) 184 break; 185 186 ts = (TopService) services.elementAt(position); 187 } 188 189 ContextManager cm = contextService.newContextManager(); 191 try { 192 cm.popContext(); 194 195 contextService.setCurrentContextManager(cm); 196 197 198 shutdown(ts.getService()); 199 200 } finally { 201 contextService.resetCurrentContextManager(cm); 202 } 203 204 } 205 ((TopService) services.elementAt(0)).shutdown(); 206 207 synchronized (dontGC) { 208 209 dontGC.goAway = true; 210 dontGC.notifyAll(); 211 } 212 213 ContextService.stop(); 214 Monitor.clearMonitor(); 215 } 216 217 221 public void shutdown(Object serviceModule) { 222 if (serviceModule == null) 223 return; 224 225 TopService ts = findTopService(serviceModule); 226 if (ts == null) 227 return; 228 229 boolean removeService = true; 231 try { 232 removeService = ts.shutdown(); 233 } finally { 234 synchronized (this) { 235 if (removeService) { 236 boolean found = services.removeElement(ts); 237 if (SanityManager.DEBUG) { 238 SanityManager.ASSERT(found, "service was not found " + serviceModule); 239 } 240 } 241 } 242 } 243 } 244 245 protected final void runWithState(Properties properties, PrintStream log) { 246 247 bootProperties = properties; 248 logging = log; 249 250 if (!initialize(false)) 252 return; 253 254 if (!Monitor.setMonitor(this)) 257 return; 258 259 Object msgService = MessageService.setFinder(this); 260 261 266 Object [] keepItems = new Object [3]; 267 keepItems[0] = this; 268 keepItems[1] = new Monitor(); 269 keepItems[2] = msgService; 270 dontGC = new AntiGC(keepItems); 271 272 Thread dontGCthread = getDaemonThread(dontGC, "antiGC", true); 273 dontGCthread.start(); 274 275 if (SanityManager.DEBUG) { 276 reportOn = Boolean.valueOf(PropertyUtil.getSystemProperty("derby.monitor.verbose")).booleanValue(); 277 } 278 279 applicationProperties = readApplicationProperties(); 281 282 Properties systemProperties = null; 285 286 if (SanityManager.DEBUG) { 287 try { 296 systemProperties = System.getProperties(); 297 } catch (SecurityException se) { 298 } 299 } 300 301 Vector bootImplementations = getImplementations(bootProperties, false); 302 303 Vector systemImplementations = null; 304 Vector applicationImplementations = null; 305 306 if (true || SanityManager.DEBUG) { 309 systemImplementations = getImplementations(systemProperties, false); 311 applicationImplementations = getImplementations(applicationProperties, false); 312 } 313 314 Vector defaultImplementations = getDefaultImplementations(); 315 316 int implementationCount = 0; 317 if (bootImplementations != null) 318 implementationCount++; 319 320 if (true || SanityManager.DEBUG) { 322 if (systemImplementations != null) 324 implementationCount++; 325 if (applicationImplementations != null) 326 implementationCount++; 327 } 328 329 if (defaultImplementations != null) 330 implementationCount++; 331 implementationSets = new Vector [implementationCount]; 332 333 implementationCount = 0; 334 if (bootImplementations != null) 335 implementationSets[implementationCount++] = bootImplementations; 336 337 if (true || SanityManager.DEBUG) { 338 if (systemImplementations != null) 340 implementationSets[implementationCount++] = systemImplementations; 341 if (applicationImplementations != null) 342 implementationSets[implementationCount++] = applicationImplementations; 343 } 344 345 if (defaultImplementations != null) 346 implementationSets[implementationCount++] = defaultImplementations; 347 348 349 if (SanityManager.DEBUG) { 350 if (applicationProperties != null) { 352 addDebugFlags(applicationProperties.getProperty(Monitor.DEBUG_FALSE), false); 353 addDebugFlags(applicationProperties.getProperty(Monitor.DEBUG_TRUE), true); 354 } 355 356 addDebugFlags(PropertyUtil.getSystemProperty(Monitor.DEBUG_FALSE), false); 357 addDebugFlags(PropertyUtil.getSystemProperty(Monitor.DEBUG_TRUE), true); 358 } 359 360 try { 361 systemStreams = (InfoStreams) Monitor.startSystemModule("org.apache.derby.iapi.services.stream.InfoStreams"); 362 363 if (SanityManager.DEBUG) { 364 SanityManager.SET_DEBUG_STREAM(systemStreams.stream().getPrintWriter()); 365 } 366 367 contextService = new ContextService(); 368 369 uuidFactory = (UUIDFactory) Monitor.startSystemModule("org.apache.derby.iapi.services.uuid.UUIDFactory"); 370 371 timerFactory = (TimerFactory)Monitor.startSystemModule("org.apache.derby.iapi.services.timer.TimerFactory"); 372 } catch (StandardException se) { 373 374 reportException(se); 376 dumpTempWriter(true); 378 379 return; 380 } 381 382 dumpTempWriter(false); 385 386 if (SanityManager.DEBUG && reportOn) { 387 dumpProperties("-- Boot Properties --", bootProperties); 388 dumpProperties("-- System Properties --", systemProperties); 389 dumpProperties("-- Application Properties --", applicationProperties); 390 } 391 392 bootServiceProviders(); 394 395 boolean bootAll = Boolean.valueOf(PropertyUtil.getSystemProperty(Property.BOOT_ALL)).booleanValue(); 397 398 399 startServices(bootProperties, bootAll); 400 startServices(systemProperties, bootAll); 401 startServices(applicationProperties, bootAll); 402 403 if (bootAll) bootPersistentServices( ); 405 } 406 407 public Object findService(String factoryInterface, String serviceName) { 408 409 if (serviceName == null) 410 return null; 411 412 ProtocolKey key; 413 414 try { 415 key = ProtocolKey.create(factoryInterface, serviceName); 416 } catch (StandardException se) { 417 return null; 418 } 419 420 TopService myts = null; 421 synchronized (this) { 422 for (int i = 1; i < services.size(); i++) { 423 TopService ts = (TopService) services.elementAt(i); 424 if (ts.isPotentialService(key)) { 425 myts = ts; 426 break; 427 } 428 } 429 } 430 431 if (myts != null) { 434 if (myts.isActiveService(key)) 435 return myts.getService(); 436 } 437 438 return null; 439 } 440 441 public Locale getLocale(Object serviceModule) { 442 443 TopService ts = findTopService(serviceModule); 444 445 if (ts == null) 446 return null; 447 448 return ts.serviceLocale; 449 450 } 451 452 public Locale getLocaleFromString(String localeDescription) 453 throws StandardException { 454 return staticGetLocaleFromString(localeDescription); 455 } 456 457 460 public String getServiceName(Object serviceModule) { 461 462 TopService ts = findTopService(serviceModule); 463 464 if (ts == null) 465 return null; 466 467 return ts.getServiceType().getUserServiceName(ts.getKey().getIdentifier()); 468 } 469 470 475 public Locale setLocale(Object serviceModule, String userDefinedLocale) 476 throws StandardException { 477 478 TopService ts = findTopService(serviceModule); 479 480 if (ts == null) 481 return null; 482 483 PersistentService provider = ts.getServiceType(); 484 if (provider == null) 485 return null; 486 487 String serviceName = ts.getKey().getIdentifier(); 488 489 Properties properties = provider.getServiceProperties(serviceName, (Properties ) null); 490 491 properties = new UpdateServiceProperties(provider, serviceName, properties, true); 492 493 return setLocale(properties, userDefinedLocale); 494 495 } 496 497 503 public Locale setLocale(Properties serviceProperties, String userDefinedLocale) 504 throws StandardException { 505 506 Locale locale = staticGetLocaleFromString(userDefinedLocale); 507 508 serviceProperties.put(Property.SERVICE_LOCALE, locale.toString()); 510 511 return locale; 512 } 513 514 518 public PersistentService getServiceType(Object serviceModule) { 519 TopService ts = findTopService(serviceModule); 520 521 if (ts == null) 522 return null; 523 524 return ts.getServiceType(); 525 } 526 527 528 535 public Object startModule(boolean create, Object serviceModule, String factoryInterface, 536 String identifier, Properties properties) throws StandardException { 537 538 539 ProtocolKey key = ProtocolKey.create(factoryInterface, identifier); 540 541 TopService ts = findTopService(serviceModule); 542 543 Object instance = ts.bootModule(create, serviceModule, key, properties); 544 545 if (instance == null) 546 throw Monitor.missingImplementation(factoryInterface); 547 548 return instance; 549 } 550 551 private synchronized TopService findTopService(Object serviceModule) { 552 553 if (serviceModule == null) 554 return (TopService) services.elementAt(0); 555 556 for (int i = 1; i < services.size(); i++) { 557 TopService ts = (TopService) services.elementAt(i); 558 if (ts.inService(serviceModule)) 559 return ts; 560 } 561 562 return null; 563 } 564 565 public Object findModule(Object serviceModule, String factoryInterface, String identifier) 566 { 567 568 ProtocolKey key; 569 570 try { 571 key = ProtocolKey.create(factoryInterface, identifier); 572 } catch (StandardException se) { 573 return null; 574 } 575 576 TopService ts = findTopService(serviceModule); 577 if (ts == null) 578 return null; 579 580 return ts.findModule(key, true, null); 581 } 582 583 584 595 public InstanceGetter classFromIdentifier(int fmtId) 596 throws StandardException { 597 598 String className; 599 int off; 600 InstanceGetter[] iga; 601 InstanceGetter ig; 602 603 try { 604 605 off = fmtId - StoredFormatIds.MIN_TWO_BYTE_FORMAT_ID; 606 iga = rc2; 607 if (iga == null) { 608 iga = rc2 = new InstanceGetter[RegisteredFormatIds.TwoByte.length]; 609 } 610 611 ig = iga[off]; 612 if (ig != null) { 613 return ig; 614 } 615 className = RegisteredFormatIds.TwoByte[off]; 616 617 } catch (ArrayIndexOutOfBoundsException aioobe) { 618 className = null; 619 iga = null; 620 off = 0; 621 } 622 623 if (className != null) { 624 625 Throwable t; 626 try { 627 Class clazz = Class.forName(className); 628 629 if (FormatableInstanceGetter.class.isAssignableFrom(clazz)) { 631 FormatableInstanceGetter tfig = (FormatableInstanceGetter) clazz.newInstance(); 632 tfig.setFormatId(fmtId); 633 return iga[off] = tfig; 634 } 635 636 return iga[off] = new ClassInfo(clazz); 637 638 } catch (ClassNotFoundException cnfe) { 639 t = cnfe; 640 } catch (IllegalAccessException iae) { 641 t = iae; 642 } catch (InstantiationException ie) { 643 t = ie; 644 } catch (LinkageError le) { 645 t = le; 646 } 647 throw StandardException.newException(SQLState.REGISTERED_CLASS_LINAKGE_ERROR, 648 t, FormatIdUtil.formatIdToString(fmtId), className); 649 } 650 651 throw StandardException.newException(SQLState.REGISTERED_CLASS_NONE, FormatIdUtil.formatIdToString(fmtId)); 652 } 653 654 655 661 public Object newInstanceFromIdentifier(int identifier) 662 throws StandardException { 663 664 InstanceGetter ci = classFromIdentifier(identifier); 665 666 Throwable t; 667 try { 668 Object result = ci.getNewInstance(); 669 686 return result; 687 } 688 catch (InstantiationException ie) { 689 t = ie; 690 } 691 catch (IllegalAccessException iae) { 692 t = iae; 693 } 694 catch (InvocationTargetException ite) { 695 t = ite; 696 } 697 catch (LinkageError le) { 698 t = le; 699 } 700 throw StandardException.newException(SQLState.REGISTERED_CLASS_INSTANCE_ERROR, 701 t, new Integer (identifier), "XX" ); 702 } 703 704 private Boolean exceptionTrace; 705 706 714 715 protected Object loadInstance(Class factoryInterface, Properties properties) { 716 717 Object instance = null; 718 719 Vector localImplementations = getImplementations(properties, false); 720 if (localImplementations != null) { 721 instance = loadInstance(localImplementations, factoryInterface, properties); 722 } 723 724 for (int i = 0; i < implementationSets.length; i++) { 725 instance = loadInstance(implementationSets[i], factoryInterface, properties); 726 if (instance != null) 727 break; 728 } 729 730 return instance; 731 } 732 733 734 private Object loadInstance(Vector implementations, Class factoryInterface, Properties properties) { 735 736 for (int index = 0; true; index++) { 737 738 index = findImplementation(implementations, index, factoryInterface); 740 if (index < 0) 741 return null; 742 743 Object instance = newInstance((Class ) implementations.elementAt(index)); 745 746 if (BaseMonitor.canSupport(instance, properties)) 747 return instance; 748 } 749 } 750 751 752 757 private static int findImplementation(Vector implementations, int startIndex, Class factoryInterface) { 758 759 for (int i = startIndex; i < implementations.size(); i++) { 760 761 Class factoryClass = (Class ) implementations.elementAt(i); 763 if (!factoryInterface.isAssignableFrom(factoryClass)) { 764 continue; 765 } 766 767 return i; 768 } 774 775 return -1; 776 } 777 778 780 private Object newInstance(String className) { 781 782 try { 783 784 Class factoryClass = Class.forName(className); 785 return factoryClass.newInstance(); 786 } 787 catch (ClassNotFoundException e) { 788 report(className + " " + e.toString()); 789 } 790 catch (InstantiationException e) { 791 report(className + " " + e.toString()); 792 } 793 catch (IllegalAccessException e) { 794 report(className + " " + e.toString()); 795 } 796 catch (LinkageError le) { 797 report(className + " " + le.toString()); 798 reportException(le); 799 } 800 801 return null; 802 } 803 805 private Object newInstance(Class classObject) { 806 807 try { 808 return classObject.newInstance(); 809 } 810 catch (InstantiationException e) { 811 report(classObject.getName() + " " + e.toString()); 812 } 813 catch (IllegalAccessException e) { 814 report(classObject.getName() + " " + e.toString()); 815 } 816 catch (LinkageError le) { 817 report(classObject.getName() + " " + le.toString()); 818 reportException(le); 819 } 820 821 return null; 822 } 823 824 public Properties getApplicationProperties() { 825 return applicationProperties; 826 } 827 828 837 public String [] getServiceList(String protocol) { 838 839 TopService ts; 840 841 synchronized (this) { 842 int count = 0; 843 844 for (int i = 1; i < services.size(); i++) { 846 ts = (TopService) services.elementAt(i); 847 if (ts.isActiveService()) { 848 if (ts.getKey().getFactoryInterface().getName().equals(protocol)) 849 count++; 850 } 851 } 852 853 String [] list = new String [count]; 855 if (count != 0) { 856 int j = 0; 857 for (int i = 1; i < services.size(); i++) { 858 ts = (TopService) services.elementAt(i); 859 if (ts.isActiveService()) { 860 if (ts.getKey().getFactoryInterface().getName().equals(protocol)) { 861 list[j++] = ts.getServiceType().getUserServiceName(ts.getKey().getIdentifier()); 862 if (j == count) 863 break; 864 } 865 } 866 } 867 } 868 return list; 869 } 870 } 871 872 875 876 877 void dumpProperties(String title, Properties props) { 878 if (SanityManager.DEBUG) { 879 report(title); 881 if (props != null) { 882 for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { 883 String key = (String ) e.nextElement(); 884 report(key + "=" + props.getProperty(key)); 886 } 887 } 888 report("-- end --"); 889 } 890 891 } 892 893 894 898 protected void report(String message) { 899 900 PrintWriter tpw = getTempWriter(); 901 902 if (tpw != null) 903 tpw.println(message); 904 905 if (systemStreams != null) 906 systemStreams.stream().printlnWithHeader(message); 907 } 908 909 protected void reportException(Throwable t) { 910 911 912 PrintWriterGetHeader pwgh = null; 913 if (systemStreams != null) 914 pwgh = systemStreams.stream().getHeader(); 915 916 ErrorStringBuilder esb = new ErrorStringBuilder(pwgh); 917 918 esb.appendln(t.getMessage()); 919 esb.stackTrace(t); 920 921 report(esb.get().toString()); 922 } 923 924 private void addDebugFlags(String flags, boolean set) { 925 if (SanityManager.DEBUG) { 926 if (flags == null) 927 return; 928 929 StringTokenizer st = new StringTokenizer (flags, ","); 930 for (; st.hasMoreTokens(); ) { 931 String flag = st.nextToken(); 932 933 if (set) 934 SanityManager.DEBUG_SET(flag); 935 else 936 SanityManager.DEBUG_CLEAR(flag); 937 } 938 } 939 } 940 941 947 private static final String SERVICE = "derby.service."; 948 949 public void startServices(Properties properties, boolean bootAll) { 950 951 if (properties == null) 952 return; 953 954 for (Enumeration e = properties.propertyNames(); e.hasMoreElements(); ) { 955 956 String key = (String ) e.nextElement(); 957 if (key.startsWith(SERVICE)) { 958 String name = key.substring(SERVICE.length()); 959 960 String protocolOrType = properties.getProperty(key); 961 962 try { 963 if (protocolOrType.equals(Monitor.SERVICE_TYPE_DIRECTORY)) { 964 if (bootAll) findProviderAndStartService(name, properties, true); 966 } else { 967 bootService((PersistentService) null, 968 protocolOrType, name, (Properties )null, false); 969 } 970 971 } catch (StandardException se) { 972 if (!protocolOrType.equals(Monitor.SERVICE_TYPE_DIRECTORY)) 976 reportException(se); 977 } 978 } 979 } 980 } 981 982 988 public final boolean startPersistentService(String name, Properties properties) 989 throws StandardException { 990 991 return findProviderAndStartService(name, properties, false); 992 993 } 994 995 1004 1005 public Object createPersistentService(String factoryInterface, String name, Properties properties) 1006 throws StandardException { 1007 1008 1009 PersistentService provider = findProviderForCreate(name); 1010 if (provider == null) { 1011 throw StandardException.newException(SQLState.PROTOCOL_UNKNOWN, name); 1012 } 1013 1014 return bootService(provider, factoryInterface, name, properties, true); 1015 } 1016 1022 public void removePersistentService(String name) 1023 throws StandardException 1024 { 1025 PersistentService provider=null; 1026 provider = findProviderForCreate(name); 1027 String serviceName = provider.getCanonicalServiceName(name); 1028 boolean removed = provider.removeServiceRoot(serviceName); 1029 if (removed == false) 1030 throw StandardException.newException(SQLState.SERVICE_DIRECTORY_REMOVE_ERROR,serviceName); 1031 } 1032 1038 public Object startNonPersistentService(String factoryInterface, String serviceName, Properties properties) 1039 throws StandardException { 1040 1041 return bootService((PersistentService) null, factoryInterface, serviceName, properties, false); 1042 } 1043 1044 1045 1053 private Vector getImplementations(Properties moduleList, boolean actualModuleList) { 1054 1055 if (moduleList == null) 1056 return null; 1057 1058 Vector implementations = actualModuleList ? new Vector (moduleList.size()) : new Vector (0,1); 1059 1060 int theJDKId = JVMInfo.JDK_ID; 1062 1063 int[] envModuleCount = new int[theJDKId + 1]; 1064 1065nextModule: 1066 for (Enumeration e = moduleList.propertyNames(); e.hasMoreElements(); ) { 1067 1068 String key = (String ) e.nextElement(); 1069 1070 String tag; 1073 1074 1080 if (key.startsWith(Property.MODULE_PREFIX)) { 1081 tag = key.substring(Property.MODULE_PREFIX.length()); 1082 } else if (key.startsWith(Property.SUB_SUB_PROTOCOL_PREFIX)) { 1083 tag = key.substring(Property.MODULE_PREFIX.length()); 1084 } else { 1085 continue nextModule; 1086 } 1087 1088 1089 1091 String envKey = Property.MODULE_ENV_JDK_PREFIX.concat(tag); 1093 String envJDK = moduleList.getProperty(envKey); 1094 int envJDKId = 0; 1095 1096 if (envJDK != null) { 1097 envJDKId = Integer.parseInt(envJDK.trim()); 1098 if (envJDKId > theJDKId) { 1099 continue nextModule; 1100 } 1101 } 1102 1103 envKey = Property.MODULE_ENV_CLASSES_PREFIX.concat(tag); 1105 String envClasses = moduleList.getProperty(envKey); 1106 if (envClasses != null) { 1107 1108 StringTokenizer st = new StringTokenizer (envClasses, ","); 1109 for (; st.hasMoreTokens(); ) { 1110 try { 1111 Class.forName(st.nextToken().trim()); 1112 } catch (ClassNotFoundException cnfe) { 1113 continue nextModule; 1114 } catch (LinkageError le) { 1115 continue nextModule; 1116 } 1117 } 1118 } 1119 1120 1121 1122 String className = moduleList.getProperty(key); 1126 1127 if (SanityManager.DEBUG && reportOn) { 1128 report("Accessing module " + className + " to run initializers at boot time"); 1129 } 1130 1131 try { 1132 Class possibleModule = Class.forName(className); 1133 1134 if (getPersistentServiceImplementation(possibleModule)) 1136 continue; 1137 1138 1139 if( StorageFactory.class.isAssignableFrom(possibleModule)) { 1140 storageFactories.put(tag, className); 1141 continue; 1142 } 1143 1144 1145 1156 if (envJDKId != 0) { 1157 1158 int offset = 0; 1160 for (int eji = theJDKId; eji > envJDKId; eji--) { 1161 offset += envModuleCount[eji]; 1162 } 1163 1164 implementations.insertElementAt(possibleModule, offset); 1165 envModuleCount[envJDKId]++; 1166 1167 } 1168 else { 1169 implementations.addElement(possibleModule); 1171 } 1172 1173 if (SanityManager.DEBUG) { 1177 Class [] csParams = { new java.util.Properties ().getClass()}; 1179 try { 1180 possibleModule.getMethod("canSupport", csParams); 1181 if (!ModuleSupportable.class.isAssignableFrom(possibleModule)) { 1182 SanityManager.THROWASSERT("Module does not implement ModuleSupportable but has canSupport() - " + className); 1183 } 1184 } catch (NoSuchMethodException nsme){} 1185 1186 boolean eitherMethod = false; 1188 1189 Class [] bootParams = {Boolean.TYPE, new java.util.Properties ().getClass()}; 1190 try { 1191 possibleModule.getMethod("boot", bootParams); 1192 eitherMethod = true; 1193 } catch (NoSuchMethodException nsme){} 1194 1195 Class [] stopParams = {}; 1196 try { 1197 possibleModule.getMethod("stop", stopParams); 1198 eitherMethod = true; 1199 } catch (NoSuchMethodException nsme){} 1200 1201 if (eitherMethod) { 1202 if (!ModuleControl.class.isAssignableFrom(possibleModule)) { 1203 SanityManager.THROWASSERT("Module does not implement ModuleControl but has its methods - " + className); 1204 } 1205 } 1206 } 1207 1208 } 1209 catch (ClassNotFoundException cnfe) { 1210 report("Class " + className + " " + cnfe.toString() + ", module ignored."); 1211 } 1212 catch (LinkageError le) { 1213 report("Class " + className + " " + le.toString() + ", module ignored."); 1214 } 1215 } 1216 1217 if (implementations.isEmpty()) 1218 return null; 1219 implementations.trimToSize(); 1220 1221 return implementations; 1222 } 1223 1224 private boolean getPersistentServiceImplementation( Class possibleModule) 1225 { 1226 if( ! PersistentService.class.isAssignableFrom(possibleModule)) 1227 return false; 1228 1229 PersistentService ps = (PersistentService) newInstance(possibleModule); 1230 if (ps == null) { 1231 report("Class " + possibleModule.getName() + " cannot create instance, module ignored."); 1232 } else { 1233 if (serviceProviders == null) 1234 serviceProviders = new Hashtable (3, (float) 1.0); 1235 serviceProviders.put(ps.getType(), ps); 1236 } 1237 return true; 1238 } 1240 private Vector getDefaultImplementations() { 1241 1242 Properties moduleList = getDefaultModuleProperties(); 1243 1244 return getImplementations(moduleList, true); 1245 } 1247 1254 Properties getDefaultModuleProperties() 1255 { 1256 Properties moduleList = new Properties (); 1259 boolean firstList = true; 1260 1261 ClassLoader cl = getClass().getClassLoader(); 1262 try { 1263 Enumeration e = cl == null ? 1264 ClassLoader.getSystemResources("org/apache/derby/modules.properties") : 1265 cl.getResources("org/apache/derby/modules.properties"); 1266 while (e.hasMoreElements()) { 1267 URL modulesPropertiesURL = (URL ) e.nextElement(); 1268 InputStream is = null; 1269 try { 1270 is = modulesPropertiesURL.openStream(); 1271 if( firstList) { 1272 moduleList.load( is); 1273 firstList = false; 1274 } 1275 else { 1276 Properties otherList = new Properties (); 1278 otherList.load( is); 1279 for( Enumeration newKeys = otherList.keys(); newKeys.hasMoreElements() ;) 1280 { 1281 String key = (String ) newKeys.nextElement(); 1282 if( moduleList.contains( key)) 1283 report( "Ignored duplicate property " + key + " in " + modulesPropertiesURL.toString()); 1285 else 1286 moduleList.setProperty( key, otherList.getProperty( key)); 1287 } 1288 } 1289 } catch (IOException ioe) { 1290 if (SanityManager.DEBUG) 1291 report("Can't load implementation list " + modulesPropertiesURL.toString() + ": " + ioe.toString()); 1292 } finally { 1293 try { 1294 if( is != null) 1295 is.close(); 1296 } catch (IOException ioe2) { 1297 } 1298 } 1299 } 1300 } catch (IOException ioe) { 1301 if (SanityManager.DEBUG) 1302 report("Can't load implementation list: " + ioe.toString()); 1303 } 1304 if (SanityManager.DEBUG) 1305 { 1306 if (firstList) 1307 report("Default implementation list not found"); 1308 } 1309 1310 return moduleList; 1311 } 1312 1313 1316 1317 1320 protected static Properties removeRuntimeProperties(Properties properties) { 1321 1322 Properties subset = new Properties (); 1323 1324 for (Enumeration e = properties.keys(); e.hasMoreElements(); ) { 1325 1326 String key = (String ) e.nextElement(); 1327 if (key.startsWith(Property.PROPERTY_RUNTIME_PREFIX)) 1328 continue; 1329 1330 subset.put(key, properties.get(key)); 1331 } 1332 1333 return subset; 1334 } 1335 1336 1337 1340 abstract InputStream applicationPropertiesStream() 1341 throws IOException ; 1342 1343 1344 1346 protected Properties readApplicationProperties() { 1347 1348 InputStream is = null; 1349 1350 try { 1351 is = applicationPropertiesStream(); 1353 if (is == null) 1354 return null; 1355 1356 Properties properties = new Properties (); 1357 1358 org.apache.derby.iapi.util.PropertyUtil.loadWithTrimmedValues( 1361 new BufferedInputStream (is), properties); 1362 1363 return properties; 1364 1365 } catch (SecurityException se) { 1366 return null; 1367 } catch (IOException ioe) { 1368 report(ioe.toString() + " (" + Property.PROPERTIES_FILE + ")"); 1369 reportException(ioe); 1370 return null; 1371 1372 }finally { 1373 1374 1375 try { 1376 if (is != null) { 1377 is.close(); 1378 is = null; 1379 } 1380 1381 } catch (IOException e) { 1382 } 1383 } 1384 } 1385 1386 1387 1407 1408 1413 protected void bootServiceProviders() { 1414 1415 if (serviceProviders == null) { 1416 return; 1417 } 1418 1419 for (Enumeration e = serviceProviders.keys(); e.hasMoreElements(); ) { 1420 1421 String serviceType = (String ) e.nextElement(); 1422 Object provider = serviceProviders.get(serviceType); 1423 1424 if (!BaseMonitor.canSupport(provider, (Properties ) null)) { 1426 serviceProviders.remove(serviceType); 1427 continue; 1428 } 1429 } 1430 } 1431 1439 protected void bootPersistentServices() { 1440 Enumeration e = new ProviderEnumeration( applicationProperties); 1441 while (e.hasMoreElements()) { 1442 PersistentService provider = (PersistentService) e.nextElement(); 1443 bootProviderServices(provider); 1444 } 1445 1446 } 1447 1448 1456 protected void bootProviderServices(PersistentService provider) { 1457 1458 if (SanityManager.DEBUG && reportOn) { 1459 report("Booting persistent services for provider: " + provider.getType()); 1460 } 1461 1462 for (Enumeration e = provider.getBootTimeServices(); (e != null) && e.hasMoreElements(); ) { 1463 1464 String serviceName = (String ) e.nextElement(); 1465 1466 Properties serviceProperties; 1467 try { 1468 serviceProperties = provider.getServiceProperties(serviceName, null); 1469 } catch (StandardException mse) { 1470 report("Failed to load service properties, name: " + serviceName + ", type = " + provider.getType()); 1471 reportException(mse); 1472 continue; 1473 } 1474 1475 if (Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) 1477 continue; 1478 1479 1480 try { 1481 startProviderService(provider, serviceName, serviceProperties); 1482 } catch (StandardException mse) { 1483 report("Service failed to boot, name: " + serviceName + ", type = " + provider.getType()); 1484 reportException(mse); 1485 continue; 1486 } 1487 } 1488 } 1489 1492 private boolean findProviderAndStartService(String name, 1493 Properties properties, boolean bootTime) 1494 throws StandardException { 1495 1496 PersistentService actualProvider = null; 1497 1498 Properties serviceProperties = null; 1499 String serviceName = null; 1500 1501 int colon = name.indexOf(':'); 1503 if (colon != -1) { 1504 actualProvider = findProviderFromName(name, colon); 1505 1506 if (actualProvider != null) { 1512 1513 serviceName = actualProvider.getCanonicalServiceName(name); 1514 if (serviceName == null) 1515 return true; 1517 serviceProperties = 1518 actualProvider.getServiceProperties(serviceName, properties); 1519 1520 if (serviceProperties == null) 1521 return true; 1523 if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) 1525 return true; 1526 1527 startProviderService(actualProvider, serviceName, serviceProperties); 1528 return true; } 1530 } 1531 1532 StandardException savedMse = null; 1533 1534 for (Enumeration e = new ProviderEnumeration( properties); e.hasMoreElements(); ) { 1535 1536 PersistentService provider = (PersistentService) e.nextElement(); 1537 1538 String sn = provider.getCanonicalServiceName(name); 1539 if (sn == null) 1540 continue; 1541 1542 Properties p = null; 1543 try { 1544 p = provider.getServiceProperties(sn, properties); 1545 if (p == null) 1547 continue; 1548 1549 } catch (StandardException mse) { 1550 savedMse = mse; 1551 } 1552 1553 1554 if (actualProvider == null) { 1556 actualProvider = provider; 1557 serviceName = sn; 1558 serviceProperties = p; 1559 continue; 1560 } 1561 1562 throw StandardException.newException(SQLState.AMBIGIOUS_PROTOCOL, name); 1564 } 1565 1566 if (actualProvider == null) 1569 return colon == -1; 1570 1571 if (savedMse != null) 1572 throw savedMse; 1573 1574 if (bootTime && Boolean.valueOf(serviceProperties.getProperty(Property.NO_AUTO_BOOT)).booleanValue()) 1576 return true; 1577 1578 startProviderService(actualProvider, serviceName, serviceProperties); 1579 return true; 1580 } 1581 1582 protected PersistentService findProviderForCreate(String name) throws StandardException { 1583 return (PersistentService) findProviderFromName(name, name.indexOf(':')); 1585 } 1586 1587 1592 private PersistentService findProviderFromName(String name, int colon) throws StandardException 1593 { 1594 if (colon == 0) 1596 return null; 1597 1598 String serviceType; 1599 if (colon < 2) { 1600 serviceType = PersistentService.DIRECTORY; 1602 } else { 1603 serviceType = name.substring(0, colon); 1604 } 1605 return getServiceProvider(serviceType); 1606 } 1607 1608 public PersistentService getServiceProvider(String subSubProtocol) throws StandardException 1609 { 1610 if( subSubProtocol == null) 1611 return null; 1612 if( serviceProviders != null) 1613 { 1614 PersistentService ps = (PersistentService) serviceProviders.get( subSubProtocol); 1615 if( ps != null) 1616 return ps; 1617 } 1618 return getPersistentService(subSubProtocol); 1619 } 1621 1622 1626 private PersistentService getPersistentService(String subSubProtocol) 1627 throws StandardException 1628 { 1629 String className = getStorageFactoryClassName(subSubProtocol); 1630 return getPersistentService( className, subSubProtocol); 1631 } 1632 1633 private PersistentService getPersistentService( final String className, String subSubProtocol) throws StandardException 1634 { 1635 if( className == null) 1636 return null; 1637 Class storageFactoryClass = null; 1638 try 1639 { 1640 storageFactoryClass = Class.forName( className); 1641 } 1642 catch (Throwable e) 1643 { 1644 throw StandardException.newException( SQLState.INSTANTIATE_STORAGE_FACTORY_ERROR, 1645 e, 1646 subSubProtocol, className); 1647 } 1648 return new StorageFactoryService( subSubProtocol, storageFactoryClass); 1649 } 1651 1657 private String getStorageFactoryClassName(String subSubProtocol) 1658 { 1659 String propertyName = Property.SUB_SUB_PROTOCOL_PREFIX + subSubProtocol; 1660 String className = PropertyUtil.getSystemProperty( propertyName); 1661 if( className != null) 1662 return className; 1663 return (String ) storageFactories.get( subSubProtocol); 1664 } 1666 private static final HashMap storageFactories = new HashMap (); 1667 static { 1668 String dirStorageFactoryClass; 1669 if( JVMInfo.JDK_ID >= JVMInfo.J2SE_14) 1670 dirStorageFactoryClass = "org.apache.derby.impl.io.DirStorageFactory4"; 1671 else 1672 dirStorageFactoryClass = "org.apache.derby.impl.io.DirStorageFactory"; 1673 1674 1675 storageFactories.put( PersistentService.DIRECTORY, dirStorageFactoryClass); 1676 storageFactories.put( PersistentService.CLASSPATH, 1677 "org.apache.derby.impl.io.CPStorageFactory"); 1678 storageFactories.put( PersistentService.JAR, 1679 "org.apache.derby.impl.io.JarStorageFactory"); 1680 storageFactories.put( PersistentService.HTTP, 1681 "org.apache.derby.impl.io.URLStorageFactory"); 1682 storageFactories.put( PersistentService.HTTPS, 1683 "org.apache.derby.impl.io.URLStorageFactory"); 1684 } 1685 1686 1689 protected void startProviderService(PersistentService provider, String serviceName, Properties serviceProperties) 1690 throws StandardException { 1691 1692 String protocol = serviceProperties.getProperty(Property.SERVICE_PROTOCOL); 1693 1694 if (protocol == null) { 1695 throw StandardException.newException(SQLState.PROPERTY_MISSING, Property.SERVICE_PROTOCOL); 1696 } 1697 1698 bootService(provider, protocol, serviceName, serviceProperties, false); 1699 } 1700 1701 1704 protected Object bootService(PersistentService provider, 1705 String factoryInterface, String serviceName, Properties properties, 1706 boolean create) throws StandardException { 1707 1708 if(provider != null) 1711 serviceName = provider.getCanonicalServiceName(serviceName); 1712 ProtocolKey serviceKey = ProtocolKey.create(factoryInterface, serviceName); 1713 if (SanityManager.DEBUG && reportOn) { 1714 report("Booting service " + serviceKey + " create = " + create); 1715 } 1716 1717 ContextManager previousCM = contextService.getCurrentContextManager(); 1718 ContextManager cm = previousCM; 1719 Object instance; 1720 TopService ts = null; 1721 Context sb = null; 1722 1723 1724 try { 1725 1726 1727 synchronized (this) { 1728 1729 if (inShutdown) { 1730 throw StandardException.newException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN); 1731 } 1732 1733 for (int i = 1; i < services.size(); i++) { 1734 TopService ts2 = (TopService) services.elementAt(i); 1735 if (ts2.isPotentialService(serviceKey)) { 1736 return null; 1738 } 1739 } 1740 1741 1742 Locale serviceLocale = null; 1743 if (create) { 1744 1745 1746 properties = new Properties (properties); 1751 1752 serviceLocale = setLocale(properties); 1753 1754 properties.put(Property.SERVICE_PROTOCOL, factoryInterface); 1755 1756 serviceName = provider.createServiceRoot(serviceName, 1757 Boolean.valueOf(properties.getProperty(Property.DELETE_ON_CREATE)).booleanValue()); 1758 1759 serviceKey = ProtocolKey.create(factoryInterface, serviceName); 1760 } else if (properties != null) { 1761 String serverLocaleDescription = properties.getProperty(Property.SERVICE_LOCALE); 1762 if ( serverLocaleDescription != null) 1763 serviceLocale = staticGetLocaleFromString(serverLocaleDescription); 1764 } 1765 1766 ts = new TopService(this, serviceKey, provider, serviceLocale); 1767 services.addElement(ts); 1768 } 1769 1770 if (SanityManager.DEBUG) { 1771 if (provider != null) 1772 { 1773 SanityManager.ASSERT(provider.getCanonicalServiceName(serviceName).equals(serviceName), 1774 "mismatched canonical names " + provider.getCanonicalServiceName(serviceName) 1775 + " != " + serviceName); 1776 SanityManager.ASSERT(serviceName.equals(serviceKey.getIdentifier()), 1777 "mismatched names " + serviceName + " != " + serviceKey.getIdentifier()); 1778 } 1779 } 1780 1781 1782 if (properties != null) { 1783 1784 1788 properties.put(PersistentService.ROOT, serviceName); 1790 1791 properties.put(PersistentService.TYPE, provider.getType()); 1793 } 1794 1795 if (SanityManager.DEBUG && reportOn) { 1796 dumpProperties("Service Properties: " + serviceKey.toString(), properties); 1797 } 1798 1799 if (previousCM == null) { 1801 cm = contextService.newContextManager(); 1802 1803 contextService.setCurrentContextManager(cm); 1804 } 1805 sb = new ServiceBootContext(cm); 1806 1807 UpdateServiceProperties usProperties; 1808 Properties serviceProperties; 1809 1810 1811 boolean inRestore = (properties !=null ? 1814 properties.getProperty(Property.IN_RESTORE_FROM_BACKUP) != null:false); 1815 1816 if ((provider != null) && (properties != null)) { 1817 usProperties = new UpdateServiceProperties(provider, 1823 serviceName, 1824 properties, 1825 !(create || inRestore)); 1826 serviceProperties = usProperties; 1827 } else { 1828 usProperties = null; 1829 serviceProperties = properties; 1830 } 1831 1832 instance = ts.bootModule(create, null, serviceKey, serviceProperties); 1833 1834 if (create || inRestore) { 1835 provider.saveServiceProperties(serviceName, usProperties.getStorageFactory(), 1837 BaseMonitor.removeRuntimeProperties(properties), false); 1838 usProperties.setServiceBooted(); 1839 } 1840 1841 if (cm != previousCM) 1842 cm.cleanupOnError(StandardException.closeException()); 1843 1844 } catch (Throwable t) { 1845 1846 if ((t instanceof StandardException) && (((StandardException) t).getSeverity() == ExceptionSeverity.DATABASE_SEVERITY)) 1848 ; 1849 else 1850 t = Monitor.exceptionStartingModule(t); 1851 1852 if (cm != previousCM) { 1853 cm.cleanupOnError(t); 1854 } 1855 1856 if (ts != null) { 1857 ts.shutdown(); 1858 synchronized (this) { 1859 services.removeElement(ts); 1860 } 1861 1862 boolean deleteOnError = (properties !=null ? 1865 properties.getProperty(Property.DELETE_ROOT_ON_ERROR) !=null:false); 1866 if (create || deleteOnError) 1867 provider.removeServiceRoot(serviceName); 1868 } 1869 1870 1871 Throwable nested = ((StandardException) t).getNestedException(); 1872 1873 if (nested instanceof ThreadDeath ) 1875 throw (ThreadDeath ) t; 1876 1877 if (nested instanceof StandardException) 1878 throw (StandardException) t; 1879 1880 throw (StandardException) t; 1881 1882 } finally { 1883 if ((previousCM == cm) && (sb != null)) 1884 sb.popMe(); 1885 1886 if (previousCM == null) 1887 contextService.resetCurrentContextManager(cm); 1888 } 1889 1890 ts.setTopModule(instance); 1892 1893 Thread.yield(); 1899 1900 return instance; 1901 } 1902 1903 1906 1907 1912 public UUIDFactory getUUIDFactory() { 1913 1914 return uuidFactory; 1915 } 1916 1917 1922 public TimerFactory getTimerFactory() { 1923 return timerFactory; 1924 } 1925 1926 1929 1930 private PrintWriter tmpWriter; 1931 private AccessibleByteArrayOutputStream tmpArray; 1932 private boolean dumpedTempWriter; 1933 1934 private PrintWriter getTempWriter() { 1935 if (tmpWriter == null && !dumpedTempWriter) { 1936 tmpArray = new AccessibleByteArrayOutputStream(); 1937 tmpWriter = new PrintWriter (tmpArray); 1938 } 1939 return tmpWriter; 1940 } 1941 1942 private void dumpTempWriter(boolean bothPlaces) { 1943 1944 if (tmpWriter == null) 1945 return; 1946 1947 tmpWriter.flush(); 1948 1949 BufferedReader lnr = new BufferedReader ( 1950 new InputStreamReader ( 1951 new ByteArrayInputStream (tmpArray.getInternalByteArray()))); 1952 try { 1953 String s; 1954 while ((s = lnr.readLine()) != null) { 1955 if (systemStreams != null) 1956 systemStreams.stream().printlnWithHeader(s); 1957 1958 if ((systemStreams == null) || bothPlaces) 1959 logging.println(s); 1960 } 1961 } catch (IOException ioe) { 1962 } 1963 1964 if ((systemStreams == null) || bothPlaces) 1965 logging.flush(); 1966 1967 tmpWriter = null; 1968 tmpArray = null; 1969 dumpedTempWriter = true; 1970 logging = null; 1971 } 1972 1973 1978 static boolean canSupport(Object instance, Properties properties) { 1979 if (instance instanceof ModuleSupportable) { 1980 if (!((ModuleSupportable) instance).canSupport(properties)) 1982 return false; 1983 } 1984 return true; 1985 } 1986 1987 1988 1993 static void boot(Object module, boolean create, Properties properties) 1994 throws StandardException { 1995 1996 if (module instanceof ModuleControl) 1997 ((ModuleControl) module).boot(create, properties); 1998 } 1999 2000 2003 private static Locale staticGetLocaleFromString(String localeDescription) 2004 throws StandardException { 2005 2006 2011 int len = localeDescription.length(); 2012 2013 boolean isOk = (len == 2) || (len == 5) || (len > 6); 2014 2015 if (isOk && (len != 2)) 2017 isOk = localeDescription.charAt(2) == '_'; 2018 2019 if (isOk && (len > 5)) 2021 isOk = localeDescription.charAt(5) == '_'; 2022 2023 if (!isOk) 2024 throw StandardException.newException(SQLState.INVALID_LOCALE_DESCRIPTION, localeDescription); 2025 2026 String language = localeDescription.substring(0, 2); 2027 String country = len == 2 ? "" : localeDescription.substring(3, 5); 2028 2029 if (len < 6) { 2030 return new Locale (language, country); 2031 } 2032 2033 String variant = (len > 6) ? localeDescription.substring(6, len) : null; 2034 2035 return new Locale (language, country, variant); 2036 } 2037 2038 private static Locale setLocale(Properties properties) 2039 throws StandardException { 2040 2041 String userDefinedLocale = properties.getProperty(Attribute.TERRITORY); 2042 Locale locale; 2043 if (userDefinedLocale == null) 2044 locale = Locale.getDefault(); 2045 else { 2046 locale = staticGetLocaleFromString(userDefinedLocale); 2048 } 2049 2050 properties.put(Property.SERVICE_LOCALE, locale.toString()); 2051 return locale; 2052 } 2053 2054 2057 2058 2060 2064 public ResourceBundle getBundle(String messageId) { 2065 ContextManager cm; 2066 try { 2067 cm = ContextService.getFactory().getCurrentContextManager(); 2068 } catch (ShutdownException se) { 2069 cm = null; 2070 } 2071 2072 if (cm != null) { 2073 return MessageService.getBundleForLocale(cm.getMessageLocale(), messageId); 2074 } 2075 return null; 2076 } 2077 2078 public Thread getDaemonThread(Runnable task, String name, boolean setMinPriority) { 2079 Thread t = new Thread (daemonGroup, task, "derby.".concat(name)); 2080 t.setDaemon(true); 2081 if (setMinPriority) { 2082 t.setPriority(Thread.MIN_PRIORITY); 2083 } 2084 return t; 2085 2086 } 2087 2088 public void setThreadPriority(int priority) { 2089 2090 Thread t = Thread.currentThread(); 2091 2092 if (t.getThreadGroup() == daemonGroup) { 2093 t.setPriority(priority); 2094 } 2095 } 2096 2097 2101 abstract boolean initialize(boolean lite); 2102 2103 class ProviderEnumeration implements Enumeration 2104 { 2105 private Enumeration serviceProvidersKeys = (serviceProviders == null) ? null : serviceProviders.keys(); 2106 private Properties startParams; 2107 private Enumeration paramEnumeration; 2108 private boolean enumeratedDirectoryProvider; 2109 private PersistentService storageFactoryPersistentService; 2110 2111 ProviderEnumeration( Properties startParams) 2112 { 2113 this.startParams = startParams; 2114 if( startParams != null) 2115 paramEnumeration = startParams.keys(); 2116 } 2117 2118 public Object nextElement() throws NoSuchElementException 2119 { 2120 if( serviceProvidersKeys != null && serviceProvidersKeys.hasMoreElements()) 2121 return serviceProviders.get( serviceProvidersKeys.nextElement()); 2122 getNextStorageFactory(); 2123 Object ret = storageFactoryPersistentService; 2124 storageFactoryPersistentService = null; 2125 return ret; 2126 } 2127 2128 private void getNextStorageFactory() 2129 { 2130 if( storageFactoryPersistentService != null) 2131 return; 2132 if( paramEnumeration != null) 2133 { 2134 while( paramEnumeration.hasMoreElements()) 2135 { 2136 String prop = (String ) paramEnumeration.nextElement(); 2137 if( prop.startsWith( Property.SUB_SUB_PROTOCOL_PREFIX)) 2138 { 2139 try 2140 { 2141 String storageFactoryClassName = (String ) startParams.get( prop); 2142 if( storageFactoryClassName != null) 2143 { 2144 storageFactoryPersistentService = 2145 getPersistentService( (String ) startParams.get( prop), 2146 prop.substring( Property.SUB_SUB_PROTOCOL_PREFIX.length())); 2147 if( storageFactoryPersistentService != null) 2148 return; 2149 } 2150 } 2151 catch( StandardException se){}; 2152 } 2153 } 2154 } 2155 if( ! enumeratedDirectoryProvider) 2156 { 2157 try 2158 { 2159 storageFactoryPersistentService 2160 = getPersistentService( getStorageFactoryClassName(PersistentService.DIRECTORY), 2161 PersistentService.DIRECTORY); 2162 } 2163 catch( StandardException se){ storageFactoryPersistentService = null; } 2164 enumeratedDirectoryProvider = true; 2165 } 2166 } 2168 public boolean hasMoreElements() 2169 { 2170 if( serviceProvidersKeys != null && serviceProvidersKeys.hasMoreElements()) 2171 return true; 2172 getNextStorageFactory(); 2173 return storageFactoryPersistentService != null; 2174 } 2175 } } 2178class AntiGC implements Runnable { 2179 2180 boolean goAway; 2181 private Object keep1; 2182 2183 AntiGC(Object a) { 2184 keep1 = a; 2185 } 2186 2187 public void run() { 2188 while (true) { 2189 synchronized (this) { 2190 if (goAway) 2191 return; 2192 try { 2193 wait(); 2194 } catch (InterruptedException ie) { 2195 } 2196 } 2197 } 2198 } 2199} | Popular Tags |