Class BaseMonitor

java.lang.Object
org.apache.derby.impl.services.monitor.BaseMonitor
All Implemented Interfaces:
BundleFinder, ModuleFactory
Direct Known Subclasses:
FileMonitor

abstract class BaseMonitor extends Object implements ModuleFactory, BundleFinder
Implementation of the monitor that uses the class loader that the its was loaded in for all class loading.
  • Field Details

  • Constructor Details

    • BaseMonitor

      BaseMonitor()
  • Method Details

    • getSystemStreams

      public InfoStreams getSystemStreams()
      Description copied from interface: ModuleFactory
      Get the defined default system streams object.
      Specified by:
      getSystemStreams in interface ModuleFactory
    • shutdown

      public void shutdown()
      Description copied from interface: ModuleFactory
      Shut down the complete system that was started by this Monitor. Will cause the stop() method to be called on each loaded module.
      Specified by:
      shutdown in interface ModuleFactory
    • shutdown

      public void shutdown(Object serviceModule)
      Shut down a service that was started by this Monitor. Will cause the stop() method to be called on each loaded module.
      Specified by:
      shutdown in interface ModuleFactory
    • runWithState

      protected final void runWithState(Properties properties, PrintWriter log)
    • getCanonicalServiceName

      public String getCanonicalServiceName(String userSpecifiedName) throws StandardException
      Description copied from interface: ModuleFactory
      Canonicalize a service name, mapping different user-specifications of a database name onto a single, standard name.
      Specified by:
      getCanonicalServiceName in interface ModuleFactory
      Throws:
      StandardException
    • findService

      public Object findService(String factoryInterface, String serviceName)
      Description copied from interface: ModuleFactory
      Find a service.
      Do not call directly - use Monitor.findService()
      Specified by:
      findService in interface ModuleFactory
      Returns:
      a refrence to a module represeting the service or null if the service does not exist.
      See Also:
    • getLocale

      public Locale getLocale(Object serviceModule)
      Description copied from interface: ModuleFactory
      Return the locale of the service that the passed in module lives in. Will return null if no-locale has been defined.
      Specified by:
      getLocale in interface ModuleFactory
    • getLocaleFromString

      public Locale getLocaleFromString(String localeDescription) throws StandardException
      Description copied from interface: ModuleFactory
      Translate a string of the form ll[_CC[_variant]] to a Locale. This is in the Monitor because we want this translation to be in only one place in the code.
      Specified by:
      getLocaleFromString in interface ModuleFactory
      Throws:
      StandardException
    • getServiceName

      public String getServiceName(Object serviceModule)
      Return the name of the service that the passed in module lives in.
      Specified by:
      getServiceName in interface ModuleFactory
    • setLocale

      public Locale setLocale(Object serviceModule, String userDefinedLocale) throws StandardException
      Set the locale for the service *outside* of boot time.
      Specified by:
      setLocale in interface ModuleFactory
      Parameters:
      userDefinedLocale - A String in the form xx_YY, where xx is the language code and YY is the country code.
      Returns:
      The new Locale for the service
      Throws:
      StandardException - Standard Derby error.
    • setLocale

      public Locale setLocale(Properties serviceProperties, String userDefinedLocale) throws StandardException
      Set the locale for the service at boot time. The passed in properties must be the one passed to the boot method.
      Specified by:
      setLocale in interface ModuleFactory
      Throws:
      StandardException - Standard Derby error.
    • getServiceType

      public PersistentService getServiceType(Object serviceModule)
      Return the PersistentService object for a service. Will return null if the service does not exist.
      Specified by:
      getServiceType in interface ModuleFactory
    • startModule

      public Object startModule(boolean create, Object serviceModule, String factoryInterface, String identifier, Properties properties) throws StandardException
      Start a module.
      Specified by:
      startModule in interface ModuleFactory
      Throws:
      StandardException - se An attempt to start the module failed.
      See Also:
    • findTopService

      private TopService findTopService(Object serviceModule)
    • findModule

      public Object findModule(Object serviceModule, String factoryInterface, String identifier)
      Description copied from interface: ModuleFactory
      Find the module in the system with the given module protocol, protocolVersion and identifier.
      Specified by:
      findModule in interface ModuleFactory
      Returns:
      The module instance if found, or null.
    • classFromIdentifier

      public InstanceGetter classFromIdentifier(int fmtId) throws StandardException
      Obtain a class that supports the given identifier.
      Specified by:
      classFromIdentifier in interface ModuleFactory
      Parameters:
      fmtId - identifer to associate with class
      Returns:
      a reference InstanceGetter
      Throws:
      StandardException - See Monitor.classFromIdentifier
      See Also:
    • newInstanceFromIdentifier

      public Object newInstanceFromIdentifier(int identifier) throws StandardException
      Obtain an new instance of a class that supports the given identifier.
      Specified by:
      newInstanceFromIdentifier in interface ModuleFactory
      Parameters:
      identifier - identifer to associate with class
      Returns:
      a reference to a newly created object or null if a matching class cannot be found.
      Throws:
      StandardException - See Monitor.newInstanceFromIdentifier
    • loadInstance

      protected Object loadInstance(Class<?> factoryInterface, Properties properties)
      load a module instance. Look through the implementations for a module that implements the required factory interface and can handle the properties given. The module's start or create method is not called.
    • loadInstance

      private Object loadInstance(List<Class<?>> implementations, Class<?> factoryInterface, Properties properties)
    • findImplementation

      private static int findImplementation(List<Class<?>> implementations, int startIndex, Class<?> factoryInterface)
      Find a class that implements the required index, return the index into the implementations vector of that class. Returns -1 if no class could be found.
    • newInstance

      private Object newInstance(Class<?> classObject)
      Return a new instance of class classObject using a no-param constructor.
      Parameters:
      classObject - the class to instantiate
      Returns:
      the instantiated object
    • getApplicationProperties

      public Properties getApplicationProperties()
      Description copied from interface: ModuleFactory
      Return the application set of properties which correspond to the set of properties in the file derby.properties.
      Specified by:
      getApplicationProperties in interface ModuleFactory
    • getServiceList

      public String[] getServiceList(String protocol)
      Return an array of the service identifiers that are running and implement the passed in protocol (java interface class name).
      Specified by:
      getServiceList in interface ModuleFactory
      Returns:
      The list of service names, if no services exist that implement the protocol an array with zero elements is returned.
      See Also:
    • dumpProperties

      void dumpProperties(String title, Properties props)
    • report

      protected void report(String message)
      Should only be called if reportOn is true apart from report/Exception().
    • reportException

      protected void reportException(Throwable t)
    • addDebugFlags

      private void addDebugFlags(String flags, boolean set)
    • startServices

      public void startServices(Properties properties, boolean bootAll)
      Description copied from interface: ModuleFactory
      Start all services identified by derby.service.* in the property set. If bootAll is true the services that are persistent will be booted.
      Specified by:
      startServices in interface ModuleFactory
    • startPersistentService

      public final boolean startPersistentService(String name, Properties properties) throws StandardException
      Start a peristent service.
      Specified by:
      startPersistentService in interface ModuleFactory
      Parameters:
      name - Name of the service to be started
      properties - Property set made available to all modules booted for this service, through their ModuleControl.boot method.
      Returns:
      true if the service type is handled by the monitor, false if it isn't
      Throws:
      StandardException - An attempt to start the service failed.
      See Also:
    • createPersistentService

      public Object createPersistentService(String factoryInterface, String name, Properties properties) throws StandardException
      Create a persistent service.
      Specified by:
      createPersistentService in interface ModuleFactory
      Returns:
      The module from the service if it was created successfully, null if a service already existed.
      Throws:
      StandardException - An exception was thrown trying to create the service.
      See Also:
    • removePersistentService

      public void removePersistentService(String name) throws StandardException
      Removes a PersistentService. Could be used for drop database.
      Specified by:
      removePersistentService in interface ModuleFactory
      Parameters:
      name - : Service name to be removed.
      Throws:
      StandardException
    • startNonPersistentService

      public Object startNonPersistentService(String factoryInterface, String serviceName, Properties properties) throws StandardException
      Start a non-persistent service.
      Specified by:
      startNonPersistentService in interface ModuleFactory
      Throws:
      StandardException - An attempt to start the service failed.
      See Also:
    • getImplementations

      private Vector<Class<?>> getImplementations(Properties moduleList, boolean actualModuleList)
      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.
    • getPersistentServiceImplementation

      private boolean getPersistentServiceImplementation(Class<?> possibleModule)
    • getDefaultImplementations

      private Vector<Class<?>> getDefaultImplementations()
    • getDefaultModuleProperties

      Properties getDefaultModuleProperties()
      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.
    • removeRuntimeProperties

      protected static Properties removeRuntimeProperties(Properties properties)
      Return a property set that has the runtime properties removed.
    • applicationPropertiesStream

      abstract InputStream applicationPropertiesStream() throws IOException
      Get InputStream for application properties file Returns nul if it does not exist.
      Throws:
      IOException
    • readApplicationProperties

      protected Properties readApplicationProperties()
    • determineSupportedServiceProviders

      private void determineSupportedServiceProviders()
      Determine which of the set of service providers (PersistentService objects) are supported in the current environment. If a PersistentService implementation does not implement ModuleControl then it is assumed it does support the current environment. Otherwise the canSupport() method makes the determination. Any providers that are not supported are removed from the list.
    • bootPersistentServices

      private void bootPersistentServices()
      Boot all persistent services that can be located at run time.
      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.
    • bootProviderServices

      protected void bootProviderServices(PersistentService provider)
      Boot all persistent services that can be located by a single service provider
      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.
    • findProviderAndStartService

      private boolean findProviderAndStartService(String name, Properties properties, boolean bootTime) throws StandardException
      Find a provider and start a service.
      Throws:
      StandardException
    • findProviderForCreate

      protected PersistentService findProviderForCreate(String name) throws StandardException
      Throws:
      StandardException
    • findProviderFromName

      private PersistentService findProviderFromName(String name, int colon) throws StandardException
      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 characters then it is assumed to be of type directory, i.e. a windows driver letter.
      Throws:
      StandardException
    • getServiceProvider

      public PersistentService getServiceProvider(String subSubProtocol) throws StandardException
      Description copied from interface: ModuleFactory
      Return the PersistentService for a subsubprotocol.
      Specified by:
      getServiceProvider in interface ModuleFactory
      Returns:
      the PersistentService or null if it does not exist
      Throws:
      StandardException
    • getPersistentService

      private PersistentService getPersistentService(String subSubProtocol) throws StandardException
      Return a PersistentService implementation to handle the subSubProtocol.
      Returns:
      Valid PersistentService or null if the protocol is not handled.
      Throws:
      StandardException
    • getPersistentService

      private PersistentService getPersistentService(String className, String subSubProtocol) throws StandardException
      Throws:
      StandardException
    • getStorageFactoryClassName

      private String getStorageFactoryClassName(String subSubProtocol)
      Find the StorageFactory class name that handles the subSub protocol. Looks in the system property set and the set defined during boot.
      Returns:
      Valid class name, or null if no StorageFactory handles the protocol.
    • startProviderService

      protected void startProviderService(PersistentService provider, String serviceName, Properties serviceProperties) throws StandardException
      Boot a service under the control of the provider
      Throws:
      StandardException
    • bootService

      protected Object bootService(PersistentService provider, String factoryInterface, String serviceName, Properties properties, boolean create) throws StandardException
      Boot (start or create) a service (persistent or non-persistent).
      Throws:
      StandardException
    • getUUIDFactory

      public UUIDFactory getUUIDFactory()
      Return the UUID factory for this system. Returns null if there isn't one. See com.ibm.db2j.system.System
      Specified by:
      getUUIDFactory in interface ModuleFactory
    • getTimerFactory

      public TimerFactory getTimerFactory()
      Returns the Timer factory for this system.
      Specified by:
      getTimerFactory in interface ModuleFactory
      Returns:
      the system's Timer factory.
    • getTempWriter

      private PrintWriter getTempWriter()
    • dumpTempWriter

      private void dumpTempWriter(boolean bothPlaces)
    • canSupport

      static boolean canSupport(Object instance, Properties properties)
      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.
    • boot

      static void boot(Object module, boolean create, Properties properties) throws StandardException
      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.
      Throws:
      StandardException
    • staticGetLocaleFromString

      private static Locale staticGetLocaleFromString(String localeDescription) throws StandardException
      Throws:
      StandardException
    • setLocale

      private static Locale setLocale(Properties properties) throws StandardException
      Throws:
      StandardException
    • getBundle

      public ResourceBundle getBundle(String messageId)
      Get the locale from the ContextManager and then find the bundle based upon that locale.
      Specified by:
      getBundle in interface BundleFinder
      Parameters:
      messageId - Message being searched for.
    • getDaemonThread

      public Thread getDaemonThread(Runnable task, String name, boolean setMinPriority)
      Description copied from interface: ModuleFactory
      Get a newly created background thread. The thread is set to be a daemon but is not started.
      Specified by:
      getDaemonThread in interface ModuleFactory
    • isDaemonThread

      public final boolean isDaemonThread(Thread thread)
      Description copied from interface: ModuleFactory
      Specified by:
      isDaemonThread in interface ModuleFactory
      Parameters:
      thread - the thread to check
      Returns:
      true if thread was created by getDaemonThread(), false otherwise.
    • getContextService

      private static ContextService getContextService()
      Privileged lookup of the ContextService. Must be private so that user code can't call this entry point.
    • stopContextService

      private static void stopContextService()
      Privileged shutdown of the ContextService. Must be private so that user code can't call this entry point.
    • setMonitor

      private static boolean setMonitor(BaseMonitor baseMonitor)
      Privileged startup. Must be private so that user code can't call this entry point. Returns true if the system is already booted or in the process of shutting down.
    • initialize

      abstract boolean initialize(boolean lite)
      Initialize the monitor wrt the current environemnt. Returns false if the monitor cannot be initialized, true otherwise.