Package jadex.base.test.impl
Class SharedServiceFactory<T>
- java.lang.Object
-
- jadex.base.test.impl.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.
-
Constructor Summary
Constructors Constructor Description SharedServiceFactory(java.util.function.BiFunction<IComponentIdentifier,SharedServiceFactory<T>,SharedService<T>> wrapperfactory)
Create a factory for service sharing.
-
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.
-
-
-
Field Detail
-
wrapperfactory
protected java.util.function.BiFunction<IComponentIdentifier,SharedServiceFactory<T>,SharedService<T>> wrapperfactory
The wrapper creation function.
-
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.
-
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.
-
-