Skip to content
Snippets Groups Projects
Commit 55ec05c6 authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

synchronized access occurs on a smaller code block (CONTROLGUI-389, PROBLEM-2297)

parent 55576af4
No related branches found
No related tags found
No related merge requests found
......@@ -666,8 +666,8 @@ public class CurrentScanDataModel {
return isSpectrum;
}
protected static void setAttributeInfoNoLock(DeviceProxy proxy, AttributeInfo attributeInfo) throws DevFailed {
proxy.set_attribute_info(new AttributeInfo[] { attributeInfo });
protected static void setAttributeInfoNoLock(DeviceProxy proxy, AttributeInfo... attributeInfo) throws DevFailed {
proxy.set_attribute_info(attributeInfo);
}
public static String readAttributeLabel(String scanServerName, String attributeName) {
......@@ -886,22 +886,17 @@ public class CurrentScanDataModel {
}
}
private static void updateNexusInfoNoLock(String scanServerName, DeviceProxy scanProxy) {
try {
private static boolean isDataRecorded(DeviceProxy scanProxy) throws DevFailed {
DeviceAttribute attribute = scanProxy.read_attribute(DATA_RECORDED);
boolean dataRecorded = attribute.extractBoolean();
if (dataRecorded) {
return attribute.extractBoolean();
}
private static String readNexusFieName(String scanServerName, DeviceProxy scanProxy, int tryCount)
throws DevFailed {
String nexusFileName = null;
long startSTMP = System.currentTimeMillis();
long durationTry = 0;
int tryCount = 0;
while ((durationTry < 5000) && ((nexusFileName == null) || nexusFileName.isEmpty())) {
try {
tryCount++;
attribute = scanProxy.read_attribute(NEXUS_FILE);
DeviceAttribute attribute = scanProxy.read_attribute(NEXUS_FILE);
if (attribute == null) {
LOGGER.error(CANNOT_READ_ATTRIBUTE_RETURNED_ATTRIBUTE_IS_NULL_TRY_NB, scanServerName,
NEXUS_FILE, tryCount);
LOGGER.error(CANNOT_READ_ATTRIBUTE_RETURNED_ATTRIBUTE_IS_NULL_TRY_NB, scanServerName, NEXUS_FILE, tryCount);
} else {
nexusFileName = attribute.extractString();
if (nexusFileName == null) {
......@@ -913,6 +908,40 @@ public class CurrentScanDataModel {
LOGGER.info(VALUE_EQUALS, scanServerName, NEXUS_FILE, nexusFileName);
}
}
return nexusFileName;
}
private static void updateNexusInfo(String scanServerName) {
if (scanServerName != null) {
NEXUS_FILE_NAME_MAP.remove(scanServerName.toLowerCase());
NEXUS_FILE_ENTRY_MAP.remove(scanServerName.toLowerCase());
if (TangoAttributeHelper.isAttributeRunning(scanServerName, NEXUS_FILE)) {
// Read the property of DataRecorder = storage/recorder/datarecorder.1/
DeviceProxy scanProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
if (scanProxy != null) {
try {
boolean dataRecorded;
if (isSynchronizeDeviceAccesses()) {
synchronized (scanProxy) {
dataRecorded = isDataRecorded(scanProxy);
}
} else {
dataRecorded = isDataRecorded(scanProxy);
}
if (dataRecorded) {
String nexusFileName = null;
long startSTMP = System.currentTimeMillis();
long durationTry = 0;
int tryCount = 0;
while ((durationTry < 5000) && ((nexusFileName == null) || nexusFileName.isEmpty())) {
try {
if (isSynchronizeDeviceAccesses()) {
synchronized (scanProxy) {
nexusFileName = readNexusFieName(scanServerName, scanProxy, ++tryCount);
}
} else {
nexusFileName = readNexusFieName(scanServerName, scanProxy, ++tryCount);
}
} catch (Exception e) {
LOGGER.error(CANNOT_READ_ATTRIBUTE_N_TRY_NB, scanServerName, NEXUS_FILE,
TangoExceptionHelper.getErrorMessage(e), tryCount);
......@@ -931,7 +960,8 @@ public class CurrentScanDataModel {
if (nexusFileName.isEmpty()) {
if (durationTry >= 5000) {
LOGGER.warn(NO_NEXUS_FILE_GENERATED_IT_TOOK_TOO_MUCH_TIME, scanServerName, NEXUS_FILE);
LOGGER.warn(NO_NEXUS_FILE_GENERATED_IT_TOOK_TOO_MUCH_TIME, scanServerName,
NEXUS_FILE);
} else {
LOGGER.warn(NO_NEXUS_FILE_GENERATED);
}
......@@ -947,7 +977,8 @@ public class CurrentScanDataModel {
}
if (TangoDeviceHelper.isDeviceRunning(dataRecorderDeviceName)) {
DeviceProxy dataRecorderProxy = TangoDeviceHelper.getDeviceProxy(dataRecorderDeviceName);
DeviceProxy dataRecorderProxy = TangoDeviceHelper
.getDeviceProxy(dataRecorderDeviceName);
if (dataRecorderProxy != null) {
if (isSynchronizeDeviceAccesses()) {
synchronized (dataRecorderProxy) {
......@@ -965,24 +996,6 @@ public class CurrentScanDataModel {
LOGGER.debug(STACK_TRACE, e);
}
}
private static void updateNexusInfo(String scanServerName) {
if (scanServerName != null) {
NEXUS_FILE_NAME_MAP.remove(scanServerName.toLowerCase());
NEXUS_FILE_ENTRY_MAP.remove(scanServerName.toLowerCase());
if (TangoAttributeHelper.isAttributeRunning(scanServerName, NEXUS_FILE)) {
// Read the property of DataRecorder = storage/recorder/datarecorder.1/
DeviceProxy scanProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
if (scanProxy != null) {
if (isSynchronizeDeviceAccesses()) {
// XXX maybe the synchronized access should not occur on such a big code block
synchronized (scanProxy) {
updateNexusInfoNoLock(scanServerName, scanProxy);
}
} else {
updateNexusInfoNoLock(scanServerName, scanProxy);
}
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment