A
- The annotation typepublic abstract class AbstractConcurrentCustomScope<A extends Annotation> extends Object implements CustomScope<A>, LifeCycle<AbstractConcurrentCustomScope<A>>, 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(Class<A> annotationType)
A custom scope annotation.
|
Modifier and Type | Method and Description |
---|---|
Class<A> |
annotationType() |
abstract void |
close()
Implement the close logic for the scope.
|
protected void |
destroyScope(Map<BeanIdentifier,CreatedBean<?>> scopeMap)
Destroys the scope.
|
protected <T> CreatedBean<T> |
doCreate(BeanCreationContext<T> creationContext)
Perform creation.
|
<T> 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 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> Optional<T> |
remove(BeanIdentifier identifier)
Remove a bean definition from the scope.
|
AbstractConcurrentCustomScope<A> |
stop()
Stops the life cycle component.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
findBeanRegistration
@NonNull protected abstract Map<BeanIdentifier,CreatedBean<?>> getScopeMap(boolean forCreation)
forCreation
- Whether it is for creationIllegalStateException
- if the scope map cannot be obtained in the current contextpublic final Class<A> annotationType()
annotationType
in interface CustomScope<A extends Annotation>
public abstract void close()
close
in interface LifeCycle<AbstractConcurrentCustomScope<A extends Annotation>>
close
in interface Closeable
close
in interface AutoCloseable
@NonNull public final AbstractConcurrentCustomScope<A> stop()
LifeCycle
stop
in interface LifeCycle<AbstractConcurrentCustomScope<A extends Annotation>>
protected void destroyScope(@Nullable Map<BeanIdentifier,CreatedBean<?>> scopeMap)
scopeMap
- Th scope mappublic final <T> T getOrCreate(BeanCreationContext<T> creationContext)
CustomScope
getOrCreate
in interface CustomScope<A extends 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> Optional<T> remove(BeanIdentifier identifier)
CustomScope
remove
in interface CustomScope<A extends 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> Optional<BeanRegistration<T>> findBeanRegistration(T bean)
CustomScope
BeanDefinition
for the given bean.findBeanRegistration
in interface CustomScope<A extends Annotation>
T
- The bean generic typebean
- The bean