Class SharedServiceFactory<T>

  • All Implemented Interfaces:
    java.util.function.Function<java.util.function.Supplier<T>,​T>

    public class SharedServiceFactory<T>
    extends java.lang.Object
    implements java.util.function.Function<java.util.function.Supplier<T>,​T>
    A factory for creating service instances that delegate to the same shared instance, i.e. it uses the first instance and ignores subsequent ones.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int cnt
      The usage count to know when the service can be shut down.
      protected jadex.commons.future.IFuture<java.lang.Void> inited
      The init future of the shared service.
      protected T instance
      The shared service instance.
      protected java.util.function.BiFunction<IComponentIdentifier,​SharedServiceFactory<T>,​SharedService<T>> wrapperfactory
      The wrapper creation function.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T apply​(java.util.function.Supplier<T> creator)
      Create a new wrapper for the first supplied instance.
      jadex.commons.future.IFuture<java.lang.Void> shutdownService()
      Shutdown the original service on last invocation.
      jadex.commons.future.IFuture<java.lang.Void> startService()
      Start the original service on first invocation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Field Detail

      • instance

        protected volatile T instance
        The shared service instance.
      • inited

        protected volatile jadex.commons.future.IFuture<java.lang.Void> inited
        The init future of the shared service.
      • cnt

        protected volatile int cnt
        The usage count to know when the service can be shut down.
    • Constructor Detail

      • SharedServiceFactory

        public SharedServiceFactory​(java.util.function.BiFunction<IComponentIdentifier,​SharedServiceFactory<T>,​SharedService<T>> wrapperfactory)
        Create a factory for service sharing.
        Parameters:
        wrapperfactory - Function to create the individual wrappers for each platform.
    • Method Detail

      • apply

        public T apply​(java.util.function.Supplier<T> creator)
        Create a new wrapper for the first supplied instance.
        Specified by:
        apply in interface java.util.function.Function<java.util.function.Supplier<T>,​T>
      • startService

        public jadex.commons.future.IFuture<java.lang.Void> startService()
        Start the original service on first invocation.
      • shutdownService

        public jadex.commons.future.IFuture<java.lang.Void> shutdownService()
        Shutdown the original service on last invocation.