E - the type of object the container can carrypublic class BlockingObjectContainer<E> extends Object implements WritableObjectContainer<E>
This might be useful in server environments where the container (e.g. a CDI container) takes care about instantiation (at some time) but clients want or need to access the the instances from without the containers context (e.g. via plain old static getter calls).
| Constructor and Description |
|---|
BlockingObjectContainer()
Creates a new instance disallowing overwriting of an existing instance
|
BlockingObjectContainer(boolean allowOverwrite)
Creates a new instance with given setting for overwriting an existing
instance
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(E instance) |
E |
get()
Retrieves the instance waiting uninterruptibly until it is registered
(i.e. the waiting Thread will NOT react to
Thread.interrupt()
calls)
Attention: this call blocks FOREVER - so you REALLY should take care that
the requested instance is finally registered |
E |
get(long time,
TimeUnit timeUnit)
Retrieves the registered instance waiting interruptibly (i.e. the waiting
Thread will react to
Thread.interrupt() calls) until it is
registered or the given timeout has elapsed |
E |
getInterruptibly()
Retrieves the registered instance waiting interruptibly until it is
registered (i.e. the waiting Thread will react to
Thread.interrupt() calls)
Attention: this call block FOREVER (if not interrupted) - so you REALLY
should take care that the requested instance is finally registered |
E |
getNoWait()
Retrieves the instance if currently registered without potentially waiting
for it (i.e. the call will always return immediately)
|
boolean |
isAllowOverwrite() |
E |
remove() |
public BlockingObjectContainer(boolean allowOverwrite)
allowOverwrite - the setting for overwriting an existing instanceWritableObjectContainer.accept(Object),
WritableObjectContainer.isAllowOverwrite()public BlockingObjectContainer()
public boolean isAllowOverwrite()
isAllowOverwrite in interface WritableObjectContainer<E>public void accept(E instance) throws IllegalStateException
accept in interface Consumer<E>accept in interface WritableObjectContainer<E>IllegalStateExceptionpublic E remove()
remove in interface WritableObjectContainer<E>public E get()
Thread.interrupt()
calls)
Attention: this call blocks FOREVER - so you REALLY should take care that the requested instance is finally registered
public E getInterruptibly() throws InterruptedException
Thread.interrupt() calls)
Attention: this call block FOREVER (if not interrupted) - so you REALLY should take care that the requested instance is finally registered
InterruptedException - if the waiting Thread is interrupted while waitingpublic E get(long time, TimeUnit timeUnit) throws InterruptedException
Thread.interrupt() calls) until it is
registered or the given timeout has elapsedtime - the number of TimeUnits to wait at until the call
returnstimeUnit - the TimeUnit of the given time amount to waitInterruptedException - if the waiting Thread is interrupted while waitingpublic E getNoWait()
null if non is
registeredCopyright © 2017. All rights reserved.