Package com.tccc.kos.commons.util
Class AutowiredList<T>
java.lang.Object
java.util.concurrent.CopyOnWriteArrayList<T>
com.tccc.kos.commons.util.AutowiredList<T>
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<T>
,Collection<T>
,List<T>
,RandomAccess
- Direct Known Subclasses:
ListenerList
Specialized list class supports autowiring. When a bean with an
Autowired
AutowiredList
property that has been added
to a BeanContext
will cause the context to automatically add
any beans in the context of type <T>
to the list. If new child
contexts are added, any beans of type <T>
will also be added.
If a child context is destroyed, any beans from that context will
automatically be removed from the list. This effectively makes
AutowiredList
a dynamically updated alternative to calling
ctx.getBeans(T)
. In addition, since the list is updated during
context lifecycle events, access the contents of the list is very
efficient compared to querying the context.
While this is a List
, it is mutated exclusively using
add()
and remove()
within BeanContext
. These
methods are instrumented to allow notification callbacks when changes
are made to the list. Use setOnAdd()
and setOnRemove()
to receive notifications of changes to the list. While this can be
a very useful feature, be aware that the notifications will occur
during BeanContext
processing so it may be common that
beans are not fully configured or ready for use. In addition, any
processing in these callbacks will interrupt the BeanContext
process.
- Since:
- 1.0
- Version:
- 2022-08-30
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
getOnAdd()
boolean
void
setOnAdd
(AutowiredList.ChangeListener<T> onAdd) void
setOnRemove
(AutowiredList.ChangeListener<T> onRemove) Methods inherited from class java.util.concurrent.CopyOnWriteArrayList
add, addAll, addAll, addAllAbsent, addIfAbsent, clear, clone, contains, containsAll, equals, forEach, get, hashCode, indexOf, indexOf, isEmpty, iterator, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, removeAll, removeIf, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, toString
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
-
Constructor Details
-
AutowiredList
public AutowiredList()
-
-
Method Details
-
add
- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceList<T>
- Overrides:
add
in classCopyOnWriteArrayList<T>
-
remove
- Specified by:
remove
in interfaceCollection<T>
- Specified by:
remove
in interfaceList<T>
- Overrides:
remove
in classCopyOnWriteArrayList<T>
-
getOnAdd
-
getOnRemove
-
setOnAdd
-
setOnRemove
-