import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
private Timeout pollTimeout;
private volatile boolean schedulingEnabled;
+ private volatile CONTEXT_STATE contextState;
StatisticsContextImpl(@CheckForNull final DeviceInfo deviceInfo, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor) {
this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
statisticsGatheringOnTheFlyService = new StatisticsGatheringOnTheFlyService(this, deviceContext);
itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
statListForCollectingInitialization();
+ contextState = CONTEXT_STATE.WORKING;
}
@Override
@Override
public void close() {
- schedulingEnabled = false;
- for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
- iterator.hasNext();) {
- RequestContextUtil.closeRequestContextWithRpcError(iterator.next(), CONNECTION_CLOSED);
- }
- if (null != pollTimeout && !pollTimeout.isExpired()) {
- pollTimeout.cancel();
+ if (CONTEXT_STATE.TERMINATION.equals(contextState)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Statistics context is already in state TERMINATION.");
+ }
+ } else {
+ contextState = CONTEXT_STATE.TERMINATION;
+ schedulingEnabled = false;
+ for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
+ iterator.hasNext(); ) {
+ RequestContextUtil.closeRequestContextWithRpcError(iterator.next(), CONNECTION_CLOSED);
+ }
+ if (null != pollTimeout && !pollTimeout.isExpired()) {
+ pollTimeout.cancel();
+ }
}
}
return itemLifeCycleListener;
}
+ @Override
+ public CONTEXT_STATE getState() {
+ return contextState;
+ }
}