public class DependencyWaiterApplicationContextExecutor extends java.lang.Object implements OsgiBundleApplicationContextExecutor, ContextExecutorAccessor
ConfigurableApplicationContext.refresh() in two
pieces so that beans are not actually created unless the OSGi service imported are present.
Supports both asynch and synch behaviour.| Modifier and Type | Class and Description |
|---|---|
private class |
DependencyWaiterApplicationContextExecutor.CompleteRefreshTask
Create the Runnable action which will complete the context creation process.
|
private class |
DependencyWaiterApplicationContextExecutor.WatchDogTask
The task for the watch dog.
|
| Modifier and Type | Field and Description |
|---|---|
protected DelegatedExecutionOsgiBundleApplicationContext |
delegateContext |
private OsgiBundleApplicationContextEventMulticaster |
delegatedMulticaster
delegated multicaster
|
protected DependencyServiceManager |
dependencyDetector
OSGi service dependencyDetector used for detecting dependencies
|
private java.util.List<OsgiServiceDependencyFactory> |
dependencyFactories |
private static org.apache.commons.logging.Log |
log |
private java.lang.Object |
monitor
this class monitor.
|
private Counter |
monitorCounter
A synchronized counter used by the Listener to determine the number of children to wait for when shutting down.
|
private ContextState |
state
State of the associated context from the executor POV.
|
private boolean |
synchronousWait
Should the waiting be synchrous or not ?
|
private org.springframework.core.task.TaskExecutor |
taskExecutor |
private long |
timeout
waiting timeout
|
private Counter |
waitBarrier
Counter used when waiting for dependencies to appear
|
private java.util.Timer |
watchdog
the timer used for executing the timeout
|
private java.util.TimerTask |
watchdogTask
watchdog task
|
| Constructor and Description |
|---|
DependencyWaiterApplicationContextExecutor(DelegatedExecutionOsgiBundleApplicationContext delegateContext,
boolean syncWait,
java.util.List<OsgiServiceDependencyFactory> dependencyFactories) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
The application context is being shutdown.
|
protected DependencyServiceManager |
createDependencyServiceListener(java.lang.Runnable task) |
void |
fail(java.lang.Throwable t) |
private void |
fail(java.lang.Throwable t,
boolean skipEvent)
Fail creating the context.
|
private org.osgi.framework.Bundle |
getBundle() |
ContextState |
getContextState() |
private java.lang.String |
getDisplayName() |
OsgiBundleApplicationContextEventMulticaster |
getEventMulticaster() |
protected void |
init()
Do some sanity checks
|
private void |
logWrongState(ContextState expected)
Reduce the code pollution.
|
void |
refresh()
Provide a continuation like approach to the application context.
|
void |
setDelegatedMulticaster(OsgiBundleApplicationContextEventMulticaster multicaster)
Sets the multicaster for delegating failing events.
|
void |
setMonitoringCounter(Counter contextsStarted)
Pass in the context counter.
|
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExec) |
void |
setTimeout(long timeout)
Sets the timeout (in ms) for waiting for service dependencies.
|
void |
setWatchdog(java.util.Timer watchdog) |
protected void |
stageOne()
Start the first stage of the application context refresh.
|
protected void |
stageTwo() |
protected void |
startWatchDog()
Schedule the watchdog task.
|
protected void |
stopWatchDog() |
private void |
timeout()
Cancel waiting due to timeout.
|
private static final org.apache.commons.logging.Log log
private final java.lang.Object monitor
private long timeout
private java.util.Timer watchdog
private java.util.TimerTask watchdogTask
protected DependencyServiceManager dependencyDetector
protected final DelegatedExecutionOsgiBundleApplicationContext delegateContext
private ContextState state
private org.springframework.core.task.TaskExecutor taskExecutor
private Counter monitorCounter
private final boolean synchronousWait
private final Counter waitBarrier
private OsgiBundleApplicationContextEventMulticaster delegatedMulticaster
private java.util.List<OsgiServiceDependencyFactory> dependencyFactories
public DependencyWaiterApplicationContextExecutor(DelegatedExecutionOsgiBundleApplicationContext delegateContext, boolean syncWait, java.util.List<OsgiServiceDependencyFactory> dependencyFactories)
public void refresh()
throws org.springframework.beans.BeansException,
java.lang.IllegalStateException
refresh in interface OsgiBundleApplicationContextExecutororg.springframework.beans.BeansExceptionjava.lang.IllegalStateExceptionprotected void init()
protected void stageOne()
synchronousWait, the current thread can simply end if there are any dependencies (the
default) or wait to either timeout or have all its dependencies met.protected void stageTwo()
public void close()
close in interface OsgiBundleApplicationContextExecutorpublic void fail(java.lang.Throwable t)
fail in interface ContextExecutorAccessorprivate void fail(java.lang.Throwable t,
boolean skipEvent)
t - - the offending Throwable which caused our demiseprivate void timeout()
protected DependencyServiceManager createDependencyServiceListener(java.lang.Runnable task)
protected void startWatchDog()
protected void stopWatchDog()
public void setTimeout(long timeout)
timeout - public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExec)
private org.osgi.framework.Bundle getBundle()
private java.lang.String getDisplayName()
public void setWatchdog(java.util.Timer watchdog)
private void logWrongState(ContextState expected)
expected - the expected value for the context state.public void setMonitoringCounter(Counter contextsStarted)
asynchCounter - public void setDelegatedMulticaster(OsgiBundleApplicationContextEventMulticaster multicaster)
multicaster - public ContextState getContextState()
getContextState in interface ContextExecutorAccessorpublic OsgiBundleApplicationContextEventMulticaster getEventMulticaster()
getEventMulticaster in interface ContextExecutorAccessor