*/
package org.opendaylight.openflowplugin.impl.services;
+import com.google.common.util.concurrent.Service;
import java.util.Collections;
import java.util.List;
-import java.util.Objects;
-import org.opendaylight.openflowplugin.api.openflow.OFPContext.ContextState;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeader> extends AbstractMultipartRequestCallback<T> {
+public abstract class AbstractMultipartRequestOnTheFlyCallback<T extends OfHeader>
+ extends AbstractMultipartRequestCallback<T> {
private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipartRequestOnTheFlyCallback.class);
private final DeviceInfo deviceInfo;
private final EventIdentifier doneEventIdentifier;
private final TxFacade txFacade;
private final MultipartWriterProvider statisticsWriterProvider;
private final DeviceRegistry deviceRegistry;
- private volatile ContextState gatheringState = ContextState.INITIALIZATION;
- private ConvertorExecutor convertorExecutor;
+ private volatile Service.State gatheringState = Service.State.NEW;
+ private final ConvertorExecutor convertorExecutor;
public AbstractMultipartRequestOnTheFlyCallback(final RequestContext<List<T>> context, Class<?> requestType,
final DeviceContext deviceContext,
final ConvertorExecutor convertorExecutor) {
super(context, requestType, deviceContext, eventIdentifier);
deviceInfo = deviceContext.getDeviceInfo();
- doneEventIdentifier = new EventIdentifier(getMultipartType().name(), deviceContext.getDeviceInfo().getNodeId().toString());
+ doneEventIdentifier =
+ new EventIdentifier(getMultipartType().name(), deviceContext.getDeviceInfo().getNodeId().toString());
txFacade = deviceContext;
deviceRegistry = deviceContext;
this.statisticsWriterProvider = statisticsWriterProvider;
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "checkstyle:IllegalCatch"})
public void onSuccess(final OfHeader result) {
- if (Objects.isNull(result)) {
+ if (result == null) {
LOG.warn("Response received was null.");
- if (!ContextState.TERMINATION.equals(gatheringState)) {
+ if (!Service.State.TERMINATED.equals(gatheringState)) {
endCollecting(true);
}
return;
- } else if (ContextState.TERMINATION.equals(gatheringState)) {
- LOG.warn("Unexpected response received: xid={}, {}", result.getXid(), result.getImplementedInterface());
+ } else if (Service.State.TERMINATED.equals(gatheringState)) {
+ LOG.warn("Unexpected response received: xid={}, {}", result.getXid(), result.implementedInterface());
return;
}
} else {
final T resultCast = (T) result;
- if (ContextState.INITIALIZATION.equals(gatheringState)) {
+ if (Service.State.NEW.equals(gatheringState)) {
startCollecting();
}
.ifPresent(writer -> writer.write(reply, false));
} catch (final Exception ex) {
LOG.warn("Stats processing of type {} for node {} failed during write-to-tx step",
- getMultipartType(), deviceInfo.getLOGValue(), ex);
+ getMultipartType(), deviceInfo, ex);
}
});
} catch (final Exception ex) {
LOG.warn("Unexpected exception occurred while translating response: {}.", result.getClass(), ex);
setResult(RpcResultBuilder.<List<T>>failed().withError(RpcError.ErrorType.APPLICATION,
- String.format("Unexpected exception occurred while translating response: %s. %s", result.getClass(), ex)).build());
+ String.format("Unexpected exception occurred while translating response: %s. %s",
+ result.getClass(),
+ ex)).build());
endCollecting(false);
return;
}
}
/**
- * Get tx facade
+ * Get tx facade.
* @return tx facade
*/
protected TxFacade getTxFacade() {
}
/**
- * Starts collecting of multipart data
+ * Starts collecting of multipart data.
*/
private synchronized void startCollecting() {
EventsTimeCounter.markStart(doneEventIdentifier);
- gatheringState = ContextState.WORKING;
+ gatheringState = Service.State.RUNNING;
final InstanceIdentifier<FlowCapableNode> instanceIdentifier = deviceInfo
.getNodeInstanceIdentifier()
getTxFacade(),
instanceIdentifier,
deviceRegistry.getDeviceFlowRegistry());
+ deviceRegistry.getDeviceFlowRegistry().processMarks();
break;
case OFPMPMETERCONFIG:
StatisticsGatheringUtils.deleteAllKnownMeters(
getTxFacade(),
instanceIdentifier,
deviceRegistry.getDeviceMeterRegistry());
+ deviceRegistry.getDeviceMeterRegistry().processMarks();
break;
case OFPMPGROUPDESC:
StatisticsGatheringUtils.deleteAllKnownGroups(
getTxFacade(),
instanceIdentifier,
deviceRegistry.getDeviceGroupRegistry());
+ deviceRegistry.getDeviceGroupRegistry().processMarks();
break;
+ default:
+ // no operation
}
}
/**
- * Ends collecting of multipart data
+ * Ends collecting of multipart data.
* @param setResult set empty success result
*/
private void endCollecting(final boolean setResult) {
- gatheringState = ContextState.TERMINATION;
+ gatheringState = Service.State.TERMINATED;
EventsTimeCounter.markEnd(doneEventIdentifier);
EventsTimeCounter.markEnd(getEventIdentifier());
spyMessage(MessageSpy.StatisticsGroup.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
case OFPMPGROUPDESC:
deviceRegistry.getDeviceGroupRegistry().processMarks();
break;
+ default:
+ // no operation
}
}
/**
- * Get multipart type
+ * Get multipart type.
* @return multipart type
*/
protected abstract MultipartType getMultipartType();
-
}