Class ServiceContainerImpl

    • Field Detail

      • SERIAL

        private static final java.util.concurrent.atomic.AtomicInteger SERIAL
      • PROFILE_OUTPUT

        static final java.lang.String PROFILE_OUTPUT
      • start

        private final long start
      • lock

        private final java.lang.Object lock
      • unstableServices

        private int unstableServices
      • shutdownInitiated

        private long shutdownInitiated
      • autoShutdown

        private final boolean autoShutdown
      • profileOutput

        private final java.io.Writer profileOutput
      • down

        private volatile boolean down
      • name

        private final java.lang.String name
      • mBeanServer

        private final javax.management.MBeanServer mBeanServer
      • objectName

        private final javax.management.ObjectName objectName
      • executorSeq

        private static final java.util.concurrent.atomic.AtomicInteger executorSeq
      • HANDLER

        private static final java.lang.Thread.UncaughtExceptionHandler HANDLER
      • POLICY

        private static final java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy POLICY
    • Constructor Detail

      • ServiceContainerImpl

        ServiceContainerImpl​(java.lang.String name,
                             int coreSize,
                             long timeOut,
                             java.util.concurrent.TimeUnit timeOutUnit,
                             boolean autoShutdown)
    • Method Detail

      • incrementUnstableServices

        void incrementUnstableServices()
      • decrementUnstableServices

        void decrementUnstableServices()
      • isAutoShutdown

        boolean isAutoShutdown()
      • getName

        public java.lang.String getName()
        Description copied from interface: ServiceContainer
        Get the name of this service container.
        Specified by:
        getName in interface ServiceContainer
        Returns:
        the container name
      • getProfileOutput

        java.io.Writer getProfileOutput()
      • getStart

        long getStart()
      • awaitTermination

        public void awaitTermination()
                              throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        Causes the current thread to wait until the container is shutdown.
        Specified by:
        awaitTermination in interface ServiceContainer
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • awaitTermination

        public void awaitTermination​(long timeout,
                                     java.util.concurrent.TimeUnit unit)
                              throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        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:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public void awaitStability()
                            throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        Causes the current thread to wait until the container is stable.
        Specified by:
        awaitStability in interface ServiceContainer
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public boolean awaitStability​(long timeout,
                                      java.util.concurrent.TimeUnit unit)
                               throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        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:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public void awaitStability​(java.util.Set<? super ServiceController<?>> failed,
                                   java.util.Set<? super ServiceController<?>> problem)
                            throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        Causes the current thread to wait until the container is stable.
        Specified by:
        awaitStability in interface ServiceContainer
        Parameters:
        failed - a set into which failed services should be copied
        problem - a set into which problem services should be copied
        Throws:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • awaitStability

        public boolean awaitStability​(long timeout,
                                      java.util.concurrent.TimeUnit unit,
                                      java.util.Set<? super ServiceController<?>> failed,
                                      java.util.Set<? super ServiceController<?>> problem)
                               throws java.lang.InterruptedException
        Description copied from interface: ServiceContainer
        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:
        java.lang.InterruptedException - if the current thread is interrupted while waiting
      • isShutdown

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

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

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

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • shutdownComplete

        private void shutdownComplete​(long started)
      • getExecutor

        java.util.concurrent.Executor getExecutor()
      • getOrCreateRegistration

        private ServiceRegistrationImpl getOrCreateRegistration​(ServiceName name)
        Atomically get or create a registration.
        Parameters:
        name - the service name
        Returns:
        the registration
      • getService

        public ServiceController<?> getService​(ServiceName serviceName)
        Description copied from interface: ServiceRegistry
        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
      • apply

        void apply​(ServiceBuilderImpl<?> builder)
        Description copied from class: ServiceTargetImpl
        Apply listeners and dependencies to serviceBuilder.
        Overrides:
        apply in class ServiceTargetImpl
        Parameters:
        builder - serviceBuilder which listeners and dependencies will be added to.