A
- The annotation typepublic abstract class AbstractConcurrentCustomScope<A extends java.lang.annotation.Annotation> extends java.lang.Object implements CustomScope<A>, LifeCycle<AbstractConcurrentCustomScope<A>>, java.lang.AutoCloseable
Note this implementation uses a singleReentrantReadWriteLock
to lock the entire scope hence it is designed for scopes that will hold a small amount of beans. For implementations that hold many beans it is recommended to use a lock per BeanIdentifier
.
Modifier | Constructor and Description |
---|---|
protected |
AbstractConcurrentCustomScope(java.lang.Class<A> annotationType)
A custom scope annotation.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<A> |
annotationType() |
abstract void |
close()
Implement the close logic for the scope.
|
protected void |
destroyScope(java.util.Map<BeanIdentifier,CreatedBean<?>> scopeMap)
Destroys the scope.
|
protected <T> CreatedBean<T> |
doCreate(BeanCreationContext<T> creationContext)
Perform creation.
|
<T> java.util.Optional<BeanRegistration<T>> |
findBeanRegistration(T bean)
Get the
BeanDefinition for the given bean. |
<T> T |
getOrCreate(BeanCreationContext<T> creationContext)
Resolve an object from the given scope.
|
protected abstract java.util.Map<BeanIdentifier,CreatedBean<?>> |
getScopeMap(boolean forCreation) |
protected void |
handleDestructionException(BeanDestructionException e)
Method that can be overridden to customize what happens on a shutdown error.
|
<T> java.util.Optional<T> |
remove(BeanIdentifier identifier)
Remove a bean definition from the scope.
|
AbstractConcurrentCustomScope<A> |
stop()
Stops the life cycle component.
|
protected AbstractConcurrentCustomScope(java.lang.Class<A> annotationType)
annotationType
- The annotation type@NonNull protected abstract java.util.Map<BeanIdentifier,CreatedBean<?>> getScopeMap(boolean forCreation)
forCreation
- Whether it is for creationjava.lang.IllegalStateException
- if the scope map cannot be obtained in the current contextpublic final java.lang.Class<A> annotationType()
annotationType
in interface CustomScope<A extends java.lang.annotation.Annotation>
public abstract void close()
close
in interface LifeCycle<AbstractConcurrentCustomScope<A extends java.lang.annotation.Annotation>>
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
@NonNull public final AbstractConcurrentCustomScope<A> stop()
LifeCycle
stop
in interface LifeCycle<AbstractConcurrentCustomScope<A extends java.lang.annotation.Annotation>>
protected void destroyScope(@Nullable java.util.Map<BeanIdentifier,CreatedBean<?>> scopeMap)
scopeMap
- Th scope mappublic final <T> T getOrCreate(BeanCreationContext<T> creationContext)
CustomScope
getOrCreate
in interface CustomScope<A extends java.lang.annotation.Annotation>
T
- The bean generic typecreationContext
- The creation context@NonNull protected <T> CreatedBean<T> doCreate(@NonNull BeanCreationContext<T> creationContext)
T
- The generic typecreationContext
- The creation contextpublic final <T> java.util.Optional<T> remove(BeanIdentifier identifier)
CustomScope
remove
in interface CustomScope<A extends java.lang.annotation.Annotation>
T
- The generic typeidentifier
- The BeanIdentifier
Optional
of the instance that was destroyed if it existsprotected void handleDestructionException(BeanDestructionException e)
e
- The exceptionpublic final <T> java.util.Optional<BeanRegistration<T>> findBeanRegistration(T bean)
CustomScope
BeanDefinition
for the given bean.findBeanRegistration
in interface CustomScope<A extends java.lang.annotation.Annotation>
T
- The bean generic typebean
- The bean