Class BaseServiceBroker

    • Constructor Detail

      • BaseServiceBroker

        protected BaseServiceBroker()
        Default constructor, protected as to only be usable by subclasses. This constructor does nothing.
    • Method Detail

      • setConfiguration

        public void setConfiguration​(org.apache.commons.configuration2.Configuration configuration)
        Set the configuration object for the services broker. This is the configuration that contains information about all services in the care of this service manager.
        Parameters:
        configuration - Broker configuration.
      • getConfiguration

        public org.apache.commons.configuration2.Configuration getConfiguration()
        Get the configuration for this service manager.
        Returns:
        Broker configuration.
      • setServiceObject

        public void setServiceObject​(String name,
                                     Object value)
        Set an application specific service object that can be used by application specific services.
        Parameters:
        name - name of service object
        value - value of service object
      • getServiceObject

        public Object getServiceObject​(String name)
        Get an application specific service object.
        Parameters:
        name - the name of the service object
        Returns:
        Object application specific service object
      • initMapping

        protected void initMapping()
                            throws InitializationException
        Creates a mapping between Service names and class names. The mapping is built according to settings present in TurbineResources.properties. The entries should have the following form:
         services.MyService.classname=com.mycompany.MyServiceImpl
         services.MyOtherService.classname=com.mycompany.MyOtherServiceImpl
         

        Generic ServiceBroker provides no Services.
        Throws:
        InitializationException - if a service class could not be found
      • isRegistered

        public boolean isRegistered​(String serviceName)
        Determines whether a service is registered in the configured TurbineResources.properties.
        Specified by:
        isRegistered in interface ServiceBroker
        Parameters:
        serviceName - The name of the service whose existence to check.
        Returns:
        Registration predicate for the desired services.
      • getServiceNames

        public Iterator<StringgetServiceNames()
        Returns an Iterator over all known service names.
        Returns:
        An Iterator of service names.
      • getServiceNames

        public Iterator<StringgetServiceNames​(String prefix)
        Returns an Iterator over all known service names beginning with the provided prefix.
        Parameters:
        prefix - The prefix against which to test.
        Returns:
        An Iterator of service names which match the prefix.
      • initServices

        public void initServices()
        Performs early initialization of all services. Failed early initialization of a Service may be non-fatal to the system, thus any exceptions are logged and the initialization process continues.
      • shutdownService

        public void shutdownService​(String name)
        Shuts down a Service, releasing resources allocated by an Service, and returns it to its initial (uninitialized) state.
        Specified by:
        shutdownService in interface ServiceBroker
        Parameters:
        name - The name of the Service to be uninitialized.
      • shutdownServices

        public void shutdownServices()
        Shuts down all Turbine services, releasing allocated resources and returning them to their initial (uninitialized) state.
        Specified by:
        shutdownServices in interface ServiceBroker
      • getServiceInstance

        protected Service getServiceInstance​(String name)
                                      throws InstantiationException
        Retrieves an instance of a Service without triggering late initialization. Early initialization of a Service can require access to Service properties. The Service must have its name and serviceBroker set by then. Therefore, before calling Initable.initClass(Object), the class must be instantiated with InitableBroker.getInitableInstance(), and Service.setServiceBroker() and Service.setName() must be called. This calls for two - level accessing the Services instances.
        Parameters:
        name - The name of the service requested.
        Returns:
        the Service instance
        Throws:
        InstantiationException - The service is unknown or can't be initialized.
      • getConfiguration

        public org.apache.commons.configuration2.Configuration getConfiguration​(String name)
        Returns the configuration for the specified service.
        Specified by:
        getConfiguration in interface ServiceBroker
        Parameters:
        name - The name of the service.
        Returns:
        Configuration of requested Service.
      • setApplicationRoot

        public void setApplicationRoot​(String applicationRoot)
        Set the application root.
        Parameters:
        applicationRoot - application root
      • isLocalService

        protected boolean isLocalService​(String name)
        Determines if the requested service is managed by this ServiceBroker.
        Parameters:
        name - The name of the Service requested.
        Returns:
        true if the service is managed by the this ServiceBroker
      • isNonLocalService

        protected boolean isNonLocalService​(String name)
        Determines if the requested service is managed by an initialized TurbineServiceProvider. We use the service names to lookup the TurbineServiceProvider to ensure that we get a fully initialized service.
        Parameters:
        name - The name of the Service requested.
        Returns:
        true if the service is managed by a TurbineServiceProvider