Class DelegatingServiceContainer

    • Constructor Detail

      • DelegatingServiceContainer

        public DelegatingServiceContainer​(ServiceTarget serviceTargetDelegate,
                                          ServiceRegistry serviceRegistryDelegate)
        Construct a new instance.
        Parameters:
        serviceTargetDelegate - the delegate to forward service target requests to
        serviceRegistryDelegate - the delegate to forward registry requests to
    • Method Detail

      • getServiceTargetDelegate

        protected ServiceTarget getServiceTargetDelegate()
        Get the ServiceTarget delegate.
        Returns:
        ServiceTarget delegate
      • getServiceRegistryDelegate

        protected ServiceRegistry getServiceRegistryDelegate()
        Get the ServiceRegistry delegate.
        Returns:
        ServiceRegistry delegate
      • addService

        public ServiceBuilder<?> addService()
        Get a builder which can be used to add a service to this target.
        Specified by:
        addService in interface ServiceTarget
        Returns:
        new service configurator
      • addListener

        public ServiceContainer addListener​(LifecycleListener listener)
        Add a service lifecycle listener that will be added to this service.
        Specified by:
        addListener in interface ServiceTarget
        Parameters:
        listener - the lifecycle listener to add to the service
        Returns:
        this target
      • subTarget

        public ServiceTarget subTarget()
        Create a sub-target using this as the parent target.
        Specified by:
        subTarget in interface ServiceTarget
        Returns:
        the new service target
      • getService

        public ServiceController<?> getService​(ServiceName serviceName)
        Get a service, returning null if it is not found.
        Specified by:
        getService in interface ServiceRegistry
        Parameters:
        serviceName - the service name
        Returns:
        the service controller for the corresponding service, or null if it is not found
      • getName

        public String getName()
        Get the name of this service container.
        Specified by:
        getName in interface ServiceContainer
        Returns:
        the container name
      • shutdown

        public void shutdown()
        Stop all services within this container.
        Specified by:
        shutdown in interface ServiceContainer
      • isShutdown

        public boolean isShutdown()
        Whether container have been shut down.
        Specified by:
        isShutdown in interface ServiceContainer
        Returns:
        true if container is shutting down
      • isShutdownComplete

        public boolean isShutdownComplete()
        Determine whether the container is completely shut down.
        Specified by:
        isShutdownComplete in interface ServiceContainer
        Returns:
        true if shutdown is complete
      • dumpServices

        public void dumpServices()
        Dump a complete list of services to System.out.
        Specified by:
        dumpServices in interface ServiceContainer
      • dumpServices

        public void dumpServices​(PrintStream stream)
        Dump a complete list of services to the given stream.
        Specified by:
        dumpServices in interface ServiceContainer
        Parameters:
        stream - the stream to which the service list should be written
      • awaitTermination

        public void awaitTermination()
        Causes the current thread to wait until the container is shutdown.
        Specified by:
        awaitTermination in interface ServiceContainer
      • awaitTermination

        public void awaitTermination​(long timeout,
                                     TimeUnit unit)
                              throws InterruptedException
        Causes the current thread to wait until the container is shutdown.
        Specified by:
        awaitTermination in interface ServiceContainer
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Throws:
        InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public boolean awaitStability​(long timeout,
                                      TimeUnit unit)
                               throws InterruptedException
        Causes the current thread to wait until the container is stable.
        Specified by:
        awaitStability in interface ServiceContainer
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        true if this container achieved stability, false if the timeout elapsed before stability
        Throws:
        InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public boolean awaitStability​(long timeout,
                                      TimeUnit unit,
                                      Set<? super ServiceController<?>> failed,
                                      Set<? super ServiceController<?>> problem)
                               throws InterruptedException
        Causes the current thread to wait until the container is stable.
        Specified by:
        awaitStability in interface ServiceContainer
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        failed - a set into which failed services should be copied
        problem - a set into which problem services should be copied
        Returns:
        true if this container achieved stability, false if the timeout elapsed before stability
        Throws:
        InterruptedException - if the current thread is interrupted while waiting
      • addService

        @Deprecated
        public <T> ServiceBuilder<T> addService​(ServiceName name,
                                                Service<T> service)
        Deprecated.
        Get a builder which can be used to add a service to this target.
        Specified by:
        addService in interface ServiceTarget
        Parameters:
        name - the service name
        service - the service
        Returns:
        the builder for the service
      • addMonitor

        @Deprecated
        public ServiceTarget addMonitor​(StabilityMonitor monitor)
        Deprecated.
        Add a stability monitor that will be added to all the ServiceBuilders installed in this target.
        Specified by:
        addMonitor in interface ServiceTarget
        Parameters:
        monitor - the monitor to add to the target
        Returns:
        this target
      • addDependency

        @Deprecated
        public ServiceContainer addDependency​(ServiceName dependency)
        Deprecated.
        Add a dependency that will be added to the all ServiceBuilders installed in this target.
        Specified by:
        addDependency in interface ServiceTarget
        Parameters:
        dependency - the dependency to add to the target
        Returns:
        this target