diff --git a/common/src/main/java/org/tango/utils/DevFailedUtils.java b/common/src/main/java/org/tango/utils/DevFailedUtils.java
index 0c8d8d37..c96f9315 100644
--- a/common/src/main/java/org/tango/utils/DevFailedUtils.java
+++ b/common/src/main/java/org/tango/utils/DevFailedUtils.java
@@ -1,14 +1,13 @@
package org.tango.utils;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import fr.esrf.Tango.DevError;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.ErrSeverity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
public final class DevFailedUtils {
private static final String TANGO_ERROR = "TANGO_ERROR";
@@ -62,7 +61,7 @@ public static DevError[] buildDevError(final String reason, final String desc, f
return err;
}
- public static DevFailed newDevFailed(final Throwable origin) throws DevFailed {
+ public static DevFailed newDevFailed(final Throwable origin) {
final DevError[] err = new DevError[1];
err[0] = new DevError();
err[0].desc = origin.getClass().getCanonicalName();
diff --git a/server/src/main/java/org/tango/server/monitoring/DeviceMonitoring.java b/server/src/main/java/org/tango/server/monitoring/DeviceMonitoring.java
index 9ac53449..57d44ab1 100644
--- a/server/src/main/java/org/tango/server/monitoring/DeviceMonitoring.java
+++ b/server/src/main/java/org/tango/server/monitoring/DeviceMonitoring.java
@@ -1,77 +1,91 @@
-/**
- * Copyright (C) : 2012
- *
- * Synchrotron Soleil
- * L'Orme des merisiers
- * Saint Aubin
- * BP48
- * 91192 GIF-SUR-YVETTE CEDEX
- *
- * This file is part of Tango.
- *
- * Tango is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Tango is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Tango. If not, see .
- */
-package org.tango.server.monitoring;
-
-import org.tango.server.history.DeviceBlackBox;
-
-import fr.esrf.Tango.ClntIdent;
-import fr.esrf.Tango.DevFailed;
-import fr.esrf.Tango.DevSource;
-
-public class DeviceMonitoring {
- private static final String SEPARATOR = " - ";
- private final String deviceName;
- private final DeviceBlackBox blackbox;
- private final TangoStats monitoring;
-
- public DeviceMonitoring(final String deviceName) {
- this.deviceName = deviceName;
- blackbox = new DeviceBlackBox();
- monitoring = TangoStats.getInstance();
- }
-
- public long startRequest(final String request) {
- blackbox.insertInblackBox(request);
- return monitoring.addRequest(deviceName + SEPARATOR + request);
- }
-
- public long startRequest(final String request, final ClntIdent clt) {
- blackbox.insertInblackBox(request, clt);
- return monitoring.addRequest(deviceName + SEPARATOR + request);
- }
-
- public long startRequest(final String request, final DevSource devSource) {
- blackbox.insertInblackBox(request, devSource);
- return monitoring.addRequest(deviceName + SEPARATOR + request);
- }
-
- public long startRequest(final String request, final DevSource devSource, final ClntIdent clt) {
- blackbox.insertInblackBox(request, devSource, clt);
- return monitoring.addRequest(deviceName + SEPARATOR + request);
- }
-
- public void addError() {
- monitoring.addError();
- }
-
- public void endRequest(final long id) {
- monitoring.endRequest(id);
- }
-
- public String[] getBlackBox(final int size) throws DevFailed {
- return blackbox.toArray(size);
- }
-
-}
+/**
+ * Copyright (C) : 2012
+ *
+ * Synchrotron Soleil
+ * L'Orme des merisiers
+ * Saint Aubin
+ * BP48
+ * 91192 GIF-SUR-YVETTE CEDEX
+ *
+ * This file is part of Tango.
+ *
+ * Tango is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Tango is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Tango. If not, see .
+ */
+package org.tango.server.monitoring;
+
+import fr.esrf.Tango.ClntIdent;
+import fr.esrf.Tango.DevFailed;
+import fr.esrf.Tango.DevSource;
+import org.tango.server.history.DeviceBlackBox;
+
+import java.io.Closeable;
+
+public class DeviceMonitoring {
+ private static final String SEPARATOR = " - ";
+ private final String deviceName;
+ private final DeviceBlackBox blackbox;
+ private final TangoStats monitoring;
+
+ public DeviceMonitoring(final String deviceName) {
+ this.deviceName = deviceName;
+ blackbox = new DeviceBlackBox();
+ monitoring = TangoStats.getInstance();
+ }
+
+ public Request startRequest(final String request) {
+ blackbox.insertInblackBox(request);
+ return new Request(deviceName + SEPARATOR + request);
+ }
+
+ public Request startRequest(final String request, final ClntIdent clt) {
+ blackbox.insertInblackBox(request, clt);
+ return new Request(deviceName + SEPARATOR + request);
+ }
+
+ public Request startRequest(final String request, final DevSource devSource) {
+ blackbox.insertInblackBox(request, devSource);
+ return new Request(deviceName + SEPARATOR + request);
+ }
+
+ public Request startRequest(final String request, final DevSource devSource, final ClntIdent clt) {
+ blackbox.insertInblackBox(request, devSource, clt);
+ return new Request(deviceName + SEPARATOR + request);
+ }
+
+ public void addError() {
+ monitoring.addError();
+ }
+
+ public void endRequest(final long id) {
+ monitoring.endRequest(id);
+ }
+
+ public String[] getBlackBox(final int size) throws DevFailed {
+ return blackbox.toArray(size);
+ }
+
+ public class Request implements Closeable {
+ public final long id;
+
+ Request(String request) {
+ this.id = monitoring.addRequest(request);
+ }
+
+ @Override
+ public void close() {
+ monitoring.endRequest(id);
+ }
+ }
+
+}
diff --git a/server/src/main/java/org/tango/server/servant/DeviceImpl.java b/server/src/main/java/org/tango/server/servant/DeviceImpl.java
index bd5dea17..3ae5a40e 100644
--- a/server/src/main/java/org/tango/server/servant/DeviceImpl.java
+++ b/server/src/main/java/org/tango/server/servant/DeviceImpl.java
@@ -24,34 +24,7 @@
*/
package org.tango.server.servant;
-import fr.esrf.Tango.AttributeConfig;
-import fr.esrf.Tango.AttributeConfig_2;
-import fr.esrf.Tango.AttributeConfig_3;
-import fr.esrf.Tango.AttributeConfig_5;
-import fr.esrf.Tango.AttributeValue;
-import fr.esrf.Tango.AttributeValue_3;
-import fr.esrf.Tango.AttributeValue_4;
-import fr.esrf.Tango.AttributeValue_5;
-import fr.esrf.Tango.ClntIdent;
-import fr.esrf.Tango.DevAttrHistory;
-import fr.esrf.Tango.DevAttrHistory_3;
-import fr.esrf.Tango.DevAttrHistory_4;
-import fr.esrf.Tango.DevAttrHistory_5;
-import fr.esrf.Tango.DevCmdHistory;
-import fr.esrf.Tango.DevCmdHistory_4;
-import fr.esrf.Tango.DevCmdInfo;
-import fr.esrf.Tango.DevCmdInfo_2;
-import fr.esrf.Tango.DevFailed;
-import fr.esrf.Tango.DevInfo;
-import fr.esrf.Tango.DevInfo_3;
-import fr.esrf.Tango.DevIntrChange;
-import fr.esrf.Tango.DevPipeData;
-import fr.esrf.Tango.DevSource;
-import fr.esrf.Tango.DevState;
-import fr.esrf.Tango.DevVarLongStringArray;
-import fr.esrf.Tango.Device_5POA;
-import fr.esrf.Tango.MultiDevFailed;
-import fr.esrf.Tango.PipeConfig;
+import fr.esrf.Tango.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.omg.CORBA.Any;
@@ -69,29 +42,15 @@
import org.tango.server.InvocationContext.CallType;
import org.tango.server.InvocationContext.ContextType;
import org.tango.server.ServerManager;
-import org.tango.server.annotation.AroundInvoke;
-import org.tango.server.annotation.Attribute;
-import org.tango.server.annotation.ClassProperty;
-import org.tango.server.annotation.Command;
-import org.tango.server.annotation.Delete;
import org.tango.server.annotation.Device;
-import org.tango.server.annotation.DeviceProperties;
-import org.tango.server.annotation.DeviceProperty;
-import org.tango.server.annotation.Init;
-import org.tango.server.annotation.State;
-import org.tango.server.annotation.Status;
-import org.tango.server.annotation.TransactionType;
+import org.tango.server.annotation.*;
import org.tango.server.attribute.AttributeImpl;
import org.tango.server.attribute.AttributePropertiesImpl;
import org.tango.server.attribute.ForwardedAttribute;
import org.tango.server.cache.PollingManager;
import org.tango.server.cache.TangoCacheManager;
import org.tango.server.command.CommandImpl;
-import org.tango.server.device.AroundInvokeImpl;
-import org.tango.server.device.DeviceLocker;
-import org.tango.server.device.InitImpl;
-import org.tango.server.device.StateImpl;
-import org.tango.server.device.StatusImpl;
+import org.tango.server.device.*;
import org.tango.server.events.DeviceInterfaceChangedSender;
import org.tango.server.idl.CleverAnyCommand;
import org.tango.server.idl.TangoIDLAttributeUtil;
@@ -108,14 +67,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -800,22 +752,19 @@ private synchronized void checkInitialization() throws DevFailed {
* @throws DevFailed
*/
@Override
- public DevInfo info() throws DevFailed {
+ public DevInfo info() {
MDC.setContextMap(contextMap);
xlogger.entry();
- long id = deviceMonitoring.startRequest("Operation info");
- final DevInfo info = new DevInfo();
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("Operation info")) {
+ final DevInfo info = new DevInfo();
info.dev_class = className;
info.doc_url = "Doc URL = http://www.tango-controls.org";
info.server_host = ServerManager.getInstance().getHostName();
info.server_id = ServerManager.getInstance().getServerName();
info.server_version = SERVER_VERSION;
- } finally {
- deviceMonitoring.endRequest(id);
+ xlogger.exit();
+ return info;
}
- xlogger.exit();
- return info;
}
/**
@@ -828,9 +777,8 @@ public DevInfo info() throws DevFailed {
public DevInfo_3 info_3() throws DevFailed {
MDC.setContextMap(contextMap);
xlogger.entry();
- long id = deviceMonitoring.startRequest("Operation info_3");
- final DevInfo_3 info3 = new DevInfo_3();
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("Operation info_3")) {
+ final DevInfo_3 info3 = new DevInfo_3();
final DevInfo info = info();
info3.dev_class = info.dev_class;
info3.doc_url = info.doc_url;
@@ -838,11 +786,9 @@ public DevInfo_3 info_3() throws DevFailed {
info3.server_id = info.server_id;
info3.server_version = info.server_version;
info3.dev_type = deviceType;
- } finally {
- deviceMonitoring.endRequest(id);
+ xlogger.exit();
+ return info3;
}
- xlogger.exit();
- return info3;
}
/**
@@ -854,7 +800,7 @@ public DevInfo_3 info_3() throws DevFailed {
public void ping() throws DevFailed {
MDC.setContextMap(contextMap);
xlogger.entry();
- deviceMonitoring.endRequest(deviceMonitoring.startRequest("Operation ping"));
+ deviceMonitoring.endRequest(deviceMonitoring.startRequest("Operation ping").id);
xlogger.exit();
}
@@ -865,7 +811,7 @@ public void ping() throws DevFailed {
public String adm_name() {
MDC.setContextMap(contextMap);
xlogger.entry();
- deviceMonitoring.endRequest(deviceMonitoring.startRequest("Attribute adm_name"));
+ deviceMonitoring.endRequest(deviceMonitoring.startRequest("Attribute adm_name").id);
xlogger.exit();
return getAdminDeviceName();
}
@@ -901,13 +847,13 @@ public String[] black_box(final int maxSize) throws DevFailed {
public String description() {
MDC.setContextMap(contextMap);
xlogger.entry();
- long id = deviceMonitoring.startRequest("Attribute description requested");
- String desc = "A TANGO device";
- if (name.equalsIgnoreCase(ServerManager.getInstance().getAdminDeviceName())) {
- desc = "A device server device !!";
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("Attribute description requested")) {
+ String desc = "A TANGO device";
+ if (name.equalsIgnoreCase(ServerManager.getInstance().getAdminDeviceName())) {
+ desc = "A device server device !!";
+ }
+ return desc;
}
- deviceMonitoring.endRequest(id);
- return desc;
}
/**
@@ -918,12 +864,9 @@ public String description() {
@Override
public String name() {
MDC.setContextMap(contextMap);
- long id = deviceMonitoring.startRequest("Device name");
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("Device name")) {
xlogger.entry();
return name;
- } finally {
- deviceMonitoring.endRequest(id);
}
}
@@ -940,12 +883,9 @@ public DevAttrHistory[] read_attribute_history_2(final String attributeName, fin
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("read_attribute_history_2");
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attribute_history_2")) {
// TODO read_attribute_history_2
return new DevAttrHistory[0];
- } finally {
- deviceMonitoring.endRequest(id);
}
}
@@ -963,11 +903,8 @@ public DevAttrHistory_3[] read_attribute_history_3(final String attributeName, f
xlogger.entry();
// TODO read_attribute_history_3
checkInitialization();
- long id = deviceMonitoring.startRequest("read_attribute_history_3");
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attribute_history_3")) {
return new DevAttrHistory_3[0];
- } finally {
- deviceMonitoring.endRequest(id);
}
}
@@ -984,25 +921,15 @@ public DevAttrHistory_4 read_attribute_history_4(final String attributeName, fin
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("read_attribute_history_4");
DevAttrHistory_4 result = null;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attribute_history_4")) {
final AttributeImpl attr = AttributeGetterSetter.getAttribute(attributeName, attributeList);
if (!attr.isPolled()) {
throw DevFailedUtils.newDevFailed(ExceptionMessages.ATTR_NOT_POLLED, attr.getName() + " is not polled");
}
result = attr.getHistory().getAttrHistory4(maxSize);
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
return result;
}
@@ -1016,36 +943,19 @@ public DevAttrHistory_4 read_attribute_history_4(final String attributeName, fin
*/
@Override
public AttributeValue[] read_attributes(final String[] attributeNames) throws DevFailed {
- MDC.setContextMap(contextMap);
- xlogger.entry();
- if (attributeNames.length != 1 || !attributeNames[0].equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !attributeNames[0].equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
+ pre_attributes(attributeNames, null);
+
+ if (attributeNames.length == 0) {
+ throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
}
- long id = deviceMonitoring.startRequest("read_attributes");
- AttributeValue[] result = null;
- try {
- clientIdentity.set(null);
- if (attributeNames.length == 0) {
- throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
- }
- try {
- result = AttributeGetterSetter.getAttributesValues(name, attributeNames, pollingManager, attributeList,
- aroundInvokeImpl, DevSource.CACHE_DEV, deviceLock, null);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attributes " + Arrays.toString(attributeNames))) {
+ AttributeValue[] result = AttributeGetterSetter.getAttributesValues(name, attributeNames, pollingManager, attributeList,
+ aroundInvokeImpl, DevSource.CACHE_DEV, deviceLock, null);
+ return result;
+ } catch (final Exception e) {
+ throw handleException(e);
}
- return result;
+
}
/**
@@ -1058,38 +968,19 @@ public AttributeValue[] read_attributes(final String[] attributeNames) throws De
*/
@Override
public AttributeValue[] read_attributes_2(final String[] names, final DevSource source) throws DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry();
- if (names.length != 1 || !names[0].equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !names[0].equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
- }
- long id = deviceMonitoring.startRequest("read_attributes_2", source);
- AttributeValue[] result = null;
- try {
- clientIdentity.set(null);
- if (names.length == 0) {
- throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
- }
- try {
- result = AttributeGetterSetter.getAttributesValues(name, names, pollingManager, attributeList,
- aroundInvokeImpl, source, deviceLock, null);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ pre_attributes(names, null);
+ if (names.length == 0) {
+ throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
+ }
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attributes_2", source)) {
+ AttributeValue[] result = AttributeGetterSetter.getAttributesValues(name, names, pollingManager, attributeList,
+ aroundInvokeImpl, source, deviceLock, null);
+ xlogger.exit();
+ return result;
+ } catch (final Exception e) {
+ throw handleException(e);
}
-
- xlogger.exit();
- return result;
}
/**
@@ -1102,38 +993,19 @@ public AttributeValue[] read_attributes_2(final String[] names, final DevSource
*/
@Override
public AttributeValue_3[] read_attributes_3(final String[] names, final DevSource source) throws DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry();
- if (names.length != 1 || !names[0].equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !names[0].equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
- }
- long id = deviceMonitoring.startRequest("read_attributes_3", source);
- AttributeValue_3[] result = null;
- try {
- clientIdentity.set(null);
- if (names.length == 0) {
- throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
- }
- try {
- result = AttributeGetterSetter.getAttributesValues3(name, names, pollingManager, attributeList,
- aroundInvokeImpl, source, deviceLock, null);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
-
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ pre_attributes(names, null);
+ if (names.length == 0) {
+ throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
+ }
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attributes_3", source)) {
+ AttributeValue_3[] result = AttributeGetterSetter.getAttributesValues3(name, names, pollingManager, attributeList,
+ aroundInvokeImpl, source, deviceLock, null);
+ xlogger.exit();
+ return result;
+ } catch (final Exception e) {
+ throw handleException(e);
}
- xlogger.exit();
- return result;
}
/**
@@ -1150,41 +1022,21 @@ public AttributeValue_4[] read_attributes_4(final String[] names, final DevSourc
throws DevFailed {
// final Profiler profilerPeriod = new Profiler("period");
// profilerPeriod.start(Arrays.toString(names));
- MDC.setContextMap(contextMap);
xlogger.entry(Arrays.toString(names));
- if (names.length != 1 || !names[0].equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !names[0].equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
+ pre_attributes(names, clIdent);
+ if (names.length == 0) {
+ throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
}
- long id = deviceMonitoring.startRequest("read_attributes_4 " + Arrays.toString(names), source, clIdent);
- AttributeValue_4[] result = null;
- try {
- clientIdentity.set(clIdent);
- if (names.length == 0) {
- throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
- }
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, names);
- }
- try {
- result = AttributeGetterSetter.getAttributesValues4(name, names, pollingManager, attributeList,
- aroundInvokeImpl, source, deviceLock, clIdent);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- }
- } finally {
- deviceMonitoring.endRequest(id);
+
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attributes_4 " + Arrays.toString(names), source, clIdent)) {
+ AttributeValue_4[] result = AttributeGetterSetter.getAttributesValues4(name, names, pollingManager, attributeList,
+ aroundInvokeImpl, source, deviceLock, clIdent);
+ xlogger.exit();
+ // profilerPeriod.stop().print();
+ return result;
+ } catch (final Exception e) {
+ throw handleException(e);
}
- xlogger.exit();
- // profilerPeriod.stop().print();
- return result;
}
/**
@@ -1199,49 +1051,25 @@ public AttributeValue_4[] read_attributes_4(final String[] names, final DevSourc
@Override
public AttributeValue_5[] read_attributes_5(final String[] names, final DevSource source, final ClntIdent clIdent)
throws DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry(Arrays.toString(names));
+ pre_attributes(names, clIdent);
// final Profiler profiler = new Profiler("read time");
// profiler.start(Arrays.toString(names));
- if (names.length != 1 || !names[0].equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !names[0].equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
+ if (names.length == 0) {
+ throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
}
// profiler.start("blackbox");
- long id = deviceMonitoring.startRequest("read_attributes_5 " + Arrays.toString(names), source, clIdent);
- AttributeValue_5[] result = null;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attributes_5 " + Arrays.toString(names), source, clIdent)) {
// profiler.start("locking");
- clientIdentity.set(clIdent);
- if (names.length == 0) {
- throw DevFailedUtils.newDevFailed(READ_ERROR, READ_ASKED_FOR_0_ATTRIBUTES);
- }
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, names);
- }
-
- try {
- // profiler.start("get value");
- result = AttributeGetterSetter.getAttributesValues5(name, names, pollingManager, attributeList,
- aroundInvokeImpl, source, deviceLock, clIdent);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ AttributeValue_5[] result = AttributeGetterSetter.getAttributesValues5(name, names, pollingManager, attributeList,
+ aroundInvokeImpl, source, deviceLock, clIdent);
+ // profiler.stop().print();
+ xlogger.exit();
+ return result;
+ } catch (final Exception e) {
+ throw handleException(e);
}
-
- // profiler.stop().print();
- xlogger.exit();
- return result;
}
/**
@@ -1252,34 +1080,21 @@ public AttributeValue_5[] read_attributes_5(final String[] names, final DevSourc
*/
@Override
public void write_attributes(final AttributeValue[] values) throws DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry();
- checkInitialization();
- long id = deviceMonitoring.startRequest("write_attributes");
- try {
- clientIdentity.set(null);
- final String[] names = new String[values.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = values[i].name;
- logger.debug("writing {}", names[i]);
- }
- final Object lock = deviceLock.getAttributeLock();
- try {
- synchronized (lock != null ? lock : new Object()) {
- AttributeGetterSetter.setAttributeValue(values, attributeList, stateImpl, aroundInvokeImpl, null);
- }
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
+
+ //TODO Java 8
+// final String[] names = Arrays.stream(values).map(attributeValue -> attributeValue.name).toArray(String[]::new);
+
+ String[] names = getNames(values);
+ pre_attributes(names, null);
+ final Object lock = deviceLock.getAttributeLock();
+ logger.debug("writing {}", Arrays.toString(names));
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_attributes")) {
+ synchronized (lock != null ? lock : new Object()) {
+ AttributeGetterSetter.setAttributeValue(values, attributeList, stateImpl, aroundInvokeImpl, null);
}
- } finally {
- deviceMonitoring.endRequest(id);
+ } catch (final Exception e) {
+ throw handleException(e);
}
xlogger.exit();
}
@@ -1291,39 +1106,42 @@ public void write_attributes(final AttributeValue[] values) throws DevFailed {
* @throws DevFailed
*/
@Override
- public void write_attributes_3(final AttributeValue[] values) throws MultiDevFailed, DevFailed {
- MDC.setContextMap(contextMap);
+ public void write_attributes_3(final AttributeValue[] values) throws DevFailed {
xlogger.entry();
- checkInitialization();
- long id = deviceMonitoring.startRequest("write_attributes_3");
- try {
- clientIdentity.set(null);
- final String[] names = new String[values.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = values[i].name;
- logger.debug("writing {}", names[i]);
- }
- final Object lock = deviceLock.getAttributeLock();
- try {
- synchronized (lock != null ? lock : new Object()) {
- AttributeGetterSetter.setAttributeValue(values, attributeList, stateImpl, aroundInvokeImpl, null);
- }
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
+ String[] names = getNames(values);
+ pre_attributes(names, null);
+ logger.debug("writing {}", Arrays.toString(names));
+ final Object lock = deviceLock.getAttributeLock();
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_attributes_3")) {
+ synchronized (lock != null ? lock : new Object()) {
+ AttributeGetterSetter.setAttributeValue(values, attributeList, stateImpl, aroundInvokeImpl, null);
}
- } finally {
- deviceMonitoring.endRequest(id);
+ } catch (final Exception e) {
+ throw handleException(e);
}
xlogger.exit();
}
+ private String[] getNames(AttributeValue[] values) {
+ //TODO Java 8
+// String[] names = Arrays.stream(values).map(attributeValue -> attributeValue.name).toArray(String[]::new);
+ String[] names = new String[values.length];
+ for (int i = 0; i < values.length; ++i) {
+ names[i] = values[i].name;
+ }
+ return names;
+ }
+
+ private String[] getNames(AttributeValue_4[] values) {
+ //TODO Java 8
+// String[] names = Arrays.stream(values).map(attributeValue -> attributeValue.name).toArray(String[]::new);
+ String[] names = new String[values.length];
+ for (int i = 0; i < values.length; ++i) {
+ names[i] = values[i].name;
+ }
+ return names;
+ }
+
/**
* Write some attributes. IDL 4 version
*
@@ -1334,37 +1152,19 @@ public void write_attributes_3(final AttributeValue[] values) throws MultiDevFai
@Override
public void write_attributes_4(final AttributeValue_4[] values, final ClntIdent clIdent) throws MultiDevFailed,
DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry();
- checkInitialization();
- final String[] names = new String[values.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = values[i].name;
- }
+ //TODO Java 8
+// String[] names = Arrays.stream(values).map(attributeValue_4 -> attributeValue_4.name).toArray(String[]::new);
+ String[] names = getNames(values);
+ pre_attributes(names, clIdent);
logger.debug("writing {}", Arrays.toString(names));
- long id = deviceMonitoring.startRequest("write_attributes_4 " + Arrays.toString(names), clIdent);
- try {
- clientIdentity.set(clIdent);
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, names);
- }
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_attributes_4 " + Arrays.toString(names), clIdent)) {
final Object lock = deviceLock.getAttributeLock();
- try {
- synchronized (lock != null ? lock : new Object()) {
- AttributeGetterSetter.setAttributeValue4(values, attributeList, stateImpl, aroundInvokeImpl, clIdent);
- }
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof MultiDevFailed) {
- throw (MultiDevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
+ synchronized (lock != null ? lock : new Object()) {
+ AttributeGetterSetter.setAttributeValue4(values, attributeList, stateImpl, aroundInvokeImpl, clIdent);
}
- } finally {
- deviceMonitoring.endRequest(id);
+ } catch (final Exception e) {
+ throw handleException(e);
}
xlogger.exit();
}
@@ -1378,43 +1178,24 @@ public void write_attributes_4(final AttributeValue_4[] values, final ClntIdent
*/
@Override
public AttributeValue_4[] write_read_attributes_4(final AttributeValue_4[] values, final ClntIdent clIdent)
- throws MultiDevFailed, DevFailed {
- MDC.setContextMap(contextMap);
+ throws DevFailed {
xlogger.entry();
- checkInitialization();
+ //TODO Java 8
+// String[] names = Arrays.stream(values).map(attributeValue_4 -> attributeValue_4.name).toArray(String[]::new);
+ String[] names = getNames(values);
+ pre_attributes(names, clIdent);
- final String[] names = new String[values.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = values[i].name;
- }
- long id = deviceMonitoring.startRequest("write_read_attributes_4 " + Arrays.toString(names), clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_read_attributes_4 " + Arrays.toString(names), clIdent)) {
AttributeValue_4[] val = null;
- try {
- clientIdentity.set(clIdent);
-
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, names);
- }
final Object lock = deviceLock.getAttributeLock();
- try {
- synchronized (lock != null ? lock : new Object()) {
- val = writeRead(values);
- }
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
+ synchronized (lock != null ? lock : new Object()) {
+ val = writeRead(values, names);
}
- } finally {
- deviceMonitoring.endRequest(id);
+ xlogger.exit();
+ return val;
+ } catch (final Exception e) {
+ throw handleException(e);
}
- xlogger.exit();
- return val;
}
/**
@@ -1427,52 +1208,47 @@ public AttributeValue_4[] write_read_attributes_4(final AttributeValue_4[] value
*/
@Override
public AttributeValue_5[] write_read_attributes_5(final AttributeValue_4[] writeValues, final String[] readNames,
- final ClntIdent clIdent) throws MultiDevFailed, DevFailed {
- long id = deviceMonitoring.startRequest("write_read_attributes_5 ", clIdent);
- AttributeValue_5[] resultValues = null;
- try {
- clientIdentity.set(clIdent);
- final String[] names = new String[writeValues.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = writeValues[i].name;
- }
+ final ClntIdent clIdent) throws DevFailed {
+ xlogger.entry();
+ //TODO Java 8
+// String[] names = Arrays.stream(writeValues).map(attributeValue_4 -> attributeValue_4.name).toArray(String[]::new);
+ String[] names = getNames(writeValues);
+ pre_attributes(names, clIdent);
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, names);
- }
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_read_attributes_5 ", clIdent)) {
+ AttributeValue_5[] resultValues = null;
final Object lock = deviceLock.getAttributeLock();
- try {
- synchronized (lock != null ? lock : new Object()) {
- aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_WRITE_READ_ATTRIBUTES,
- CallType.CACHE_DEV, clIdent, name));
- // write attributes
- try {
- AttributeGetterSetter.setAttributeValue4(writeValues, attributeList, stateImpl, aroundInvokeImpl,
- clIdent);
- } catch (final MultiDevFailed e) {
- throw new DevFailed(e.errors[0].err_list);
- }
- // read attributes
- resultValues = AttributeGetterSetter.getAttributesValues5(name, readNames, pollingManager,
- attributeList, aroundInvokeImpl, DevSource.DEV, deviceLock, clIdent);
- aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_WRITE_READ_ATTRIBUTES,
- CallType.CACHE_DEV, clIdent, name));
- }
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
+ synchronized (lock != null ? lock : new Object()) {
+ aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_WRITE_READ_ATTRIBUTES,
+ CallType.CACHE_DEV, clIdent, name));
+ // write attributes
+ AttributeGetterSetter.setAttributeValue4(writeValues, attributeList, stateImpl, aroundInvokeImpl,
+ clIdent);
+ // read attributes
+ resultValues = AttributeGetterSetter.getAttributesValues5(name, readNames, pollingManager,
+ attributeList, aroundInvokeImpl, DevSource.DEV, deviceLock, clIdent);
+ aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_WRITE_READ_ATTRIBUTES,
+ CallType.CACHE_DEV, clIdent, name));
+ xlogger.exit();
+ return resultValues;
}
- } finally {
- deviceMonitoring.endRequest(id);
+ } catch (final Exception e) {
+ throw handleException(e);
}
+ }
- return resultValues;
+ private void pre_attributes(String[] names, ClntIdent clIdent) throws DevFailed {
+ MDC.setContextMap(contextMap);
+ checkInitialization();
+
+ checkClientLocking(clIdent, names);
+ clientIdentity.set(clIdent);
+ }
+
+ private void checkClientLocking(ClntIdent clIdent, String[] names) throws DevFailed {
+ if (!name.equalsIgnoreCase(getAdminDeviceName())) {
+ clientLocking.checkClientLocking(clIdent, names);
+ }
}
/**
@@ -1480,7 +1256,7 @@ public AttributeValue_5[] write_read_attributes_5(final AttributeValue_4[] write
* @return The read values
* @throws DevFailed
*/
- private AttributeValue_4[] writeRead(final AttributeValue_4[] values) throws DevFailed {
+ private AttributeValue_4[] writeRead(final AttributeValue_4[] values, String[] names) throws DevFailed {
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_WRITE_READ_ATTRIBUTES, CallType.CACHE_DEV,
null, name));
try {
@@ -1488,10 +1264,6 @@ private AttributeValue_4[] writeRead(final AttributeValue_4[] values) throws Dev
} catch (final MultiDevFailed e) {
throw new DevFailed(e.errors[0].err_list);
}
- final String[] names = new String[values.length];
- for (int i = 0; i < names.length; i++) {
- names[i] = values[i].name;
- }
final AttributeValue_4[] resultValues = AttributeGetterSetter.getAttributesValues4(name, names, pollingManager,
attributeList, aroundInvokeImpl, DevSource.DEV, deviceLock, null);
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_WRITE_READ_ATTRIBUTES, CallType.CACHE_DEV,
@@ -1506,13 +1278,12 @@ private AttributeValue_4[] writeRead(final AttributeValue_4[] values) throws Dev
* @throws DevFailed
*/
@Override
- public DevCmdInfo[] command_list_query() throws DevFailed {
+ public DevCmdInfo[] command_list_query() {
MDC.setContextMap(contextMap);
xlogger.entry();
// checkInitialization();
- long id = deviceMonitoring.startRequest("command_list_query");
final DevCmdInfo[] back = new DevCmdInfo[commandList.size()];
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_list_query")) {
// Retrieve number of command and allocate memory to send back info
final List cmdList = getCommandList();
Collections.sort(cmdList);
@@ -1527,8 +1298,6 @@ public DevCmdInfo[] command_list_query() throws DevFailed {
tmp.out_type_desc = cmd.getOutTypeDesc();
back[i++] = tmp;
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return back;
@@ -1541,13 +1310,12 @@ public DevCmdInfo[] command_list_query() throws DevFailed {
* @throws DevFailed
*/
@Override
- public DevCmdInfo_2[] command_list_query_2() throws DevFailed {
+ public DevCmdInfo_2[] command_list_query_2() {
MDC.setContextMap(contextMap);
xlogger.entry();
// checkInitialization();
- long id = deviceMonitoring.startRequest("command_list_query_2");
final DevCmdInfo_2[] back = new DevCmdInfo_2[commandList.size()];
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_list_query_2")) {
int i = 0;
final List cmdList = getCommandList();
Collections.sort(cmdList);
@@ -1564,8 +1332,6 @@ public DevCmdInfo_2[] command_list_query_2() throws DevFailed {
}
logger.debug("found {} commands ", commandList.size());
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return back;
@@ -1583,9 +1349,8 @@ public DevCmdInfo command_query(final String commandName) throws DevFailed {
MDC.setContextMap(contextMap);
xlogger.entry();
// checkInitialization();
- long id = deviceMonitoring.startRequest("command_query " + commandName);
final DevCmdInfo cmdInfo = new DevCmdInfo();
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_query " + commandName)) {
final CommandImpl foundCmd = getCommand(commandName);
cmdInfo.cmd_name = foundCmd.getName();
cmdInfo.cmd_tag = foundCmd.getTag();
@@ -1593,8 +1358,6 @@ public DevCmdInfo command_query(final String commandName) throws DevFailed {
cmdInfo.out_type = foundCmd.getOutType().getTangoIDLType();
cmdInfo.in_type_desc = foundCmd.getInTypeDesc();
cmdInfo.out_type_desc = foundCmd.getOutTypeDesc();
- } finally {
- deviceMonitoring.endRequest(id);
}
return cmdInfo;
}
@@ -1611,9 +1374,8 @@ public DevCmdInfo_2 command_query_2(final String commandName) throws DevFailed {
MDC.setContextMap(contextMap);
xlogger.entry();
// checkInitialization();
- long id = deviceMonitoring.startRequest("command_query_2 " + commandName);
final DevCmdInfo_2 cmdInfo = new DevCmdInfo_2();
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_query_2 " + commandName)) {
final CommandImpl foundCmd = getCommand(commandName);
cmdInfo.cmd_name = foundCmd.getName();
cmdInfo.cmd_tag = foundCmd.getTag();
@@ -1622,8 +1384,6 @@ public DevCmdInfo_2 command_query_2(final String commandName) throws DevFailed {
cmdInfo.in_type_desc = foundCmd.getInTypeDesc();
cmdInfo.out_type_desc = foundCmd.getOutTypeDesc();
cmdInfo.level = foundCmd.getDisplayLevel();
- } finally {
- deviceMonitoring.endRequest(id);
}
return cmdInfo;
}
@@ -1638,30 +1398,15 @@ public DevCmdInfo_2 command_query_2(final String commandName) throws DevFailed {
*/
@Override
public Any command_inout(final String command, final Any argin) throws DevFailed {
- MDC.setContextMap(contextMap);
- xlogger.entry();
- if (!command.equalsIgnoreCase(DeviceImpl.STATE_NAME) && !command.equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
- }
- final long request = deviceMonitoring.startRequest("command_inout " + command);
- Any argout = null;
- try {
- clientIdentity.set(null);
- argout = commandHandler(command, argin, DevSource.CACHE_DEV, null);
+ xlogger.entry(command);
+ pre_command_inout(command, null);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_inout " + command)) {
+ Any argout = commandHandler(command, argin, DevSource.CACHE_DEV, null);
+ xlogger.exit();
+ return argout;
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(request);
+ throw handleException(e);
}
- xlogger.exit();
- return argout;
}
/**
@@ -1675,30 +1420,15 @@ public Any command_inout(final String command, final Any argin) throws DevFailed
*/
@Override
public Any command_inout_2(final String command, final Any argin, final DevSource source) throws DevFailed {
- MDC.setContextMap(contextMap);
- xlogger.entry();
- if (!command.equalsIgnoreCase(DeviceImpl.STATE_NAME) && !command.equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
- checkInitialization();
- }
- long id = deviceMonitoring.startRequest("command_inout_2 " + command, source);
- Any argout = null;
- try {
- clientIdentity.set(null);
- argout = commandHandler(command, argin, source, null);
+ xlogger.entry(command);
+ pre_command_inout(command, null);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_inout_2 " + command, source)) {
+ Any argout = commandHandler(command, argin, source, null);
+ xlogger.exit();
+ return argout;
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
- xlogger.exit();
- return argout;
}
/**
@@ -1714,35 +1444,45 @@ public Any command_inout_2(final String command, final Any argin, final DevSourc
@Override
public Any command_inout_4(final String commandName, final Any argin, final DevSource source,
final ClntIdent clIdent) throws DevFailed {
- MDC.setContextMap(contextMap);
xlogger.entry(commandName);
- if (!commandName.equalsIgnoreCase(DeviceImpl.STATE_NAME)
- && !commandName.equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
+ pre_command_inout(commandName, clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("Operation command_inout_4 (cmd = " + commandName + ")",
+ source, clIdent)) {
+ Any argout = commandHandler(commandName, argin, source, clIdent);
+ xlogger.exit();
+ return argout;
+ } catch (final Exception e) {
+ throw handleException(e);
+ }
+ }
+
+ private void pre_command_inout(String command, ClntIdent clIdent) throws DevFailed {
+ MDC.setContextMap(contextMap);
+ if (!command.equalsIgnoreCase(DeviceImpl.STATE_NAME) && !command.equalsIgnoreCase(DeviceImpl.STATUS_NAME)) {
checkInitialization();
}
- final long request = deviceMonitoring.startRequest("Operation command_inout_4 (cmd = " + commandName + ")",
- source, clIdent);
- Any argout = null;
- try {
- clientIdentity.set(clIdent);
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent, commandName);
- }
- argout = commandHandler(commandName, argin, source, clIdent);
- } catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(request);
+ if (!name.equalsIgnoreCase(getAdminDeviceName())) {
+ clientLocking.checkClientLocking(clIdent, command);
+ }
+ clientIdentity.set(clIdent);
+ }
+
+ private DevFailed handleException(Exception e) {
+ deviceMonitoring.addError();
+ if (e instanceof DevFailed) {
+ return (DevFailed) e;
+ }
+ if (e instanceof MultiDevFailed) {
+ return new DevFailed("MultiDevFailed", ((MultiDevFailed) e).errors[0].err_list);
+// not supported by Java 7
+// Arrays.stream(((MultiDevFailed) e).errors)
+// .flatMap(namedDevError -> Arrays.stream(namedDevError.err_list))
+// .toArray(DevError[]::new));
+ } else {
+ // with CORBA, the stack trace is not visible by the client if
+ // not inserted in DevFailed.
+ return DevFailedUtils.newDevFailed(e);
}
- xlogger.exit();
- return argout;
}
/**
@@ -1758,15 +1498,11 @@ public DevCmdHistory[] command_inout_history_2(final String commandName, final i
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("command_inout_history_2 " + commandName);
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_inout_history_2 " + commandName)) {
// TODO command_inout_history_2
// returncommandHistory.get(command).toArray(n)
return new DevCmdHistory[]{};
- } finally {
- deviceMonitoring.endRequest(id);
}
-
}
/**
@@ -1782,24 +1518,14 @@ public DevCmdHistory_4 command_inout_history_4(final String commandName, final i
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- final long request = deviceMonitoring.startRequest("command_inout_history_4 " + commandName);
- DevCmdHistory_4 history = null;
- try {
- final CommandImpl command = getCommand(commandName);
- history = command.getHistory().toDevCmdHistory4(maxSize);
+ final CommandImpl command = getCommand(commandName);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("command_inout_history_4 " + commandName)) {
+ DevCmdHistory_4 history = command.getHistory().toDevCmdHistory4(maxSize);
+ xlogger.exit();
+ return history;
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(request);
+ throw handleException(e);
}
- return history;
}
/**
@@ -1878,9 +1604,8 @@ public AttributeConfig_5[] get_attribute_config_5(final String[] attributeNames)
MDC.setContextMap(contextMap);
xlogger.entry(Arrays.toString(attributeNames));
// checkInitialization();
- long id = deviceMonitoring.startRequest("get_attribute_config_5 " + Arrays.toString(attributeNames));
AttributeConfig_5[] result;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("get_attribute_config_5 " + Arrays.toString(attributeNames))) {
// check if we must retrieve all attributes config
final int length = attributeNames.length;
boolean getAllConfig = false;
@@ -1915,8 +1640,6 @@ public AttributeConfig_5[] get_attribute_config_5(final String[] attributeNames)
result[i++] = TangoIDLAttributeUtil.toAttributeConfig5(attribute);
}
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return result;
@@ -1934,9 +1657,8 @@ public AttributeConfig_3[] get_attribute_config_3(final String[] attributeNames)
MDC.setContextMap(contextMap);
xlogger.entry(Arrays.toString(attributeNames));
// checkInitialization();
- long id = deviceMonitoring.startRequest("get_attribute_config_3 " + Arrays.toString(attributeNames));
AttributeConfig_3[] result;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("get_attribute_config_3 " + Arrays.toString(attributeNames))) {
// check if we must retrieve all attributes config
final int length = attributeNames.length;
boolean getAllConfig = false;
@@ -1969,8 +1691,6 @@ public AttributeConfig_3[] get_attribute_config_3(final String[] attributeNames)
result[i++] = TangoIDLAttributeUtil.toAttributeConfig3(attribute);
}
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return result;
@@ -1988,10 +1708,8 @@ public AttributeConfig_2[] get_attribute_config_2(final String[] attributeNames)
MDC.setContextMap(contextMap);
xlogger.entry(Arrays.toString(attributeNames));
// checkInitialization();
- long id = deviceMonitoring.startRequest("get_attribute_config_2 " + Arrays.toString(attributeNames));
-
AttributeConfig_2[] result;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("get_attribute_config_2 " + Arrays.toString(attributeNames))) {
// check if we must retrieve all attributes config
final int length = attributeNames.length;
boolean getAllConfig = false;
@@ -2025,8 +1743,6 @@ public AttributeConfig_2[] get_attribute_config_2(final String[] attributeNames)
}
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return result;
@@ -2044,9 +1760,8 @@ public AttributeConfig[] get_attribute_config(final String[] attributeNames) thr
MDC.setContextMap(contextMap);
xlogger.entry();
// checkInitialization();
- long id = deviceMonitoring.startRequest("get_attribute_config " + Arrays.toString(attributeNames));
AttributeConfig[] result;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("get_attribute_config " + Arrays.toString(attributeNames))) {
// check if we must retrieve all attributes config
final int length = attributeNames.length;
boolean getAllConfig = false;
@@ -2070,8 +1785,6 @@ public AttributeConfig[] get_attribute_config(final String[] attributeNames) thr
result[i++] = TangoIDLAttributeUtil.toAttributeConfig(attribute);
}
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return result;
@@ -2087,16 +1800,9 @@ public AttributeConfig[] get_attribute_config(final String[] attributeNames) thr
@Override
public void set_attribute_config_5(final AttributeConfig_5[] newConf, final ClntIdent clIdent) throws DevFailed {
- MDC.setContextMap(contextMap);
- xlogger.entry();
- checkInitialization();
- clientIdentity.set(clIdent);
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent);
- }
+ pre_command_inout("set_attribute_config_5", clIdent);
- long id = deviceMonitoring.startRequest("set_attribute_config_5", clIdent);
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("set_attribute_config_5", clIdent)) {
for (final AttributeConfig_5 attributeConfig : newConf) {
final String attributeName = attributeConfig.name;
@@ -2121,8 +1827,6 @@ public void set_attribute_config_5(final AttributeConfig_5[] newConf, final Clnt
}
attribute.setProperties(props);
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
}
@@ -2136,21 +1840,11 @@ public void set_attribute_config_5(final AttributeConfig_5[] newConf, final Clnt
*/
@Override
public void set_attribute_config_4(final AttributeConfig_3[] newConf, final ClntIdent clIdent) throws DevFailed {
- MDC.setContextMap(contextMap);
- xlogger.entry();
- checkInitialization();
- clientIdentity.set(clIdent);
- if (!name.equalsIgnoreCase(getAdminDeviceName())) {
- clientLocking.checkClientLocking(clIdent);
- }
- long id = deviceMonitoring.startRequest("set_attribute_config_4", clIdent);
- try {
+ pre_command_inout("set_attribute_config_4", clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("set_attribute_config_4", clIdent)) {
set_attribute_config_3(newConf);
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
-
}
/**
@@ -2164,8 +1858,7 @@ public void set_attribute_config_3(final AttributeConfig_3[] newConf) throws Dev
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("set_attribute_config_3");
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("set_attribute_config_3")) {
for (final AttributeConfig_3 attributeConfig : newConf) {
final String attributeName = attributeConfig.name;
@@ -2183,8 +1876,6 @@ public void set_attribute_config_3(final AttributeConfig_3[] newConf) throws Dev
logger.debug("set_attribute_config_3: {}", props);
attribute.setProperties(props);
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
}
@@ -2200,8 +1891,7 @@ public void set_attribute_config(final AttributeConfig[] newConf) throws DevFail
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("set_attribute_config");
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("set_attribute_config")) {
for (final AttributeConfig attributeConfig : newConf) {
final String attributeName = attributeConfig.name;
final AttributeImpl attribute = AttributeGetterSetter.getAttribute(attributeName, attributeList);
@@ -2217,8 +1907,6 @@ public void set_attribute_config(final AttributeConfig[] newConf) throws DevFail
logger.debug("set_attribute_config: {}", props);
attribute.setProperties(props);
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
}
@@ -2655,9 +2343,8 @@ public DevAttrHistory_5 read_attribute_history_5(final String attributeName, fin
MDC.setContextMap(contextMap);
xlogger.entry();
checkInitialization();
- long id = deviceMonitoring.startRequest("read_attribute_history_5");
DevAttrHistory_5 result = null;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_attribute_history_5")) {
final AttributeImpl attr = AttributeGetterSetter.getAttribute(attributeName, attributeList);
if (attr.getBehavior() instanceof ForwardedAttribute) {
final ForwardedAttribute fwdAttr = (ForwardedAttribute) attr.getBehavior();
@@ -2670,16 +2357,7 @@ public DevAttrHistory_5 read_attribute_history_5(final String attributeName, fin
result = attr.getHistory().getAttrHistory5(maxSize);
}
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
return result;
@@ -2689,9 +2367,8 @@ public DevAttrHistory_5 read_attribute_history_5(final String attributeName, fin
public PipeConfig[] get_pipe_config_5(final String[] names) throws DevFailed {
xlogger.entry(Arrays.toString(names));
// checkInitialization();
- long id = deviceMonitoring.startRequest("get_pipe_config_5 " + Arrays.toString(names));
PipeConfig[] result;
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("get_pipe_config_5 " + Arrays.toString(names))) {
// check if we must retrieve all attributes config
final int length = names.length;
boolean getAllConfig = false;
@@ -2714,8 +2391,6 @@ public PipeConfig[] get_pipe_config_5(final String[] names) throws DevFailed {
result[i++] = TangoIDLUtil.toPipeConfig(pipe);
}
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
return result;
@@ -2728,15 +2403,12 @@ public void set_pipe_config_5(final PipeConfig[] newConf, final ClntIdent clIden
checkInitialization();
clientIdentity.set(clIdent);
- long id = deviceMonitoring.startRequest("set_pipe_config_5", clIdent);
- try {
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("set_pipe_config_5", clIdent)) {
for (final PipeConfig config : newConf) {
final String name = config.name;
final PipeImpl pipe = getPipe(name, pipeList);
pipe.setConfiguration(config.label, config.description);
}
- } finally {
- deviceMonitoring.endRequest(id);
}
xlogger.exit();
}
@@ -2746,30 +2418,20 @@ public DevPipeData read_pipe_5(final String name, final ClntIdent clIdent) throw
MDC.setContextMap(contextMap);
xlogger.entry(name);
final PipeImpl pipe = getPipe(name, pipeList);
- long id = deviceMonitoring.startRequest("read_pipe_5 " + name, clIdent);
- DevPipeData result = null;
- try {
- clientIdentity.set(clIdent);
+ clientIdentity.set(clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("read_pipe_5 " + name, clIdent)) {
+ DevPipeData result = null;
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_PIPE_READ, CallType.UNKNOWN, clIdent,
pipe.getName()));
pipe.updateValue();
result = TangoIDLUtil.toDevPipeData(pipe.getName(), pipe.getReadValue());
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_PIPE_READ, CallType.UNKNOWN, clIdent,
pipe.getName()));
+ xlogger.exit();
+ return result;
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
- xlogger.exit();
- return result;
}
@Override
@@ -2777,25 +2439,15 @@ public void write_pipe_5(final DevPipeData value, final ClntIdent clIdent) throw
MDC.setContextMap(contextMap);
xlogger.entry(value.name);
final PipeImpl pipe = getPipe(value.name, pipeList);
- long id = deviceMonitoring.startRequest("write_pipe_5 " + value.name, clIdent);
- try {
- clientIdentity.set(clIdent);
+ clientIdentity.set(clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_pipe_5 " + value.name, clIdent)) {
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_PIPE_WRITE, CallType.UNKNOWN, clIdent,
pipe.getName()));
pipe.setValue(TangoIDLUtil.toPipeValue(value));
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_PIPE_WRITE, CallType.UNKNOWN, clIdent,
pipe.getName()));
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
xlogger.exit();
}
@@ -2805,10 +2457,9 @@ public DevPipeData write_read_pipe_5(final DevPipeData value, final ClntIdent cl
MDC.setContextMap(contextMap);
xlogger.entry(name);
final PipeImpl pipe = getPipe(name, pipeList);
- long id = deviceMonitoring.startRequest("write_read_pipe_5 " + name, clIdent);
- DevPipeData result = null;
- try {
- clientIdentity.set(clIdent);
+ clientIdentity.set(clIdent);
+ try (DeviceMonitoring.Request ignored = deviceMonitoring.startRequest("write_read_pipe_5 " + name, clIdent)) {
+ DevPipeData result = null;
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.PRE_PIPE_WRITE_READ, CallType.UNKNOWN,
clIdent, pipe.getName()));
pipe.setValue(TangoIDLUtil.toPipeValue(value));
@@ -2816,19 +2467,10 @@ public DevPipeData write_read_pipe_5(final DevPipeData value, final ClntIdent cl
result = TangoIDLUtil.toDevPipeData(pipe.getName(), pipe.getReadValue());
aroundInvokeImpl.aroundInvoke(new InvocationContext(ContextType.POST_PIPE_WRITE_READ, CallType.UNKNOWN,
clIdent, pipe.getName()));
+ xlogger.exit();
+ return result;
} catch (final Exception e) {
- deviceMonitoring.addError();
- if (e instanceof DevFailed) {
- throw (DevFailed) e;
- } else {
- // with CORBA, the stack trace is not visible by the client if
- // not inserted in DevFailed.
- throw DevFailedUtils.newDevFailed(e);
- }
- } finally {
- deviceMonitoring.endRequest(id);
+ throw handleException(e);
}
- xlogger.exit();
- return result;
}
}