use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.RecoverKeyException in project open-smart-grid-platform by OSGP.
the class RecoverKeyProcess method run.
@Override
public void run() {
final DlmsDevice device = this.findDeviceAndCheckState();
log.info("[{}] Attempting key recovery for device {}", this.messageMetadata.getCorrelationUid(), this.deviceIdentification);
try {
// The process started in this try-catch block should only be stopped in the
// ThrottlingPermitDeniedException catch block. If a DeviceKeyProcessAlreadyRunningException
// is thrown the process was already started and should not be stopped. This method below
// could also throw a RecoverKeyException in this case the process wasn't started either
// The next try-catch block has a finally block to ensure stopping the process started here.
this.startProcessing(device);
if (!this.canConnectUsingNewKeys(device)) {
log.warn("[{}] Could not recover keys: could not connect to device {} using New keys", this.messageMetadata.getCorrelationUid(), this.deviceIdentification);
return;
}
} catch (final ThrottlingPermitDeniedException e) {
log.warn("RecoverKeyProcess could not connect to the device due to throttling constraints", e);
new Timer().schedule(new TimerTask() {
@Override
public void run() {
RecoverKeyProcess.this.run();
}
}, this.throttlingClientConfig.permitRejectedDelay().toMillis());
this.deviceKeyProcessingService.stopProcessing(this.deviceIdentification);
return;
} catch (final DeviceKeyProcessAlreadyRunningException e) {
log.info("RecoverKeyProcess could not be started while other key changing process is already running.");
new Timer().schedule(new TimerTask() {
@Override
public void run() {
RecoverKeyProcess.this.run();
}
}, this.deviceKeyProcessingService.getDeviceKeyProcessingTimeout().toMillis());
return;
}
try {
this.secretManagementService.activateNewKeys(this.messageMetadata, this.deviceIdentification, Arrays.asList(E_METER_ENCRYPTION, E_METER_AUTHENTICATION));
} catch (final Exception e) {
throw new RecoverKeyException(e);
} finally {
this.deviceKeyProcessingService.stopProcessing(this.deviceIdentification);
}
}
Aggregations