diff --git a/.classpath b/.classpath index 3f8b7611192bb9a494ade0d2bcc1d358f4d49ba4..bfbe1725010acc11dfee02824a4f84833ba28177 100644 --- a/.classpath +++ b/.classpath @@ -2,7 +2,6 @@ <classpath> <classpathentry kind="src" output="target/classes" path="src/main/java"/> <classpathentry excluding="**" including="**/*.java" kind="src" output="target/classes" path="src/main/resources"/> - <classpathentry kind="src" path="src/test/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/> <classpathentry kind="output" path="target/classes"/> diff --git a/.project b/.project index 8449a4332a46e89bafbf7654ef9fa21db72860c6..a4743907b8b54a7b2a121b98404e3a97a2bb4107 100644 --- a/.project +++ b/.project @@ -27,11 +27,4 @@ <nature>org.devzuz.q.maven.jdt.core.mavenNature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> </natures> - <linkedResources> - <link> - <name>ArchivingConf</name> - <type>2</type> - <location>C:/SOLEIL_ROOT/tango-soleil-win32-5.5.8RC3/tango/bin/ArchivingConf</location> - </link> - </linkedResources> </projectDescription> diff --git a/pom.xml b/pom.xml index 25b09b537784a089addb167d69b167818b4daf2c..fbaf0cc40fac3a5d336fcaf0e88cf5a09df4f1b8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ <artifactId>hdbtdbArchivingServers</artifactId> <name>hdbtdbArchivingServers</name> - <version>2.2.15</version> + <version>2.2.20</version> <scm> <connection>${scm.connection.svn.tango-cs}:archiving/server/hdbtdbArchivingServers</connection> @@ -42,6 +42,10 @@ <groupId>org.tango</groupId> <artifactId>TangORB-javadao</artifactId> </dependency> + <dependency> + <groupId>org.tango</groupId> + <artifactId>JTangoCommons</artifactId> + </dependency> <dependency> <groupId>fr.esrf.atk</groupId> <artifactId>ATKCore</artifactId> diff --git a/src/main/java/Common/Archiver/Collector/ArchiverCollector.java b/src/main/java/Common/Archiver/Collector/ArchiverCollector.java index 16c927ee8cb2cfa0146db4ff3db563f500c91b96..eeb15f2d17990dbdf47d26e26458d716bdc16170 100644 --- a/src/main/java/Common/Archiver/Collector/ArchiverCollector.java +++ b/src/main/java/Common/Archiver/Collector/ArchiverCollector.java @@ -11,7 +11,7 @@ public abstract class ArchiverCollector { // This hashtable contains the mode counters by attribute private final Map<String, ModesCounters> attributeModeCounterMap = new HashMap<String, ModesCounters>(); // Diary file - protected ILogger m_logger; + protected ILogger logger; /** * An ModeHandler is associated to each Collector to handle the archiving @@ -24,14 +24,14 @@ public abstract class ArchiverCollector { } public void setDiaryLogger(ILogger _logger) { - this.m_logger = _logger; + this.logger = _logger; } /* Allows to indicate to the collector that a new attribute must be managed */ protected synchronized void addAttribute(String name) { String lower = name.toLowerCase(); if (attributeModeCounterMap.containsKey(lower)) { - m_logger.trace(ILogger.LEVEL_WARNING, "ArchiverCollector.addAttribute : The attribute " + name + logger.trace(ILogger.LEVEL_WARNING, "ArchiverCollector.addAttribute : The attribute " + name + "already exists in the map ==> Counter Re-init"); attributeModeCounterMap.get(lower).init(); } else { @@ -71,7 +71,7 @@ public abstract class ArchiverCollector { doArchive = m_modeHandler.isDataArchivable(mc, dataType, readValueObject, lastValueObject); } catch (Exception e) { e.printStackTrace(); - this.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + "/doArchiveEvent/catch " + e + this.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + "/doArchiveEvent/catch " + e + " with the value of " + attCompleteName); } diff --git a/src/main/java/HdbArchiver/Collector/DbProxy.java b/src/main/java/HdbArchiver/Collector/DbProxy.java index 904ec1db5d6ab49a0cc3147069aceb8329e309fd..f2d2da2182f8c760fd19e82ac7e410c5330391fc 100644 --- a/src/main/java/HdbArchiver/Collector/DbProxy.java +++ b/src/main/java/HdbArchiver/Collector/DbProxy.java @@ -356,26 +356,13 @@ public class DbProxy implements IDbProxy { } public Vector<AttributeLightMode> getArchiverCurrentTasks(final String archiverName) throws ArchivingException { - Util.out4.println("DbProxy.getArchiverCurrentTasks"); - // Vector<AttributeLightMode> archiverCurrentTasks = new - // Vector<AttributeLightMode>(); final boolean facility = manager.isM_Facility(); - try { final Vector<AttributeLightMode> archiverCurrentTasks = manager .getDataBase() .getMode() .getArchiverCurrentTasks( (facility ? "//" + new Database().get_tango_host() + "/" : "") + archiverName); - // System.out.println("Current Tasks - " + - // archiverCurrentTasks.size() + ": "); - // for (int i = 0; i < archiverCurrentTasks.size(); i++) { - // final AttributeLightMode attributeLightMode = - // archiverCurrentTasks.elementAt(i); - // System.out.println("******************* " + (i + 1) - // + " *******************"); - // System.out.println(attributeLightMode); - // } return archiverCurrentTasks; } catch (final DevFailed devFailed) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + GlobalConst.DBT_UNREACH_EXCEPTION; diff --git a/src/main/java/HdbArchiver/Collector/HdbCollector.java b/src/main/java/HdbArchiver/Collector/HdbCollector.java index 2cb43def930bc7738c3da6e10cf31ad256bec55c..f0c4d15ae301b22f5eceb05752527de25f22ca4f 100644 --- a/src/main/java/HdbArchiver/Collector/HdbCollector.java +++ b/src/main/java/HdbArchiver/Collector/HdbCollector.java @@ -126,6 +126,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import Common.Archiver.Collector.ArchiverCollector; import HdbArchiver.HdbArchiver; @@ -151,7 +152,7 @@ public abstract class HdbCollector extends ArchiverCollector { */ protected boolean refreshing; - protected boolean isFirstValue; + protected volatile Map<String, Boolean> isFirstValueList = new ConcurrentHashMap<String, Boolean>(); /** * This parameter specify the number of time a Collector retry the archiving @@ -182,7 +183,6 @@ public abstract class HdbCollector extends ArchiverCollector { public HdbCollector(final HdbModeHandler _modeHandler) { super(_modeHandler); - isFirstValue = true; } /** @@ -211,7 +211,7 @@ public abstract class HdbCollector extends ArchiverCollector { */ public void addSource(final AttributeLightMode attributeLightMode) throws ArchivingException { - isFirstValue = true; + isFirstValueList.put(attributeLightMode.getAttribute_complete_name().toLowerCase(), true); if (HdbArchiver.isUseEvents) { addSourceForEvents(attributeLightMode); } else { @@ -236,16 +236,19 @@ public abstract class HdbCollector extends ArchiverCollector { /** * Triggers the collecting action of this HdbCollector. */ - public synchronized void startCollecting() { + protected synchronized void startCollecting() { if (!attributeList.isEmpty()) { - if (attributeList.size() == 1) { + if (!attributeList.isRefresherStarted()) { attributeList.setRefreshInterval(m_modeHandler.getRefreshInterval()); attributeList.setSynchronizedPeriod(true); attributeList.startRefresher(); refreshing = true; + logger.trace(ILogger.LEVEL_DEBUG, this.getClass() + " start refresh for " + attributeList.getSize() + + " attributes"); } else { // force a refresh for newly added attributes attributeList.refresh(); + logger.trace(ILogger.LEVEL_DEBUG, "FORCING refresh for " + this.getClass()); } } } @@ -253,14 +256,12 @@ public abstract class HdbCollector extends ArchiverCollector { /** * Stops the collecting action of this HdbCollector. */ - public synchronized void stopCollecting() { - Util.out4.println("HdbCollector.stopCollecting"); - m_logger.trace(ILogger.LEVEL_INFO, "HdbCollector.stopCollecting"); + protected synchronized void stopCollecting() { try { - if (attributeList.isEmpty()) { - attributeList.stopRefresher(); - refreshing = false; - } + logger.trace(ILogger.LEVEL_DEBUG, this.getClass() + " stop refresh on " + attributeList.getSize() + + " attributes"); + attributeList.stopRefresher(); + refreshing = false; } catch (final Exception e) { Util.out2.println("ERROR !! " + "\r\n" + "\t Origin : \t " + "HdbCollector.stopCollecting" + "\r\n" + "\t Reason : \t " + "UNKNOWN_ERROR" + "\r\n" + "\t Description : \t " + e.getMessage() + "\r\n" @@ -325,7 +326,7 @@ public abstract class HdbCollector extends ArchiverCollector { final long newTime = archivingEvent.getTimeStamp(); if (newTime == 0) { - m_logger.trace(ILogger.LEVEL_WARNING, "NOARCHIVING - received a zero timestamp for " + name + logger.trace(ILogger.LEVEL_WARNING, "NOARCHIVING - received a zero timestamp for " + name + " - tableName: " + archivingEvent.getTable_name()); return false; } @@ -335,10 +336,10 @@ public abstract class HdbCollector extends ArchiverCollector { return true; } - final boolean isAlreadyRegisteredDate = lastTimestampStack.containsDate(newTime, m_logger); - final boolean isValidDate = lastTimestampStack.validateDate(newTime, m_logger); + final boolean isAlreadyRegisteredDate = lastTimestampStack.containsDate(newTime, logger); + final boolean isValidDate = lastTimestampStack.validateDate(newTime, logger); if (isAlreadyRegisteredDate || !isValidDate) { - m_logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - AlreadyRegisteredDate - attribute: " + name + logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - AlreadyRegisteredDate - attribute: " + name + " - timestamp: " + new Timestamp(newTime)); return false; } @@ -368,7 +369,7 @@ public abstract class HdbCollector extends ArchiverCollector { return ret; } - public List<String> getAttributeList() { + public synchronized List<String> getAttributeList() { final List<String> attributeListResult = new ArrayList<String>(); final Enumeration<?> myAttList = attributeList.elements(); while (myAttList.hasMoreElements()) { diff --git a/src/main/java/HdbArchiver/Collector/image/Image_RO.java b/src/main/java/HdbArchiver/Collector/image/Image_RO.java index 2fd94e06cfc5d58d01e53e4ddb288de3af04bd4f..66efdac48cabc5474f699a303bd48b3e4a41d2d1 100644 --- a/src/main/java/HdbArchiver/Collector/image/Image_RO.java +++ b/src/main/java/HdbArchiver/Collector/image/Image_RO.java @@ -203,8 +203,8 @@ public class Image_RO extends HdbCollector implements IImageListener { super.setLastTimestamp(snapImageEvent_RO); } catch (final Exception e) { final String message = "Problem (ArchivingException) storing Image_RO value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { diff --git a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar.java b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar.java index 2fa92d05717a5db946c3cf945a1e3cc5a9dad263..3fd0732113c1d2348bc235ae8c0f2588ea827937 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar.java @@ -130,7 +130,7 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal evtAdaptHMap = new HashMap<Device, TangoEventsAdapter>(); } - /* synchronized */@Override + @Override public synchronized void removeSource(final String attributeName) throws ArchivingException { Util.out2.println("BooleanScalar.removeSource"); @@ -143,20 +143,18 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal * while ( ( IBooleanScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IBooleanScalar attribute = (IBooleanScalar) attributeList.get(attributeName); if (attribute != null) { attribute.removeBooleanScalarListener(this); attribute.removeErrorListener(this); attributeList.remove(attributeName); - + isFirstValueList.remove(attributeName.toLowerCase()); // informs the mother class that one new attribute must be // removed removeAttribute(attributeName); removeTimestamps(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -165,6 +163,8 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -175,6 +175,7 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal final String attName = attributeLightMode.getAttribute_complete_name(); if (attName != null) { + stopCollecting(); final IBooleanScalar attribute = (IBooleanScalar) attributeList.add(attName); attribute.addBooleanScalarListener(this); attribute.addErrorListener(this); @@ -183,12 +184,8 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal // informs the mother class that one new attribute must be // managed addAttribute(attName); - m_logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); - startCollecting(); + logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); - } else { - m_logger.trace(ILogger.LEVEL_ERROR, "archiving not started because attribute name is null " - + attributeLightMode); } } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" @@ -203,6 +200,8 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -361,14 +360,14 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -382,8 +381,8 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal setLastValue(scalarEvent, scalarEvent.getReadValue()); } catch (final Exception e) { final String message = "Problem storing BooleanScalar value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { @@ -414,13 +413,13 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar(getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_BOOLEAN, getWritableValue()), DEFAULT_TRY_NUMBER); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RO.java b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RO.java index f1d3cc499965999f494a117c2e25325d5c839995..cd343da0bcbd5fda93196598a1568f1dfb9f1d50 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RO.java @@ -139,8 +139,8 @@ public class BooleanScalar_RO extends BooleanScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in BooleanScalar_RO/booleanScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RW.java b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RW.java index 575de2184a67c48b4c9ecf051869acf47bc5b47d..3d7d714deed6c6ffdfeb551c5d95fde835480008 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RW.java +++ b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_RW.java @@ -143,8 +143,8 @@ public class BooleanScalar_RW extends BooleanScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in BooleanScalar_RW/booleanScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_WO.java b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_WO.java index 576ab682368d83a30b580107369c15f0e51bf2e9..0035c3a64fa6c8368c35e007b89dd97b027f675c 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_WO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/BooleanScalar_WO.java @@ -124,8 +124,8 @@ public class BooleanScalar_WO extends BooleanScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in BooleanScalar_WO/booleanScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar.java b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar.java index f7c32989fd1616d37abf502c8d67689731fa1a2b..b29b4e3c4ff4b574783cce0adfd0799be105d6e7 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar.java @@ -176,7 +176,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar public synchronized void removeSource(final String attributeName) throws ArchivingException { Util.out2.println("NumberScalar.removeSource"); - m_logger.trace(ILogger.LEVEL_INFO, "===> Entering " + this.getClass().getSimpleName() + ".removeSource for " + logger.trace(ILogger.LEVEL_INFO, "===> Entering " + this.getClass().getSimpleName() + ".removeSource for " + attributeName); if (HdbArchiver.isUseEvents) { @@ -188,20 +188,18 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar * while ( ( INumberScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final INumberScalar attribute = (INumberScalar) attributeList.get(attributeName); if (attribute != null) { attribute.removeNumberScalarListener(this); attribute.removeErrorListener(this); attributeList.remove(attributeName); - m_logger.trace(ILogger.LEVEL_INFO, "\t The attribute was fired from the Collector list..."); + isFirstValueList.remove(attributeName.toLowerCase()); + logger.trace(ILogger.LEVEL_INFO, "\t The attribute was fired from the Collector list..."); // informs the mother class that one new attribute must be // removed removeAttribute(attributeName); removeTimestamps(attributeName); - if (attributeList.isEmpty()) { - m_logger.trace(ILogger.LEVEL_INFO, "===> StopCollecting is requested "); - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -211,8 +209,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar + ".removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); } finally { - m_logger.trace(ILogger.LEVEL_INFO, "===> Exiting " + this.getClass().getSimpleName() + ".removeSource for " - + attributeName); + startCollecting(); } } @@ -223,6 +220,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar final String attName = attributeLightMode.getAttribute_complete_name(); if (attName != null) { INumberScalar attribute = null; + stopCollecting(); attribute = (INumberScalar) attributeList.add(attName); attribute.addNumberScalarListener(this); attribute.addErrorListener(this); @@ -231,11 +229,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar // informs the mother class that one new attribute must be // managed addAttribute(attName); - m_logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); - startCollecting(); - } else { - m_logger.trace(ILogger.LEVEL_ERROR, "archiving not started because attribute name is null " - + attributeLightMode); + logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); } } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" @@ -249,6 +243,8 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -419,17 +415,18 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar scalarEvent.avoidUnderFlow(); boolean doArchive = false; - if (isFirstValue) { + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown "); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown "); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); + } } @@ -441,8 +438,8 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar } catch (final Exception e) { e.printStackTrace(); final String message = "Problem storing NumberScalar value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { @@ -473,7 +470,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); /* Must be change because the number scalar are not only double */ try { @@ -481,7 +478,7 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar getNullValueScalarEvent(errorEvent, ((AAttribute) errorEvent.getSource()).getTangoDataType(), getWritableValue()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RO.java b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RO.java index b08efa283acc53889d648599569a5252b4e2a12f..9f44bfd6b61c3e76b8ae6a4eda73f1bb8c751f2c 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RO.java @@ -157,8 +157,8 @@ public class NumberScalar_RO extends NumberScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in NumberScalar_RO/numberScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RW.java b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RW.java index e2bc2b63a1cb71fe96d40ff5c02987b8990ff1ba..25cb3d6dc9b1926d2fd50c46e555fac2ac2d08ca 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RW.java +++ b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_RW.java @@ -182,8 +182,8 @@ public class NumberScalar_RW extends NumberScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in NumberScalar_RW/numberScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_WO.java b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_WO.java index c5b53be73c66d21dbee8a3cf7fb81f2df9f73a9d..03dbd68354f8fdde35298260ffbccded9212ec8e 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_WO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/NumberScalar_WO.java @@ -140,8 +140,8 @@ public class NumberScalar_WO extends NumberScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in NumberScalar_RW/numberScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java b/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java index a65a3bcf3386884397c543d6f335520d1841a34e..401792d1f2ce8ffe377365e8819df4e909b14451 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java @@ -80,19 +80,18 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala * while ( ( IDevStateScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IDevStateScalar attribute = (IDevStateScalar) attributeList.get(attributeName); if (attribute != null) { attribute.removeDevStateScalarListener(this); attribute.removeErrorListener(this); attributeList.remove(attributeName); + isFirstValueList.remove(attributeName.toLowerCase()); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); // informs the mother class that one new attribute must be // removed removeAttribute(attributeName); removeTimestamps(attributeName); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -101,6 +100,8 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -114,6 +115,7 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala // == // null ) // { + stopCollecting(); IDevStateScalar attribute = null; attribute = (IDevStateScalar) attributeList.add(attName); @@ -123,11 +125,7 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala // informs the mother class that one new attribute must be // managed addAttribute(attName); - m_logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); - startCollecting(); - } else { - m_logger.trace(ILogger.LEVEL_ERROR, "archiving not started because attribute name is null " - + attributeLightMode); + logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); } } catch (final ConnectionException e) { @@ -143,6 +141,8 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -300,15 +300,15 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + "attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + "attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -322,8 +322,8 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala setLastValue(scalarEvent, scalarEvent.getReadValue()); } catch (final Exception e) { final String message = "Problem storing StateScalar value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { @@ -358,13 +358,13 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar(getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_STATE, getWritableValue()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StateScalar_RO.java b/src/main/java/HdbArchiver/Collector/scalar/StateScalar_RO.java index e324e0c998a43d12f97e71a4252381df9a6c92e0..d1faeab0ce41f0605cca3e3ad141b9c88da29469 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StateScalar_RO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StateScalar_RO.java @@ -104,8 +104,8 @@ public class StateScalar_RO extends StateScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in StateScalar_RO/devStateScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java b/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java index 72a6154eb69428023190eeebc1df2da03203dd35..d11e826d69713d8ad08012296395f3e68579e0bd 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java @@ -82,19 +82,18 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar * while ( ( IStringScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IStringScalar attribute = (IStringScalar) attributeList.get(attributeName); if (attribute != null) { attribute.removeStringScalarListener(this); attribute.removeErrorListener(this); attributeList.remove(attributeName); + isFirstValueList.remove(attributeName.toLowerCase()); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); // informs the mother class that one new attribute must be // removed removeAttribute(attributeName); removeTimestamps(attributeName); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -103,6 +102,8 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -113,6 +114,7 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar try { final String attName = attributeLightMode.getAttribute_complete_name(); if (attName != null) { + stopCollecting(); IStringScalar attribute = null; attribute = (IStringScalar) attributeList.add(attName); @@ -122,11 +124,7 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar // informs the mother class that one new attribute must be // managed addAttribute(attName); - m_logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); - startCollecting(); - } else { - m_logger.trace(ILogger.LEVEL_ERROR, "archiving not started because attribute name is null " - + attributeLightMode); + logger.trace(ILogger.LEVEL_INFO, "add archiving for " + attName); } } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" @@ -141,6 +139,8 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing " + this.getClass().getSimpleName() + ".addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -304,15 +304,15 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -326,8 +326,8 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar setLastValue(scalarEvent, scalarEvent.getReadValue()); } catch (final Exception e) { final String message = "Problem storing StringScalar value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { @@ -357,13 +357,13 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar(getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_STRING, getWritableValue()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RO.java b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RO.java index 377865edbe21fa897abc500623f94ff74cb36726..b3bc30a5ade064774052085fe6ffeab8b6a6fe96 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RO.java @@ -102,8 +102,8 @@ public class StringScalar_RO extends StringScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in StringScalar_RO/stringScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RW.java b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RW.java index 78bcc06c4cc130159f4f144e05a176312c98c13c..5db2cfd42429f6de8974e3ae26046673150ddee5 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RW.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_RW.java @@ -105,8 +105,8 @@ public class StringScalar_RW extends StringScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in StringScalar_RW/stringScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_WO.java b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_WO.java index 889db320b669ffc0aafca0df587664e92b577f7a..ffc6cc6c2ae35793920b225e0f284a2a2eec5d98 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StringScalar_WO.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StringScalar_WO.java @@ -96,8 +96,8 @@ public class StringScalar_WO extends StringScalar { processEventScalar(scalarEvent, tryNumber); final String message = "Problem in StringScalar_WO/stringScalarChange"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, exE); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, exE); } } diff --git a/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RO.java b/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RO.java index 119fbf39b4bdefa322f554df8574cc169f9444e1..c7c20000049b3f10ec0fc6be20335810ecf9fc03 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RO.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RO.java @@ -156,6 +156,7 @@ public class BooleanSpectrum_RO extends HdbCollector implements IBooleanSpectrum * while ( ( IBooleanSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IBooleanSpectrum attribute = (IBooleanSpectrum) attributeList.get(attributeName); if (attribute != null) { @@ -165,9 +166,6 @@ public class BooleanSpectrum_RO extends HdbCollector implements IBooleanSpectrum attributeList.remove(attributeName); removeTimestamps(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -175,6 +173,8 @@ public class BooleanSpectrum_RO extends HdbCollector implements IBooleanSpectrum final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing BooleanSpectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -182,19 +182,21 @@ public class BooleanSpectrum_RO extends HdbCollector implements IBooleanSpectrum protected synchronized void addSourceForPolling(final AttributeLightMode attributeLightMode) throws ArchivingException { try { + stopCollecting(); final IBooleanSpectrum attribute = (IBooleanSpectrum) attributeList.add(attributeLightMode .getAttribute_complete_name()); attribute.addBooleanSpectrumListener(this); attribute.addErrorListener(this); Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + " was hired to the Collector list..."); - startCollecting(); } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -474,8 +476,8 @@ public class BooleanSpectrum_RO extends HdbCollector implements IBooleanSpectrum super.setLastTimestamp(snapSpectrumEvent_RO); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing BooleanSpectrum_RO value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { diff --git a/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RW.java b/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RW.java index 18be8e8d3f025790712930871ff9033e0b6ee6bc..7c254b2d7f990810f215249496ffec395d381418 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RW.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/BooleanSpectrum_RW.java @@ -84,6 +84,7 @@ public class BooleanSpectrum_RW extends HdbCollector implements IBooleanSpectrum * while ( ( IBooleanSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IBooleanSpectrum attribute = (IBooleanSpectrum) attributeList.get(attributeName); if (attribute != null) { @@ -92,9 +93,6 @@ public class BooleanSpectrum_RW extends HdbCollector implements IBooleanSpectrum removeTimestamps(attributeName); attributeList.remove(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -102,6 +100,8 @@ public class BooleanSpectrum_RW extends HdbCollector implements IBooleanSpectrum final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -109,20 +109,21 @@ public class BooleanSpectrum_RW extends HdbCollector implements IBooleanSpectrum protected synchronized void addSourceForPolling(final AttributeLightMode attributeLightMode) throws ArchivingException { try { - + stopCollecting(); final IBooleanSpectrum attribute = (IBooleanSpectrum) attributeList.add(attributeLightMode .getAttribute_complete_name()); attribute.addBooleanSpectrumListener(this); attribute.addErrorListener(this); Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + " was hired to the Collector list..."); - startCollecting(); } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -410,8 +411,8 @@ public class BooleanSpectrum_RW extends HdbCollector implements IBooleanSpectrum super.setLastTimestamp(snapSpectrumEvent_RW); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing BooleanSpectrum_RW value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); Util.out4.println("BooleanSpectrumEvent_RW.processEventSpectrum/ArchivingException"); diff --git a/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RO.java b/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RO.java index dde45450c37b9e72e83b2e673be80fa43de6e629..68dd050a7a551273d91a4315eaaec31e4c8b2c10 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RO.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RO.java @@ -159,6 +159,7 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener * while ( ( INumberSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final INumberSpectrum attribute = (INumberSpectrum) attributeList.get(attributeName); if (attribute != null) { @@ -167,9 +168,6 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener removeTimestamps(attributeName); attributeList.remove(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -177,6 +175,8 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing NumberSpectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -184,10 +184,7 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener protected synchronized void addSourceForPolling(final AttributeLightMode attributeLightMode) throws ArchivingException { try { - // while ( ( INumberSpectrum ) - // attributeList.get(attributeLightMode.getAttribute_complete_name()) - // == null ) - // { + stopCollecting(); final INumberSpectrum attribute = (INumberSpectrum) attributeList.add(attributeLightMode .getAttribute_complete_name()); attribute.addSpectrumListener(this); @@ -195,14 +192,14 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + " was hired to the Collector list..."); - startCollecting(); - // } } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing NumberSpectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -551,8 +548,8 @@ public class NumberSpectrum_RO extends HdbCollector implements ISpectrumListener super.setLastTimestamp(snapSpectrumEvent_RO); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing NumberSpectrum_RO value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { diff --git a/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RW.java b/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RW.java index cd0ee6bc0582c377e07dc7a3b203f640344a4c55..4fec5b6a87bf01e0111821bfa3c1785777fcd494 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RW.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/NumberSpectrum_RW.java @@ -84,24 +84,24 @@ public class NumberSpectrum_RW extends HdbCollector implements ISpectrumListener * while ( ( INumberSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final INumberSpectrum attribute = (INumberSpectrum) attributeList.get(attributeName); if (attribute != null) { - attribute.removeSpectrumListener(this); attribute.removeErrorListener(this); removeTimestamps(attributeName); attributeList.remove(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } + } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName + "' from sources"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -113,19 +113,21 @@ public class NumberSpectrum_RW extends HdbCollector implements ISpectrumListener // attributeList.get(attributeLightMode.getAttribute_complete_name()) // == null ) // { + stopCollecting(); final INumberSpectrum attribute = (INumberSpectrum) attributeList.add(attributeLightMode .getAttribute_complete_name()); attribute.addSpectrumListener(this); attribute.addErrorListener(this); Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + " was hired to the Collector list..."); - startCollecting(); } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -468,8 +470,8 @@ public class NumberSpectrum_RW extends HdbCollector implements ISpectrumListener super.setLastTimestamp(snapSpectrumEvent_RW); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing NumberSpectrum_RW value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); Util.out4.println("SpectrumEvent_RW.processEventSpectrum/ArchivingException"); diff --git a/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RO.java b/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RO.java index 498f3e60ab94ba2a7e206433dac9f3be85018aa4..de3aa796ecea3fa1b57e883b482bb3248040d17c 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RO.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RO.java @@ -156,17 +156,14 @@ public class StringSpectrum_RO extends HdbCollector implements IStringSpectrumLi * while ( ( IStringSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IStringSpectrum attribute = (IStringSpectrum) attributeList.get(attributeName); if (attribute != null) { - attribute.removeListener(this); attribute.removeErrorListener(this); removeTimestamps(attributeName); attributeList.remove(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -174,6 +171,8 @@ public class StringSpectrum_RO extends HdbCollector implements IStringSpectrumLi final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -181,20 +180,21 @@ public class StringSpectrum_RO extends HdbCollector implements IStringSpectrumLi protected synchronized void addSourceForPolling(final AttributeLightMode attributeLightMode) throws ArchivingException { try { - + stopCollecting(); final IStringSpectrum attribute = (IStringSpectrum) attributeList.add(attributeLightMode .getAttribute_complete_name()); attribute.addListener(this); attribute.addErrorListener(this); Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + " was hired to the Collector list..."); - startCollecting(); } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -466,8 +466,8 @@ public class StringSpectrum_RO extends HdbCollector implements IStringSpectrumLi super.setLastTimestamp(snapSpectrumEvent_RO); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing StringSpectrum_RO value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); try_number--; if (try_number > 0) { diff --git a/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RW.java b/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RW.java index e51bc567acb0de549715b9f136b2e1d10fc9db7e..f8f968c9c438446dda0dbcf730376b360128722e 100644 --- a/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RW.java +++ b/src/main/java/HdbArchiver/Collector/spectrum/StringSpectrum_RW.java @@ -84,6 +84,7 @@ public class StringSpectrum_RW extends HdbCollector implements IStringSpectrumLi * while ( ( IStringSpectrum ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IStringSpectrum attribute = (IStringSpectrum) attributeList.get(attributeName); if (attribute != null) { @@ -92,9 +93,6 @@ public class StringSpectrum_RW extends HdbCollector implements IStringSpectrumLi removeTimestamps(attributeName); attributeList.remove(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); - if (attributeList.isEmpty()) { - stopCollecting(); - } } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -102,27 +100,30 @@ public class StringSpectrum_RW extends HdbCollector implements IStringSpectrumLi final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @Override protected void addSourceForPolling(final AttributeLightMode attributeLightMode) throws ArchivingException { try { - synchronized (attributeList) { - final IStringSpectrum attribute = (IStringSpectrum) attributeList.add(attributeLightMode - .getAttribute_complete_name()); - attribute.addListener(this); - attribute.addErrorListener(this); - Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() - + " was hired to the Collector list..."); - startCollecting(); - } + stopCollecting(); + final IStringSpectrum attribute = (IStringSpectrum) attributeList.add(attributeLightMode + .getAttribute_complete_name()); + attribute.addListener(this); + attribute.addErrorListener(this); + Util.out4.println("\t The attribute named " + attributeLightMode.getAttribute_complete_name() + + " was hired to the Collector list..."); + } catch (final ConnectionException e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing Spectrum_RO.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } @@ -400,8 +401,8 @@ public class StringSpectrum_RW extends HdbCollector implements IStringSpectrumLi super.setLastTimestamp(snapSpectrumEvent_RW); } catch (final ArchivingException e) { final String message = "Problem (ArchivingException) storing StringSpectrum_RW value"; - super.m_logger.trace(ILogger.LEVEL_ERROR, message); - super.m_logger.trace(ILogger.LEVEL_ERROR, e); + super.logger.trace(ILogger.LEVEL_ERROR, message); + super.logger.trace(ILogger.LEVEL_ERROR, e); Util.out4.println("StringSpectrumEvent_RW.processEventSpectrum/ArchivingException"); diff --git a/src/main/java/HdbArchiver/HdbArchiver.java b/src/main/java/HdbArchiver/HdbArchiver.java index 101d3ffe0bc4c58a19b72bf11b4e90a9f00dff53..87327f0d236c0073c55f115b72909b382c4f5ee3 100644 --- a/src/main/java/HdbArchiver/HdbArchiver.java +++ b/src/main/java/HdbArchiver/HdbArchiver.java @@ -361,10 +361,12 @@ package HdbArchiver; import java.sql.Timestamp; import java.util.Arrays; import java.util.Enumeration; -import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; import java.util.Map; +import java.util.Set; import java.util.Vector; +import java.util.concurrent.Executors; import org.omg.CORBA.SystemException; import org.omg.CORBA.UserException; @@ -374,7 +376,6 @@ import HdbArchiver.Collector.HdbCollector; import HdbArchiver.Collector.HdbCollectorFactory; import fr.esrf.Tango.DevError; import fr.esrf.Tango.DevFailed; -import fr.esrf.Tango.DevState; import fr.esrf.Tango.ErrSeverity; import fr.esrf.TangoApi.DbDatum; import fr.esrf.TangoDs.Attribute; @@ -542,7 +543,8 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { public static final short NA = 10; public static final short SUCCEEDED = 20; public static final short FAILED = 30; - private final Map<String, Boolean> archivingStatus = new HashMap<String, Boolean>(); + private final Set<String> koAttributes = new HashSet<String>(); + private final Set<String> okAttributes = new HashSet<String>(); private ILogger logger; private String dbSchema; @@ -616,8 +618,8 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { attr_image_charge_read = 0; attr_spectrum_charge_read = 0; attr_scalar_charge_read = 0; - archivingStatus.clear(); - + koAttributes.clear(); + okAttributes.clear(); get_logger().info("DbHost = " + dbHost); get_logger().info("DbName = " + dbName); get_logger().info("dbUser = " + dbUser); @@ -640,26 +642,8 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { get_logger().error("ERROR : Database unconnected !!"); } else { setControlMode(safetyPeriod); - try { - final Vector<AttributeLightMode> myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name); - if (myCurrentTasks.size() > 0) { - final ArchivingMessConfig archivingMessConfig = ArchivingMessConfig.basicObjectCreation(); - for (final AttributeLightMode attributeLightMode : myCurrentTasks) { - archivingMessConfig.add(attributeLightMode); - } - launchStartArchivingTask(archivingMessConfig, false, false); - } else { - TangoStateUtils.setOn(this, archivingStatus); - } - } catch (final ArchivingException e) { - TangoStateUtils.setFault(this, e.getMessage()); - get_logger().error(e.toString()); - Util.out2.println(e.toString()); - } catch (final DevFailed devFailed) { - final String message = DBTools.getCompleteMessage(devFailed); - get_logger().error(message); - TangoStateUtils.setFault(this, message); - } + // start archiving in a thread + Executors.newSingleThreadExecutor().submit(new InitDeviceTask()); } } @@ -683,6 +667,33 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { } } + private class InitDeviceTask implements Runnable { + @Override + public void run() { + + Vector<AttributeLightMode> myCurrentTasks = null; + try { + myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name); + } catch (ArchivingException e) { + logger.trace(ILogger.LEVEL_ERROR, "cannot getArchiverCurrentTasks " + e); + TangoStateUtils.setFault(HdbArchiver.this, e.getMessage()); + } + + try { + if (myCurrentTasks != null && myCurrentTasks.size() > 0) { + final ArchivingMessConfig archivingMessConfig = ArchivingMessConfig.basicObjectCreation(); + for (final AttributeLightMode attributeLightMode : myCurrentTasks) { + archivingMessConfig.add(attributeLightMode); + } + triggerArchiving(archivingMessConfig.toArray(), false); + } + } catch (final DevFailed devFailed) { + } finally { + TangoStateUtils.updateState(HdbArchiver.this, koAttributes, okAttributes); + } + } + } + private class StartArchivingRunnable implements Runnable { private final ArchivingMessConfig archivingMessConfig; @@ -698,11 +709,17 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { try { triggerArchiving(archivingMessConfig.toArray(), updateAMTTable); } catch (final DevFailed devFailed) { - TangoStateUtils.setDisable(HdbArchiver.this, archivingStatus); + } finally { + TangoStateUtils.updateState(HdbArchiver.this, koAttributes, okAttributes); } + } } + public String[] getKOAttributes() { + return koAttributes.toArray(new String[koAttributes.size()]); + } + /** * @param safetyPeriod2 */ @@ -1003,9 +1020,11 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { // ========================================================= public void trigger_archive_conf(final String[] argin) throws DevFailed { TangoStateUtils.isAllowed(this); - TangoStateUtils.setRunning(this); - triggerArchiving(argin, true); - + try { + triggerArchiving(argin, true); + } finally { + TangoStateUtils.updateState(this, koAttributes, okAttributes); + } } private void triggerArchiving(final String[] argin, final boolean updateAMTTable) throws DevFailed { @@ -1111,7 +1130,8 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { // --------------------------------------------------------------------------// } - archivingStatus.put(attCompleteName, true); + okAttributes.add(attCompleteName); + koAttributes.remove(attCompleteName); logger.trace(ILogger.LEVEL_INFO, "OK: " + attCompleteName); } catch (final ArchivingException e) { try { @@ -1124,13 +1144,22 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { final String desc = "impossible to start " + attCompleteName; archivingException.addStack(message, reason, ErrSeverity.PANIC, desc, "", e); logger.trace(ILogger.LEVEL_ERROR, reason + " " + desc); - archivingStatus.put(attCompleteName, false); + koAttributes.add(attCompleteName); + okAttributes.remove(attCompleteName); logger.trace(ILogger.LEVEL_INFO, "KO: " + attCompleteName); + } catch (Exception e) { + try { + collectorFactory.remove(attCompleteName); + } catch (final ArchivingException e1) { + } + koAttributes.add(attCompleteName); + okAttributes.remove(attCompleteName); + e.printStackTrace(); + logger.trace(ILogger.LEVEL_ERROR, "KO " + attCompleteName + " unexpected " + e); } } computeLoads(); - TangoStateUtils.setOn(this, archivingStatus); if (!archivingException.getMessage().equals("")) { logger.trace(ILogger.LEVEL_INFO, "trigger_archive_conf ERROR - out"); throw archivingException.toTangoException(); @@ -1726,7 +1755,6 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { // ========================================================= public void stop_archive_att(final String[] argin) throws DevFailed { TangoStateUtils.isAllowed(this); - boolean wasDisable = get_state().equals(DevState.DISABLE) ? true : false; TangoStateUtils.setRunning(this); logger.trace(ILogger.LEVEL_INFO, "stop_archive_att - in"); @@ -1762,18 +1790,15 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { * desc , ""); */ } - archivingStatus.remove(attributeLightMode.getAttribute_complete_name()); + koAttributes.remove(attributeLightMode.getAttribute_complete_name()); + okAttributes.remove(attributeLightMode.getAttribute_complete_name()); } catch (final ArchivingException e) { logger.trace(ILogger.LEVEL_ERROR, e); e.printStackTrace(); throw e.toTangoException(); } finally { computeLoads(); - if (wasDisable) { - TangoStateUtils.setDisable(this, archivingStatus); - } else { - TangoStateUtils.setOn(this, archivingStatus); - } + TangoStateUtils.updateState(this, koAttributes, okAttributes); logger.trace(ILogger.LEVEL_INFO, "stop_archive_att - out"); } @@ -1793,7 +1818,7 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { // ---Add your Own code to control device here --- final StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(TangoStateUtils.statusToString(archivingStatus)); + stringBuffer.append(TangoStateUtils.statusToString(koAttributes, okAttributes)); stringBuffer.append(collectorFactory.factoryAssessment()); argout = stringBuffer.toString(); diff --git a/src/main/java/HdbArchiver/HdbArchiverClass.java b/src/main/java/HdbArchiver/HdbArchiverClass.java index 9f0b4ddfb95be976673e7785ea69dd67bfed5517..d2ae1499dcd14e8e4779d8ede195eff235687f6b 100644 --- a/src/main/java/HdbArchiver/HdbArchiverClass.java +++ b/src/main/java/HdbArchiver/HdbArchiverClass.java @@ -77,304 +77,349 @@ import fr.esrf.TangoDs.Attr; import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.DeviceImpl; import fr.esrf.TangoDs.TangoConst; +import fr.esrf.TangoDs.TemplCommandOut; import fr.esrf.TangoDs.Util; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Mode.ShortPeriodAttributesManager; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Tools.ArchivingException; public class HdbArchiverClass extends DeviceClass implements TangoConst { - /** - * HdbArchiverClass class instance (it is a singleton). - */ - private static HdbArchiverClass _instance = null; - - /** - * Class properties array. - */ - private DbDatum[] cl_prop = null; - - // --------- Start of properties data members ---------- - - /** - * Computer identifier on wich is settled the database HDB. The identifier - * can be the computer name or its IP address. <br> - * <b>Default value : </b> localhost - */ - String dbHost; - /** - * Database name.<br> - * <b>Default value : </b> hdb - */ - String dbName; - /** - * true if the 'facility' information is appended to all device's (or - * attributes) name. false otherwise.<br> - * <b>Default value : </b> false - */ - boolean facility; - - /** - * true if the ORACLE RAC connection is activated. This information is - * appended to all device's (or attributes) name. false otherwise.<br> - * <b>Default value : </b> false + /** + * HdbArchiverClass class instance (it is a singleton). + */ + private static HdbArchiverClass _instance = null; + + /** + * Class properties array. + */ + private DbDatum[] cl_prop = null; + + // --------- Start of properties data members ---------- + + /** + * Computer identifier on wich is settled the database HDB. The identifier + * can be the computer name or its IP address. <br> + * <b>Default value : </b> localhost + */ + String dbHost; + /** + * Database name.<br> + * <b>Default value : </b> hdb + */ + String dbName; + /** + * true if the 'facility' information is appended to all device's (or + * attributes) name. false otherwise.<br> + * <b>Default value : </b> false + */ + boolean facility; + + /** + * true if the ORACLE RAC connection is activated. This information is + * appended to all device's (or attributes) name. false otherwise.<br> + * <b>Default value : </b> false + */ + boolean RacConnection; + + // --------- End of properties data members ---------- + + // =================================================================== + // + // method : instance() + // + // description : static method to retrieve the HdbArchiverClass object + // once it has been initialised + // + // =================================================================== + public static HdbArchiverClass instance() { + if (_instance == null) { + System.err.println("HdbArchiverClass is not initialised !!!"); + System.err.println("Exiting"); + System.exit(-1); + } + return _instance; + } + + // =================================================================== + // + // method : Init() + // + // description : static method to create/retrieve the HdbArchiverClass + // object. This method is the only one which enables a + // user to create the object + // + // in : - class_name : The class name + // + // =================================================================== + public static synchronized HdbArchiverClass init(String class_name) throws DevFailed { + if (_instance == null) { + try { + // First call to this method. + // It initializes the short period attributes map + ShortPeriodAttributesManager.getShortPeriodAttributes(); + } catch (ArchivingException e) { + e.printStackTrace(); + throw new DevFailed(); + } + _instance = new HdbArchiverClass(class_name); + } + return _instance; + } + + // =================================================================== + // + // method : HdbArchiverClass() + // + // description : constructor for the HdbArchiverClass class + // + // argument : in : - name : The class name + // + // =================================================================== + protected HdbArchiverClass(String name) throws DevFailed { + super(name); + + Util.out2.println("Entering HdbArchiverClass constructor"); + write_class_property(); + get_class_property(); + + Util.out2.println("Leaving HdbArchiverClass constructor"); + } + + // =================================================================== + // + // method : command_factory() + // + // description : Create the command object(s) and store them in the + // command list + // =================================================================== + @Override + public void command_factory() { + command_list + .addElement(new GetErrorDomainsInternal("GetErrorDomainsInternal", Tango_DEV_VOID, + Tango_DEVVAR_STRINGARRAY, "", + "The list of all domains that have at least one attribute not correctly archiving", + DispLevel.OPERATOR)); + + command_list.addElement(new GetErrorsForDomainInternal("GetErrorsForDomainInternal", Tango_DEV_STRING, + Tango_DEVVAR_STRINGARRAY, "The domain name", "The list of all KO attributes for this domain", + DispLevel.OPERATOR)); + + command_list.addElement(new GetErrorsForAttributeInternal("GetErrorsForAttributeInternal", Tango_DEV_STRING, + Tango_DEVVAR_STRINGARRAY, "The attribute name (NOT the complete name)", + "The list of all KO attributes sharing this name", DispLevel.OPERATOR)); + + command_list.addElement(new IsAttributeCorrectlyArchivedInternal("IsAttributeCorrectlyArchivedInternal", + Tango_DEV_STRING, Tango_DEV_BOOLEAN, "The complete name of the attribute", + "True if this attribute is archiving correctly", DispLevel.OPERATOR)); + + command_list + .addElement(new RetryForKOAttributes( + "RetryForKOAttributes", + Tango_DEV_VOID, + Tango_DEV_SHORT, + "", + "A return code, can be either: 10 (the archiver isn't in charge of any attribute, or they are all correctly archiving) 20 (the retry succeeded) or 30 (the retry failed)", + DispLevel.OPERATOR)); + + command_list + .addElement(new RetryForAll( + "RetryForAll", + Tango_DEV_VOID, + Tango_DEV_SHORT, + "", + "A return code, can be either: 10 (the archiver isn't in charge of any attribute) 20 (the retry succeeded) or 30 (the retry failed)", + DispLevel.OPERATOR)); + + command_list + .addElement(new RetryForAttributesCmd( + "RetryForAttributes", + Tango_DEVVAR_STRINGARRAY, + Tango_DEV_SHORT, + "The complete names of the attributes", + "A return code, can be either: 10 (the archiver isn't in charge of any of the specified attributes) 20 (the retry succeeded) or 30 (the retry failed)", + DispLevel.OPERATOR)); + + command_list + .addElement(new RetryForAttributeCmd( + "RetryForAttribute", + Tango_DEV_STRING, + Tango_DEV_SHORT, + "The complete name of the attribute", + "A return code, can be either: 10 (the archiver isn't in charge of the specified attribute) 20 (the retry succeeded) or 30 (the retry failed)", + DispLevel.OPERATOR)); + + command_list.addElement(new TriggerArchiveConfCmd("TriggerArchiveConf", Tango_DEVVAR_STRINGARRAY, + Tango_DEV_VOID, "The group of attributes to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new TriggerArchiveAttCmd("TriggerArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "The attribute to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new TriggerArchiveAttCheckCmd("TriggerArchiveAttCheck", Tango_DEV_STRING, + Tango_DEV_VOID, "The name of the attribute to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new StopArchiveConfCmd("StopArchiveConf", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "The group of attributes", "", DispLevel.OPERATOR)); + command_list.addElement(new StopArchiveAttCmd("StopArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "the attribute on witch archiving must be stopped", "", DispLevel.OPERATOR)); + command_list.addElement(new StateDetailedClass("StateDetailed", Tango_DEV_VOID, Tango_DEV_STRING, "", + "The detailed state", DispLevel.EXPERT)); + command_list.addElement(new TemplCommandOut("GetKOAttributes", "getKOAttributes")); + // add polling if any + /* + * for (int i = 0; i < command_list.size(); i++) { // Command cmd = ( + * Command ) command_list.elementAt(i); } */ - boolean RacConnection; - - // --------- End of properties data members ---------- - - // =================================================================== - // - // method : instance() - // - // description : static method to retrieve the HdbArchiverClass object - // once it has been initialised - // - // =================================================================== - public static HdbArchiverClass instance() { - if (_instance == null) { - System.err.println("HdbArchiverClass is not initialised !!!"); - System.err.println("Exiting"); - System.exit(-1); - } - return _instance; + } + + // =================================================================== + // + // method : device_factory() + // + // description : Create the device object(s) and store them in the + // device list + // + // argument : in : String[] devlist : The device name list + // + // =================================================================== + @Override + public void device_factory(String[] devlist) throws DevFailed { + String device_version = ResourceBundle.getBundle("application").getString("project.version"); + + for (int i = 0; i < devlist.length; i++) { + // Util.out4.println("Device name : " + devlist[ i ]); + + // Create device and add it into the device list + // ---------------------------------------------- + + device_list.addElement(new HdbArchiver(this, devlist[i], device_version)); + + // Export device to the outside world + // ---------------------------------------------- + if (Util._UseDb == true) { + export_device(((DeviceImpl) device_list.elementAt(i))); + } else { + export_device(((DeviceImpl) device_list.elementAt(i)), devlist[i]); + } } - - // =================================================================== - // - // method : Init() - // - // description : static method to create/retrieve the HdbArchiverClass - // object. This method is the only one which enables a - // user to create the object - // - // in : - class_name : The class name - // - // =================================================================== - public static synchronized HdbArchiverClass init(String class_name) throws DevFailed { - if (_instance == null) { - try { - // First call to this method. - // It initializes the short period attributes map - ShortPeriodAttributesManager.getShortPeriodAttributes(); - } catch (ArchivingException e) { - e.printStackTrace(); - throw new DevFailed(); - } - _instance = new HdbArchiverClass(class_name); - } - return _instance; + } + + // ============================================================================= + // + // Method: attribute_factory(Vector att_list) + // + // ============================================================================= + @Override + public void attribute_factory(Vector att_list) throws DevFailed { + // Attribute : scalar_charge + Attr scalar_charge = new Attr("scalar_charge", Tango_DEV_SHORT, AttrWriteType.READ); + att_list.addElement(scalar_charge); + + // Attribute : spectrum_charge + Attr spectrum_charge = new Attr("spectrum_charge", Tango_DEV_SHORT, AttrWriteType.READ); + att_list.addElement(spectrum_charge); + + // Attribute : image_charge + Attr image_charge = new Attr("image_charge", Tango_DEV_SHORT, AttrWriteType.READ); + att_list.addElement(image_charge); + + // Attribute : version + Attr version = new Attr("version", Tango_DEV_STRING, AttrWriteType.READ); + att_list.addElement(version); + + } + + // =================================================================== + /** + * Get the class property for specified name. + * + * @param name + * The property name. + */ + // =================================================================== + public DbDatum get_class_property(String name) { + for (int i = 0; i < cl_prop.length; i++) { + if (cl_prop[i].name.equals(name)) { + return cl_prop[i]; + } } - - // =================================================================== - // - // method : HdbArchiverClass() - // - // description : constructor for the HdbArchiverClass class - // - // argument : in : - name : The class name - // - // =================================================================== - protected HdbArchiverClass(String name) throws DevFailed { - super(name); - - Util.out2.println("Entering HdbArchiverClass constructor"); - write_class_property(); - get_class_property(); - - Util.out2.println("Leaving HdbArchiverClass constructor"); + // if not found, return an empty DbDatum + return new DbDatum(name); + } + + // =================================================================== + /** + * Read the class properties from database. + */ + // =================================================================== + public void get_class_property() throws DevFailed { + // Initialize your default values here. + // ------------------------------------------ + + // Read class properties from database.(Automatic code generation) + // ------------------------------------------------------------- + if (Util._UseDb == false) { + return; } - - // =================================================================== - // - // method : command_factory() - // - // description : Create the command object(s) and store them in the - // command list - // =================================================================== - @Override - public void command_factory() { - command_list.addElement(new GetErrorDomainsInternal("GetErrorDomainsInternal", Tango_DEV_VOID, Tango_DEVVAR_STRINGARRAY, "", - "The list of all domains that have at least one attribute not correctly archiving", DispLevel.OPERATOR)); - - command_list.addElement(new GetErrorsForDomainInternal("GetErrorsForDomainInternal", Tango_DEV_STRING, Tango_DEVVAR_STRINGARRAY, "The domain name", - "The list of all KO attributes for this domain", DispLevel.OPERATOR)); - - command_list.addElement(new GetErrorsForAttributeInternal("GetErrorsForAttributeInternal", Tango_DEV_STRING, Tango_DEVVAR_STRINGARRAY, "The attribute name (NOT the complete name)", - "The list of all KO attributes sharing this name", DispLevel.OPERATOR)); - - command_list.addElement(new IsAttributeCorrectlyArchivedInternal("IsAttributeCorrectlyArchivedInternal", Tango_DEV_STRING, Tango_DEV_BOOLEAN, "The complete name of the attribute", - "True if this attribute is archiving correctly", DispLevel.OPERATOR)); - - command_list.addElement(new RetryForKOAttributes("RetryForKOAttributes", Tango_DEV_VOID, Tango_DEV_SHORT, "", - "A return code, can be either: 10 (the archiver isn't in charge of any attribute, or they are all correctly archiving) 20 (the retry succeeded) or 30 (the retry failed)", - DispLevel.OPERATOR)); - - command_list.addElement(new RetryForAll("RetryForAll", Tango_DEV_VOID, Tango_DEV_SHORT, "", - "A return code, can be either: 10 (the archiver isn't in charge of any attribute) 20 (the retry succeeded) or 30 (the retry failed)", DispLevel.OPERATOR)); - - command_list.addElement(new RetryForAttributesCmd("RetryForAttributes", Tango_DEVVAR_STRINGARRAY, Tango_DEV_SHORT, "The complete names of the attributes", - "A return code, can be either: 10 (the archiver isn't in charge of any of the specified attributes) 20 (the retry succeeded) or 30 (the retry failed)", DispLevel.OPERATOR)); - - command_list.addElement(new RetryForAttributeCmd("RetryForAttribute", Tango_DEV_STRING, Tango_DEV_SHORT, "The complete name of the attribute", - "A return code, can be either: 10 (the archiver isn't in charge of the specified attribute) 20 (the retry succeeded) or 30 (the retry failed)", DispLevel.OPERATOR)); - - command_list.addElement(new TriggerArchiveConfCmd("TriggerArchiveConf", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "The group of attributes to archive", "", DispLevel.OPERATOR)); - command_list.addElement(new TriggerArchiveAttCmd("TriggerArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "The attribute to archive", "", DispLevel.OPERATOR)); - command_list.addElement(new TriggerArchiveAttCheckCmd("TriggerArchiveAttCheck", Tango_DEV_STRING, Tango_DEV_VOID, "The name of the attribute to archive", "", DispLevel.OPERATOR)); - command_list.addElement(new StopArchiveConfCmd("StopArchiveConf", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "The group of attributes", "", DispLevel.OPERATOR)); - command_list.addElement(new StopArchiveAttCmd("StopArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "the attribute on witch archiving must be stopped", "", DispLevel.OPERATOR)); - command_list.addElement(new StateDetailedClass("StateDetailed", Tango_DEV_VOID, Tango_DEV_STRING, "", "The detailed state", DispLevel.EXPERT)); - - // add polling if any - /* - * for (int i = 0; i < command_list.size(); i++) { // Command cmd = ( - * Command ) command_list.elementAt(i); } - */ + String[] propnames = { "DbHost", "DbName", "Facility", "RacConnection" }; + + // Call database and extract values + // -------------------------------------------- + cl_prop = get_db_class().get_property(propnames); + int i = -1; + // Extract DbHost value + if (cl_prop[++i].is_empty() == false) { + dbHost = cl_prop[i].extractString(); + } else { + cl_prop[i].insert(dbHost); } - // =================================================================== - // - // method : device_factory() - // - // description : Create the device object(s) and store them in the - // device list - // - // argument : in : String[] devlist : The device name list - // - // =================================================================== - @Override - public void device_factory(String[] devlist) throws DevFailed { - String device_version = ResourceBundle.getBundle("application").getString("project.version"); - - for (int i = 0; i < devlist.length; i++) { - // Util.out4.println("Device name : " + devlist[ i ]); - - // Create device and add it into the device list - // ---------------------------------------------- - - device_list.addElement(new HdbArchiver(this, devlist[i], device_version)); - - // Export device to the outside world - // ---------------------------------------------- - if (Util._UseDb == true) - export_device(((DeviceImpl) (device_list.elementAt(i)))); - else - export_device(((DeviceImpl) (device_list.elementAt(i))), devlist[i]); - } + // Extract DbName value + if (cl_prop[++i].is_empty() == false) { + dbName = cl_prop[i].extractString(); + } else { + cl_prop[i].insert(dbName); } - // ============================================================================= - // - // Method: attribute_factory(Vector att_list) - // - // ============================================================================= - @Override - public void attribute_factory(Vector att_list) throws DevFailed { - // Attribute : scalar_charge - Attr scalar_charge = new Attr("scalar_charge", Tango_DEV_SHORT, AttrWriteType.READ); - att_list.addElement(scalar_charge); - - // Attribute : spectrum_charge - Attr spectrum_charge = new Attr("spectrum_charge", Tango_DEV_SHORT, AttrWriteType.READ); - att_list.addElement(spectrum_charge); - - // Attribute : image_charge - Attr image_charge = new Attr("image_charge", Tango_DEV_SHORT, AttrWriteType.READ); - att_list.addElement(image_charge); - - // Attribute : version - Attr version = new Attr("version", Tango_DEV_STRING, AttrWriteType.READ); - att_list.addElement(version); + // Extract Facility value + if (cl_prop[++i].is_empty() == false) { + facility = cl_prop[i].extractBoolean(); + } else { + cl_prop[i].insert(facility); + } + // Extract RacConnection value + if (cl_prop[++i].is_empty() == false) { + RacConnection = cl_prop[i].extractBoolean(); + } else { + cl_prop[i].insert(RacConnection); } - // =================================================================== - /** - * Get the class property for specified name. - * - * @param name - * The property name. - */ - // =================================================================== - public DbDatum get_class_property(String name) { - for (int i = 0; i < cl_prop.length; i++) - if (cl_prop[i].name.equals(name)) - return cl_prop[i]; - // if not found, return an empty DbDatum - return new DbDatum(name); + // End of Automatic code generation + // ------------------------------------------------------------- + + } + + // =================================================================== + /** + * Set class description as property in database + */ + // =================================================================== + private void write_class_property() throws DevFailed { + // First time, check if database used + // -------------------------------------------- + if (Util._UseDb == false) { + return; } - // =================================================================== - /** - * Read the class properties from database. - */ - // =================================================================== - public void get_class_property() throws DevFailed { - // Initialize your default values here. - // ------------------------------------------ - - // Read class properties from database.(Automatic code generation) - // ------------------------------------------------------------- - if (Util._UseDb == false) - return; - String[] propnames = { "DbHost", "DbName", "Facility", "RacConnection" }; - - // Call database and extract values - // -------------------------------------------- - cl_prop = get_db_class().get_property(propnames); - int i = -1; - // Extract DbHost value - if (cl_prop[++i].is_empty() == false) - dbHost = cl_prop[i].extractString(); - else - cl_prop[i].insert(dbHost); - - // Extract DbName value - if (cl_prop[++i].is_empty() == false) - dbName = cl_prop[i].extractString(); - else - cl_prop[i].insert(dbName); - - // Extract Facility value - if (cl_prop[++i].is_empty() == false) - facility = cl_prop[i].extractBoolean(); - else - cl_prop[i].insert(facility); - - // Extract RacConnection value - if (cl_prop[++i].is_empty() == false) - RacConnection = cl_prop[i].extractBoolean(); - else - cl_prop[i].insert(RacConnection); - - // End of Automatic code generation - // ------------------------------------------------------------- + // Prepeare DbDatum + // -------------------------------------------- + DbDatum[] data = new DbDatum[2]; + data[0] = new DbDatum("ProjectTitle"); + data[0].insert("Tango Device Server"); - } + data[1] = new DbDatum("Description"); + data[1].insert("Device of Archiving system"); - // =================================================================== - /** - * Set class description as property in database - */ - // =================================================================== - private void write_class_property() throws DevFailed { - // First time, check if database used - // -------------------------------------------- - if (Util._UseDb == false) - return; - - // Prepeare DbDatum - // -------------------------------------------- - DbDatum[] data = new DbDatum[2]; - data[0] = new DbDatum("ProjectTitle"); - data[0].insert("Tango Device Server"); - - data[1] = new DbDatum("Description"); - data[1].insert("Device of Archiving system"); - - // Call database and and values - // -------------------------------------------- - get_db_class().put_property(data); - } + // Call database and and values + // -------------------------------------------- + get_db_class().put_property(data); + } } diff --git a/src/main/java/HdbArchivingWatcher/HdbArchivingWatcher.java b/src/main/java/HdbArchivingWatcher/HdbArchivingWatcher.java index bae74a001ad85966a2d4b81dc46a1d93283b7067..f035cad71212fd17e4198b0fdc5bebd4e9bc11d8 100644 --- a/src/main/java/HdbArchivingWatcher/HdbArchivingWatcher.java +++ b/src/main/java/HdbArchivingWatcher/HdbArchivingWatcher.java @@ -1,5 +1,7 @@ package HdbArchivingWatcher; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Hashtable; import java.util.Iterator; @@ -15,7 +17,13 @@ import fr.esrf.Tango.DevError; import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevState; import fr.esrf.Tango.ErrSeverity; +import fr.esrf.TangoApi.ApiUtil; import fr.esrf.TangoApi.DbDatum; +import fr.esrf.TangoApi.DeviceData; +import fr.esrf.TangoApi.DeviceProxy; +import fr.esrf.TangoApi.Group.Group; +import fr.esrf.TangoApi.Group.GroupCmdReply; +import fr.esrf.TangoApi.Group.GroupCmdReplyList; import fr.esrf.TangoDs.Attribute; import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.Except; @@ -23,6 +31,7 @@ import fr.esrf.TangoDs.Util; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.ILogger; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.LoggerFactory; import fr.soleil.hdbtdbArchivingApi.ArchivingApi.ConfigConst; +import fr.soleil.hdbtdbArchivingApi.ArchivingManagerApi.HdbArchivingManagerApiRef; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Mode.Mode; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Tools.ArchivingException; import fr.soleil.hdbtdbArchivingApi.ArchivingWatchApi.ArchivingWatch; @@ -194,6 +203,34 @@ public class HdbArchivingWatcher extends AbsArchivingWatcher { } // =================================================================== + /** + * ask all archivers for their KO attributes + * + * @return + * @throws DevFailed + */ + public String[] getKOAttributesFromArchivers(boolean doRetry) throws DevFailed { + List<String> archiversStatus = new ArrayList<String>(); + String[] archiverNames = ApiUtil.get_db_obj().get_device_exported_for_class( + HdbArchivingManagerApiRef.classDevice); + Group group = new Group("archivers"); + group.add(archiverNames); + GroupCmdReplyList replies = group.command_inout("GetKOAttributes", true); + for (Object reply : replies) { + GroupCmdReply r = (GroupCmdReply) reply; + try { + DeviceData result = r.get_data(); + String archiverStatus = r.dev_name() + " " + Arrays.toString(result.extractStringArray()); + archiversStatus.add(archiverStatus); + if (doRetry) { + new DeviceProxy(r.dev_name()).command_inout_asynch("RetryForAttribute", result, true); + } + } catch (DevFailed e) { + archiversStatus.add(r.dev_name() + " ERROR"); + } + } + return archiversStatus.toArray(new String[archiversStatus.size()]); + } // =================================================================== /** diff --git a/src/main/java/HdbArchivingWatcher/HdbArchivingWatcherClass.java b/src/main/java/HdbArchivingWatcher/HdbArchivingWatcherClass.java index 21d2cbcd445794a9991d252e19d835675e105a86..d0ab11ff06a2cf64230784db3deae131f9188348 100644 --- a/src/main/java/HdbArchivingWatcher/HdbArchivingWatcherClass.java +++ b/src/main/java/HdbArchivingWatcher/HdbArchivingWatcherClass.java @@ -95,6 +95,7 @@ import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.DeviceImpl; import fr.esrf.TangoDs.SpectrumAttr; import fr.esrf.TangoDs.TangoConst; +import fr.esrf.TangoDs.TemplCommandInOut; import fr.esrf.TangoDs.UserDefaultAttrProp; import fr.esrf.TangoDs.Util; @@ -265,6 +266,8 @@ public class HdbArchivingWatcherClass extends DeviceClass implements TangoConst command_list.addElement(new GetFeedAliveProgressionClass("GetFeedAliveProgression", Tango_DEV_VOID, Tango_DEV_LONG, "", "Percentage of the feedalive execution ", DispLevel.OPERATOR)); + command_list.addElement(new TemplCommandInOut("GetKOAttributesFromArchivers", "getKOAttributesFromArchivers", + "do a retry", "the list of ko per archiver")); // add polling if any /* * for (int i = 0; i < command_list.size(); i++) { Command cmd = diff --git a/src/main/java/TdbArchiver/Collector/DbProxy.java b/src/main/java/TdbArchiver/Collector/DbProxy.java index 6a48b6b67b0920aa4f1b818cfec85df34606cb8b..23cd6598646bffe5e234514bec5839462908a005 100644 --- a/src/main/java/TdbArchiver/Collector/DbProxy.java +++ b/src/main/java/TdbArchiver/Collector/DbProxy.java @@ -69,9 +69,12 @@ package TdbArchiver.Collector; import java.util.Vector; +import fr.esrf.Tango.DevFailed; +import fr.esrf.Tango.ErrSeverity; import fr.esrf.TangoApi.Database; import fr.esrf.TangoDs.Util; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.ILogger; +import fr.soleil.commonarchivingapi.ArchivingTools.Tools.GlobalConst; import fr.soleil.hdbtdbArchivingApi.ArchivingApi.ConfigConst; import fr.soleil.hdbtdbArchivingApi.ArchivingApi.DataBaseManager; import fr.soleil.hdbtdbArchivingApi.ArchivingApi.TDBDataBaseManager; @@ -166,11 +169,7 @@ public class DbProxy { tableName, writable); } - public Vector<AttributeLightMode> getArchiverCurrentTasks(final String archiverName) // throws - // ArchivingException - // , DevFailed - { - // System.out.println("DbProxy.getArchiverCurrentTasks"); + public Vector<AttributeLightMode> getArchiverCurrentTasks(final String archiverName) throws ArchivingException { Vector<AttributeLightMode> archiverCurrentTasks; final boolean facility = manager.getFacility(); try { @@ -179,31 +178,20 @@ public class DbProxy { .getMode() .getArchiverCurrentTasks( (facility ? "//" + new Database().get_tango_host() + "/" : "") + archiverName); - System.out.println("Current Tasks (" + archiverCurrentTasks.size() + "): .... \n\r\t"); - for (int i = 0; i < archiverCurrentTasks.size(); i++) { - final AttributeLightMode attributeLightMode = archiverCurrentTasks.elementAt(i); - System.out.println(">>>>>>>>>>>>\t" + i + "\t<<<<<<<<<<<<"); - System.out.println("attributeLightMode.toString() : \r\n" + attributeLightMode.toString() + "\r\n"); - } - return archiverCurrentTasks; + } catch (final DevFailed devFailed) { + final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + GlobalConst.DBT_UNREACH_EXCEPTION; + final String reason = GlobalConst.TANGO_COMM_EXCEPTION; + final String desc = "Failed while executing DbProxy.getArchiverCurrentTasks() method..."; + throw new ArchivingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed); } - /* - * catch ( ArchivingException e ) { System.err.println("ERROR !! " + - * "\r\n" + "\t Origin : \t " + "DbProxy.getArchiverCurrentTasks" + - * "\r\n" + "\t Reason : \t " + e.getClass().getName() + "\r\n" + - * "\t Description : \t " + e.getMessage() + "\r\n" + - * "\t Additional information : \t " + "Unable to get current tasks..." - * + "\r\n"); throw e; } catch ( DevFailed devFailed ) { - * Util.out2.println("ERROR !! " + "\r\n" + "\t Origin : \t " + - * "DbProxy.getArchiverCurrentTasks" + "\r\n" + "\t Reason : \t " + - * "UNKNOWN_ERROR" + "\r\n" + "\t Description : \t " + - * devFailed.getMessage() + "\r\n" + "\t Additional information : \t " + - * "" + "\r\n"); throw devFailed; } - */ - catch (final Exception e) { - e.printStackTrace(); - return null; + System.out.println("Current Tasks (" + archiverCurrentTasks.size() + "): .... \n\r\t"); + for (int i = 0; i < archiverCurrentTasks.size(); i++) { + final AttributeLightMode attributeLightMode = archiverCurrentTasks.elementAt(i); + System.out.println(">>>>>>>>>>>>\t" + i + "\t<<<<<<<<<<<<"); + System.out.println("attributeLightMode.toString() : \r\n" + attributeLightMode.toString() + "\r\n"); } + return archiverCurrentTasks; + } public void deleteOldRecords(final long time, final String[] attributeList) throws ArchivingException { diff --git a/src/main/java/TdbArchiver/Collector/TdbCollector.java b/src/main/java/TdbArchiver/Collector/TdbCollector.java index 6c57a31191bf693cfe8d207be2b7eddb7e874425..e1e202f09bc391ad3b521ae6e3b9d2fca430d78b 100644 --- a/src/main/java/TdbArchiver/Collector/TdbCollector.java +++ b/src/main/java/TdbArchiver/Collector/TdbCollector.java @@ -153,6 +153,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import Common.Archiver.Collector.ArchiverCollector; import TdbArchiver.Collector.Tools.FileTools; @@ -194,11 +195,8 @@ public abstract class TdbCollector extends ArchiverCollector { * This parameter specify the number of time a Collector retry the archiving * of an attribute event */ - // protected static int tryNumber = 1; protected final static int DEFAULT_TRY_NUMBER = 2; - protected KeepingThread keepingThread; - protected long keepingPeriod; private final Map<String, LimitedStack> lastTimestampStacks = new HashMap<String, LimitedStack>(); @@ -209,7 +207,7 @@ public abstract class TdbCollector extends ArchiverCollector { */ private final Map<String, Object> lastValueHashtable = new HashMap<String, Object>(); - protected boolean isFirstValue; + protected volatile Map<String, Boolean> isFirstValueList = new ConcurrentHashMap<String, Boolean>(); protected Warnable warnable; protected DbProxy dbProxy; @@ -224,7 +222,6 @@ public abstract class TdbCollector extends ArchiverCollector { final AttrWriteType writableType) { super(_modeHandler); this.writableType = writableType; - isFirstValue = true; m_currentDbPath = currentDbPath; m_currentDsPath = currentDsPath; } @@ -261,6 +258,7 @@ public abstract class TdbCollector extends ArchiverCollector { public synchronized void addSource(final AttributeLightMode attributeLightMode, final int attributePerFile) throws ArchivingException { try { + stopCollecting(); final String attName = attributeLightMode.getAttribute_complete_name(); final IEntity attribute = attributeList.add(attName); addListeners(attribute); @@ -271,23 +269,17 @@ public abstract class TdbCollector extends ArchiverCollector { addAttribute(attName); // Verify that the recording file exists final String table_name = dbProxy.getDataBase().getDbUtil().getTableName(attName); - if (filesNames.get(attName) == null) { + if (filesNames.get(attName.toLowerCase()) == null) { final FileTools myFile = new FileTools(attName, table_name, attributeLightMode.getData_format(), attributeLightMode.getWritable(), attributeLightMode.getMode().getTdbSpec().getExportPeriod(), - super.m_logger, dbProxy, m_currentDsPath, m_currentDbPath); + super.logger, dbProxy, m_currentDsPath, m_currentDbPath); myFile.setAttributePerFile(attributePerFile); - filesNames.put(attName, myFile); + filesNames.put(attName.toLowerCase(), myFile); } - isFirstValue = true; - startCollecting(); - - if (attributeList.get(attName) == null) { - super.m_logger.trace(ILogger.LEVEL_WARNING, "addSource/The first add test failed for attribute|" - + attName); - } + isFirstValueList.put(attName.toLowerCase(), true); } catch (final ConnectionException e) { - super.m_logger.trace(ILogger.LEVEL_WARNING, e); + super.logger.trace(ILogger.LEVEL_WARNING, e); final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed adding '" + attributeLightMode.getAttribute_complete_name() + "' as source"; @@ -295,9 +287,11 @@ public abstract class TdbCollector extends ArchiverCollector { final String desc = "Failed while executing BooleanScalar.addSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_WARNING, + super.logger.trace(ILogger.LEVEL_WARNING, "Unexpected exception during addSource:" + attributeLightMode.getAttribute_complete_name()); - super.m_logger.trace(ILogger.LEVEL_WARNING, e); + super.logger.trace(ILogger.LEVEL_WARNING, e); + } finally { + startCollecting(); } } @@ -318,10 +312,11 @@ public abstract class TdbCollector extends ArchiverCollector { * while ( ( IBooleanScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IEntity attribute = attributeList.get(attributeName); if (attribute != null) { removeListeners(attribute); - + isFirstValueList.remove(attributeName.toLowerCase()); attributeList.remove(attributeName); // informs the mother class that one new attribute must be @@ -330,13 +325,9 @@ public abstract class TdbCollector extends ArchiverCollector { removeTimestamps(attributeName); Util.out4.println("\t The attribute named " + attributeName + " was fired from the Collector list..."); if (closeFile) { - filesNames.get(attributeName).closeFile(); - filesNames.remove(attributeName); + filesNames.get(attributeName.toLowerCase()).closeFile(); + filesNames.remove(attributeName.toLowerCase()); } - if (attributeList.isEmpty()) { - stopCollecting(); - } - } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -344,56 +335,55 @@ public abstract class TdbCollector extends ArchiverCollector { final String reason = GlobalConst.TANGO_COMM_EXCEPTION; final String desc = "Failed while executing BooleanScalar.removeSource() method..."; throw new ArchivingException(message, reason, ErrSeverity.WARN, desc, "", e); + } finally { + startCollecting(); } } public abstract void removeListeners(IEntity attribute) throws ArchivingException; public String exportFile2Db(final String attributeName) throws IOException, ArchivingException { - m_logger.trace(ILogger.LEVEL_DEBUG, "XXXXXXX FORCING export for " + attributeName); - final String result = filesNames.get(attributeName).switchFile(); - m_logger.trace(ILogger.LEVEL_DEBUG, "Export forced done for " + attributeName + " - " + result); + logger.trace(ILogger.LEVEL_DEBUG, "XXXXXXX FORCING export for " + attributeName); + final String result = filesNames.get(attributeName.toLowerCase()).switchFile(); + logger.trace(ILogger.LEVEL_DEBUG, "Export forced done for " + attributeName + " - " + result); return result; } protected void processFileScalar(final ScalarEvent scalarEvent) throws ArchivingException { String attrName = scalarEvent.getAttribute_complete_name(); - filesNames.get(attrName).processEventScalar(scalarEvent); + filesNames.get(attrName.toLowerCase()).processEventScalar(scalarEvent); } protected void processFileSpectrum(final SpectrumEvent_RO spectrumEvent) throws ArchivingException { String attrName = spectrumEvent.getAttribute_complete_name(); - filesNames.get(attrName).processEventSpectrum(spectrumEvent); + filesNames.get(attrName.toLowerCase()).processEventSpectrum(spectrumEvent); } protected void processFileSpectrum(final SpectrumEvent_RW spectrumEvent) throws ArchivingException { String attrName = spectrumEvent.getAttribute_complete_name(); - filesNames.get(attrName).processEventSpectrum(spectrumEvent); + filesNames.get(attrName.toLowerCase()).processEventSpectrum(spectrumEvent); } protected void processFileImage(final ImageEvent_RO imageEvent) throws ArchivingException { String attrName = imageEvent.getAttribute_complete_name(); - filesNames.get(attrName).processEventImage(imageEvent); + filesNames.get(attrName.toLowerCase()).processEventImage(imageEvent); } /** * Triggers the collecting action of this TdbCollector. */ - public synchronized void startCollecting() { + protected synchronized void startCollecting() { if (!attributeList.isEmpty()) { - if (attributeList.size() == 1) { + if (!attributeList.isRefresherStarted()) { attributeList.setRefreshInterval(m_modeHandler.getRefreshInterval()); attributeList.setSynchronizedPeriod(true); - // force a refresh for newly added attributes - m_logger.trace(ILogger.LEVEL_DEBUG, "start refresh for " + this.getClass()); attributeList.startRefresher(); refreshing = true; - if (keepingThread != null) { - keepingThread.start(); - } + logger.trace(ILogger.LEVEL_DEBUG, this.getClass() + " start refresh for " + attributeList.getSize() + + " attributes"); } else { // force a refresh for newly added attributes - m_logger.trace(ILogger.LEVEL_DEBUG, "FORCING refresh for " + this.getClass()); + logger.trace(ILogger.LEVEL_DEBUG, "FORCING refresh for " + this.getClass()); attributeList.refresh(); } } @@ -402,17 +392,12 @@ public abstract class TdbCollector extends ArchiverCollector { /** * Stops the collecting action of this TdbCollector. */ - public synchronized void stopCollecting() { - Util.out4.println("TdbCollector.stopCollecting"); + protected synchronized void stopCollecting() { try { - if (attributeList.isEmpty()) { - attributeList.stopRefresher(); - if (keepingThread != null) { - keepingThread.destroy(); - keepingThread = null; - } - refreshing = false; - } + logger.trace(ILogger.LEVEL_DEBUG, this.getClass() + " stop refresh on " + attributeList.getSize() + + " attributes"); + attributeList.stopRefresher(); + refreshing = false; } catch (final Exception e) { Util.out2.println("ERROR !! " + "\r\n" + "\t Origin : \t " + "TdbCollector.stopCollecting" + "\r\n" + "\t Reason : \t " + e.getClass().getName() + "\r\n" + "\t Description : \t " + e.getMessage() @@ -448,67 +433,6 @@ public abstract class TdbCollector extends ArchiverCollector { return refreshing; } - private class KeepingThread extends Thread { - long keeping_time = m_modeHandler.getMode().getTdbSpec().getKeepingPeriod(); - long sleeping_time = 10 * 60 * 1000; // Deletes records every 10 minutes - String state = "NOT RUNNING"; - - public KeepingThread() { - super("KeepingThread"); - } - - public void activate(final boolean b) { - if (b) { - state = "RUNNING"; - } else { - state = "NOT RUNNING"; - } - } - - /** - * This method is called by the system to give a Thread a chance to - * clean up before it actually exits. - */ - @Override - public void destroy() { - System.out.println("KeepingThread.destroy"); - activate(false); - interrupt(); - } - - @Override - public void run() { - System.out.println("KeepingThread.run"); - state = "RUNNING"; - while (state.equals("RUNNING")) { - try { - sleep(sleeping_time); - } catch (final InterruptedException e) { - activate(false); - /* - * System.err.println( "Reason : Unknown !!!" + - * "\r\n" + - * "Description : The thread does not want to sleep !!" + - * "\r\n" + "Origin : KeepingThread.run"); - * e.printStackTrace(); - */ - } - Util.out4.println("KeepingThread.run : Getting attribute list..."); - final AttributePolledList tmpAttributeList = attributeList; - final String[] m_attributeList = new String[tmpAttributeList.size()]; - for (int i = 0; i < m_attributeList.length; i++) { - m_attributeList[i] = ((IEntity) tmpAttributeList.getElementAt(i)).getName(); - } - try { - Util.out4.println("KeepingThread.run : Sending the attribute list to the database..."); - dbProxy.deleteOldRecords(keeping_time, m_attributeList); - } catch (final ArchivingException e) { - Util.out2.println(e.toString()); - } - } - } - } - protected void setLastTimestamp(final ArchivingEvent scalarEvent) { if (scalarEvent != null) { final String name = scalarEvent.getAttribute_complete_name(); @@ -538,7 +462,7 @@ public abstract class TdbCollector extends ArchiverCollector { final long newTime = scalarEvent.getTimeStamp(); if (newTime == 0) { - m_logger.trace(ILogger.LEVEL_WARNING, "NOARCHIVING - received a zero timestamp for " + name + logger.trace(ILogger.LEVEL_WARNING, "NOARCHIVING - received a zero timestamp for " + name + " - tableName: " + scalarEvent.getTable_name()); return false; } @@ -549,24 +473,25 @@ public abstract class TdbCollector extends ArchiverCollector { return true; } - final boolean isAlreadyRegisteredDate = lastTimestampStack.containsDate(newTime, m_logger); + final boolean isAlreadyRegisteredDate = lastTimestampStack.containsDate(newTime, logger); // System.out.println ( // "isDataArchivableTimestampWise/isAlreadyRegisteredDate/"+isAlreadyRegisteredDate); if (isAlreadyRegisteredDate) { - m_logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - AlreadyRegisteredDate - attribute: " + name + logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - AlreadyRegisteredDate - attribute: " + name + " - timestamp: " + new Timestamp(newTime)); return false; } - final boolean isValidRegisteredDate = lastTimestampStack.validateDate(newTime, m_logger); + final boolean isValidRegisteredDate = lastTimestampStack.validateDate(newTime, logger); // System.out.println ( // "isDataArchivableTimestampWise/isAlreadyRegisteredDate/"+isAlreadyRegisteredDate); if (!isValidRegisteredDate) { - m_logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - not ValidRegisteredDate - attribute: " + name + logger.trace(ILogger.LEVEL_DEBUG, "NOARCHIVING - not ValidRegisteredDate - attribute: " + name + " - timestamp: " + new Timestamp(newTime)); return false; } - + // m_logger.trace(ILogger.LEVEL_DEBUG, name + " timestamp OK: " + new + // Timestamp(newTime)); // System.out.println ( "isDataArchivableTimestampWise/name/3"); return true; } diff --git a/src/main/java/TdbArchiver/Collector/scalar/BooleanScalar.java b/src/main/java/TdbArchiver/Collector/scalar/BooleanScalar.java index b49a7ca94ae6988d9224e4689507deaa9da22e5c..fc736b7e4b232f44ad7ecdba0d46e57d1a963bc9 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/BooleanScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/BooleanScalar.java @@ -165,7 +165,7 @@ public class BooleanScalar extends TdbCollector implements IBooleanScalarListene } else { final String message = "event is null or empty: " + event; System.err.println(message); - m_logger.trace(ILogger.LEVEL_ERROR, message); + logger.trace(ILogger.LEVEL_ERROR, message); } } @@ -177,14 +177,14 @@ public class BooleanScalar extends TdbCollector implements IBooleanScalarListene String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + "Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + "Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -223,14 +223,14 @@ public class BooleanScalar extends TdbCollector implements IBooleanScalarListene final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar( getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_BOOLEAN, getWritableValue().value()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java b/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java index e514bc00ca806905ce36fdbc30a22cdb8bc6324e..b1993a8785d1b40c382b53ff57423989324e4832 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java @@ -206,14 +206,14 @@ public class NumberScalar extends TdbCollector implements INumberScalarListener scalarEvent.avoidUnderFlow(); boolean doArchive = false; - if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -354,7 +354,7 @@ public class NumberScalar extends TdbCollector implements INumberScalarListener } else { final String message = "event is null or empty: " + event; System.err.println(message); - m_logger.trace(ILogger.LEVEL_ERROR, message); + logger.trace(ILogger.LEVEL_ERROR, message); } } @@ -365,14 +365,14 @@ public class NumberScalar extends TdbCollector implements INumberScalarListener final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar( getNullValueScalarEvent(errorEvent, ((AAttribute) errorEvent.getSource()).getTangoDataType(), getWritableValue().value()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java b/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java index 130ca90296df312c2be49cc3b7a6642015b0167c..faf55bee535fff2a13c59f4aef17c6bbb55927aa 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java @@ -55,14 +55,14 @@ public class StateScalar extends TdbCollector implements IDevStateScalarListener String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + "first value, forcing archiving"); + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -136,7 +136,7 @@ public class StateScalar extends TdbCollector implements IDevStateScalarListener } else { final String message = "event is null or empty: " + event; System.err.println(message); - m_logger.trace(ILogger.LEVEL_ERROR, message); + logger.trace(ILogger.LEVEL_ERROR, message); } } @@ -146,14 +146,14 @@ public class StateScalar extends TdbCollector implements IDevStateScalarListener final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar( getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_STATE, getWritableValue().value()), DEFAULT_TRY_NUMBER); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java b/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java index 473aa0ab6ba4741d4127432174950170b1fc0f34..d320b71cbb4f7d1002618cb955bd75edc7daff83 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java @@ -73,15 +73,15 @@ public class StringScalar extends TdbCollector implements IStringScalarListener String attributeName = scalarEvent.getAttribute_complete_name(); try { boolean doArchive = false; - if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + if (isFirstValueList.get(attributeName.toLowerCase())) { doArchive = true; - isFirstValue = false; + isFirstValueList.put(attributeName.toLowerCase(), false); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); } else { final ModesCounters mc = getModeCounter(attributeName); if (mc == null) { - m_logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); + logger.trace(ILogger.LEVEL_ERROR, attributeName + " Attribute Counters unknown"); } else { doArchive = doArchiveEvent(mc, scalarEvent.getData_type(), scalarEvent.getReadValue(), getLastValue(scalarEvent), attributeName); @@ -147,7 +147,7 @@ public class StringScalar extends TdbCollector implements IStringScalarListener } else { final String message = "event is null or empty: " + event; System.err.println(message); - m_logger.trace(ILogger.LEVEL_ERROR, message); + logger.trace(ILogger.LEVEL_ERROR, message); } } @@ -159,14 +159,14 @@ public class StringScalar extends TdbCollector implements IStringScalarListener final String errorMess = this.getClass().getSimpleName() + ".errorChange : Unable to read the attribute named " + errorEvent.getSource().toString(); Util.out3.println(errorMess); - super.m_logger.trace(ILogger.LEVEL_ERROR, errorMess); + super.logger.trace(ILogger.LEVEL_ERROR, errorMess); try { processEventScalar( getNullValueScalarEvent(errorEvent, TangoConst.Tango_DEV_STRING, getWritableValue().value()), tryNumber); } catch (final Exception e) { - super.m_logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + super.logger.trace(ILogger.LEVEL_ERROR, this.getClass().getSimpleName() + ".errorChange : during processEventScalar creation execp : " + e); e.printStackTrace(); } diff --git a/src/main/java/TdbArchiver/TdbArchiver.java b/src/main/java/TdbArchiver/TdbArchiver.java index 745373804b2d0b4b78539e69ad29b68092fcbbe4..657309d68edc435cfcc04c388a8d6a99ab561ce2 100644 --- a/src/main/java/TdbArchiver/TdbArchiver.java +++ b/src/main/java/TdbArchiver/TdbArchiver.java @@ -388,10 +388,11 @@ package TdbArchiver; import java.io.IOException; import java.sql.Timestamp; import java.util.Enumeration; -import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; -import java.util.Map; +import java.util.Set; import java.util.Vector; +import java.util.concurrent.Executors; import org.omg.CORBA.SystemException; import org.omg.CORBA.UserException; @@ -400,7 +401,6 @@ import TdbArchiver.Collector.DbProxy; import TdbArchiver.Collector.TdbCollector; import TdbArchiver.Collector.TdbCollectorFactory; import fr.esrf.Tango.DevFailed; -import fr.esrf.Tango.DevState; import fr.esrf.Tango.ErrSeverity; import fr.esrf.TangoApi.DbDatum; import fr.esrf.TangoDs.Attribute; @@ -569,7 +569,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { public static final short FAILED = 30; private ILogger logger; - private final Map<String, Boolean> archivingStatus = new HashMap<String, Boolean>(); + private final Set<String> koAttributes = new HashSet<String>(); + private final Set<String> okAttributes = new HashSet<String>(); private String dbSchema; // -------------------------------------- @@ -626,8 +627,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { attr_image_charge_read = 0; attr_spectrum_charge_read = 0; attr_scalar_charge_read = 0; - archivingStatus.clear(); - + koAttributes.clear(); + okAttributes.clear(); get_logger().info("dbHost = " + dbHost); get_logger().info("dbName = " + dbName); @@ -652,24 +653,7 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { TangoStateUtils.setFault(this, "database connection error"); get_logger().error("ERROR : Database unconnected !!"); } else { - try { - final Vector<AttributeLightMode> myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name); - if (myCurrentTasks != null && myCurrentTasks.size() > 0) { - final ArchivingMessConfig archivingMessConfig = ArchivingMessConfig.basicObjectCreation(); - for (int i = 0; i < myCurrentTasks.size(); i++) { - archivingMessConfig.add(myCurrentTasks.elementAt(i)); - } - - final boolean forceThreadedMode = false; - startArchiving(archivingMessConfig, forceThreadedMode, false); - } else { - TangoStateUtils.setOn(this, archivingStatus); - } - } catch (final DevFailed devFailed) { - final String message = DBTools.getCompleteMessage(devFailed); - get_logger().error(message); - TangoStateUtils.setFault(this, message); - } + Executors.newSingleThreadExecutor().submit(new InitDeviceTask()); } } @@ -708,6 +692,31 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { } } + private class InitDeviceTask implements Runnable { + @Override + public void run() { + Vector<AttributeLightMode> myCurrentTasks = null; + try { + myCurrentTasks = dbProxy.getArchiverCurrentTasks(device_name); + } catch (ArchivingException e) { + logger.trace(ILogger.LEVEL_ERROR, "cannot getArchiverCurrentTasks " + e); + TangoStateUtils.setFault(TdbArchiver.this, e.getMessage()); + } + try { + if (myCurrentTasks != null && myCurrentTasks.size() > 0) { + final ArchivingMessConfig archivingMessConfig = ArchivingMessConfig.basicObjectCreation(); + for (final AttributeLightMode attributeLightMode : myCurrentTasks) { + archivingMessConfig.add(attributeLightMode); + } + triggerArchiving(archivingMessConfig.toArray(), false); + } + } catch (final DevFailed devFailed) { + } finally { + TangoStateUtils.updateState(TdbArchiver.this, koAttributes, okAttributes); + } + } + } + private class StartArchivingRunnable implements Runnable { private final ArchivingMessConfig archivingMessConfig; private final boolean updateAMTTable; @@ -722,7 +731,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { try { triggerArchiving(archivingMessConfig.toArray(), updateAMTTable); } catch (final DevFailed devFailed) { - TangoStateUtils.setDisable(TdbArchiver.this, archivingStatus); + } finally { + TangoStateUtils.updateState(TdbArchiver.this, koAttributes, okAttributes); } } } @@ -950,6 +960,10 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { get_logger().info("In always_executed_hook method()"); } + public String[] getKOAttributes() { + return koAttributes.toArray(new String[koAttributes.size()]); + } + // =================================================================== /** * Method called by the read_attributes CORBA operation to set internal @@ -994,7 +1008,11 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { public void trigger_archive_conf(final String[] argin) throws DevFailed { TangoStateUtils.isAllowed(this); - triggerArchiving(argin, true); + try { + triggerArchiving(argin, true); + } finally { + TangoStateUtils.updateState(this, koAttributes, okAttributes); + } } private void triggerArchiving(final String[] argin, final boolean updateAMTTable) throws DevFailed { @@ -1049,7 +1067,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { } } - archivingStatus.put(attCompleteName, true); + okAttributes.add(attCompleteName); + koAttributes.remove(attCompleteName); logger.trace(ILogger.LEVEL_INFO, "OK: " + attCompleteName); } catch (final ArchivingException e) { try { @@ -1063,15 +1082,23 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { archivingException.addStack(message, reason, ErrSeverity.PANIC, desc, "", e); hasToThrow = true; logger.trace(ILogger.LEVEL_ERROR, reason + " " + desc); - archivingStatus.put(attCompleteName, false); + koAttributes.add(attCompleteName); + okAttributes.remove(attCompleteName); logger.trace(ILogger.LEVEL_INFO, "KO: " + attCompleteName); + } catch (Exception e) { + try { + collectorFactory.remove(attCompleteName); + } catch (final ArchivingException e1) { + } + e.printStackTrace(); + koAttributes.add(attCompleteName); + okAttributes.remove(attCompleteName); + logger.trace(ILogger.LEVEL_ERROR, "KO " + attCompleteName + " unexpected " + e); } } computeLoads(); - TangoStateUtils.setOn(this, archivingStatus); - if (hasToThrow) { logger.trace(ILogger.LEVEL_INFO, "trigger_archive_conf ERROR - out"); throw archivingException.toTangoException(); @@ -1179,7 +1206,6 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { // ========================================================= public void stop_archive_att(final String[] argin) throws DevFailed { TangoStateUtils.isAllowed(this); - boolean wasDisable = get_state().equals(DevState.DISABLE) ? true : false; TangoStateUtils.setRunning(this); get_logger().info("Entering stop_archive_att()"); @@ -1214,7 +1240,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { * desc , ""); */ } - archivingStatus.remove(attributeLightMode.getAttribute_complete_name()); + okAttributes.remove(attributeLightMode.getAttribute_complete_name()); + koAttributes.remove(attributeLightMode.getAttribute_complete_name()); } catch (final ArchivingException e) { logWarningAboutRiskySettingOfStateBackToOn("StopArchiveAtt", e); @@ -1223,11 +1250,8 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { throw e.toTangoException(); } finally { computeLoads(); - if (wasDisable) { - TangoStateUtils.setDisable(this, archivingStatus); - } else { - TangoStateUtils.setOn(this, archivingStatus); - } + TangoStateUtils.updateState(this, koAttributes, okAttributes); + } get_logger().info("Exiting stop_archive_att()"); @@ -1297,7 +1321,7 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { // ---Add your Own code to control device here --- final StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append(TangoStateUtils.statusToString(archivingStatus)); + stringBuffer.append(TangoStateUtils.statusToString(koAttributes, okAttributes)); stringBuffer.append(collectorFactory.factoryAssessment()); argout = stringBuffer.toString(); get_logger().info("Exiting state_detailed()"); @@ -1313,21 +1337,17 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { try { final Util tg = Util.init(argv, "TdbArchiver"); tg.server_init(); - System.out.println("Ready to accept request"); - tg.server_run(); } catch (final OutOfMemoryError ex) { System.err.println("Can't allocate memory !!!!"); System.err.println("Exiting"); } catch (final UserException ex) { Except.print_exception(ex); - System.err.println("Received a CORBA user exception"); System.err.println("Exiting"); } catch (final SystemException ex) { Except.print_exception(ex); - System.err.println("Received a CORBA system exception"); System.err.println("Exiting"); } diff --git a/src/main/java/TdbArchiver/TdbArchiverClass.java b/src/main/java/TdbArchiver/TdbArchiverClass.java index 2387cab6e9ba47999a25405632e3fd27aa88c839..cc23b717af7c01ca36352e4cd180607e8b9487eb 100644 --- a/src/main/java/TdbArchiver/TdbArchiverClass.java +++ b/src/main/java/TdbArchiver/TdbArchiverClass.java @@ -69,6 +69,7 @@ import fr.esrf.TangoDs.Attr; import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.DeviceImpl; import fr.esrf.TangoDs.TangoConst; +import fr.esrf.TangoDs.TemplCommandOut; import fr.esrf.TangoDs.Util; public class TdbArchiverClass extends DeviceClass implements TangoConst { @@ -185,26 +186,21 @@ public class TdbArchiverClass extends DeviceClass implements TangoConst { "A return code, can be either: 10 (the archiver isn't in charge of the specified attribute) 20 (the retry succeeded) or 30 (the retry failed)", DispLevel.OPERATOR)); - command_list.addElement(new TriggerArchiveConfCmd("TriggerArchiveConf", - Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "The group of attributes to archive", "", - DispLevel.OPERATOR)); - command_list.addElement(new TriggerArchiveAttCmd("TriggerArchiveAtt", - Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, "The attribute to archive", "", - DispLevel.OPERATOR)); - command_list.addElement(new TriggerArchiveAttCheckCmd("TriggerArchiveAttCheck", - Tango_DEV_STRING, Tango_DEV_VOID, "The name of the attribute to archive", "", - DispLevel.OPERATOR)); - command_list.addElement(new StopArchiveConfCmd("StopArchiveConf", Tango_DEVVAR_STRINGARRAY, - Tango_DEV_VOID, "The group of attributes", "", DispLevel.OPERATOR)); - command_list.addElement(new StopArchiveAttCmd("StopArchiveAtt", Tango_DEVVAR_STRINGARRAY, - Tango_DEV_VOID, "the attribute on witch archiving must be stopped", "", - DispLevel.OPERATOR)); - command_list.addElement(new ExportData2DbCmd("ExportData2Db", Tango_DEVVAR_STRINGARRAY, - Tango_DEV_VOID, "the attribute from witch data are expected.", "", - DispLevel.OPERATOR)); - command_list.addElement(new StateDetailedClass("StateDetailed", Tango_DEV_VOID, - Tango_DEV_STRING, "", "The detailed state", DispLevel.EXPERT)); - + command_list.addElement(new TriggerArchiveConfCmd("TriggerArchiveConf", Tango_DEVVAR_STRINGARRAY, + Tango_DEV_VOID, "The group of attributes to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new TriggerArchiveAttCmd("TriggerArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "The attribute to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new TriggerArchiveAttCheckCmd("TriggerArchiveAttCheck", Tango_DEV_STRING, + Tango_DEV_VOID, "The name of the attribute to archive", "", DispLevel.OPERATOR)); + command_list.addElement(new StopArchiveConfCmd("StopArchiveConf", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "The group of attributes", "", DispLevel.OPERATOR)); + command_list.addElement(new StopArchiveAttCmd("StopArchiveAtt", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "the attribute on witch archiving must be stopped", "", DispLevel.OPERATOR)); + command_list.addElement(new ExportData2DbCmd("ExportData2Db", Tango_DEVVAR_STRINGARRAY, Tango_DEV_VOID, + "the attribute from witch data are expected.", "", DispLevel.OPERATOR)); + command_list.addElement(new StateDetailedClass("StateDetailed", Tango_DEV_VOID, Tango_DEV_STRING, "", + "The detailed state", DispLevel.EXPERT)); + command_list.addElement(new TemplCommandOut("GetKOAttributes", "getKOAttributes")); // add polling if any /* * for (int i = 0; i < command_list.size(); i++) { Command cmd = @@ -224,8 +220,7 @@ public class TdbArchiverClass extends DeviceClass implements TangoConst { // =================================================================== @Override public void device_factory(final String[] devlist) throws DevFailed { - final String device_version = ResourceBundle.getBundle("application").getString( - "project.version"); + final String device_version = ResourceBundle.getBundle("application").getString("project.version"); for (int i = 0; i < devlist.length; i++) { // Util.out4.println("Device name : " + devlist[ i ]); @@ -255,8 +250,7 @@ public class TdbArchiverClass extends DeviceClass implements TangoConst { att_list.addElement(scalar_charge); // Attribute : spectrum_charge - final Attr spectrum_charge = new Attr("spectrum_charge", Tango_DEV_SHORT, - AttrWriteType.READ); + final Attr spectrum_charge = new Attr("spectrum_charge", Tango_DEV_SHORT, AttrWriteType.READ); att_list.addElement(spectrum_charge); // Attribute : image_charge @@ -351,8 +345,7 @@ public class TdbArchiverClass extends DeviceClass implements TangoConst { data[0].insert("Tango Device Server"); data[1] = new DbDatum("Description"); - data[1] - .insert("Tis project defines the Tango DServer in charge of the intermediate archiving service."); + data[1].insert("Tis project defines the Tango DServer in charge of the intermediate archiving service."); // Call database and and values // -------------------------------------------- diff --git a/src/main/java/TdbArchivingWatcher/TdbArchivingWatcher.java b/src/main/java/TdbArchivingWatcher/TdbArchivingWatcher.java index d45c2fa636249a32468425477eb7efba8880862d..82531ee5dc2094608f15a2b91f5d97608010efbe 100644 --- a/src/main/java/TdbArchivingWatcher/TdbArchivingWatcher.java +++ b/src/main/java/TdbArchivingWatcher/TdbArchivingWatcher.java @@ -1,5 +1,7 @@ package TdbArchivingWatcher; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Hashtable; import java.util.Iterator; @@ -15,7 +17,13 @@ import fr.esrf.Tango.DevError; import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevState; import fr.esrf.Tango.ErrSeverity; +import fr.esrf.TangoApi.ApiUtil; import fr.esrf.TangoApi.DbDatum; +import fr.esrf.TangoApi.DeviceData; +import fr.esrf.TangoApi.DeviceProxy; +import fr.esrf.TangoApi.Group.Group; +import fr.esrf.TangoApi.Group.GroupCmdReply; +import fr.esrf.TangoApi.Group.GroupCmdReplyList; import fr.esrf.TangoDs.Attribute; import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.Except; @@ -23,6 +31,7 @@ import fr.esrf.TangoDs.Util; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.ILogger; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.LoggerFactory; import fr.soleil.hdbtdbArchivingApi.ArchivingApi.ConfigConst; +import fr.soleil.hdbtdbArchivingApi.ArchivingManagerApi.TdbArchivingManagerApiRef; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Mode.Mode; import fr.soleil.hdbtdbArchivingApi.ArchivingTools.Tools.ArchivingException; import fr.soleil.hdbtdbArchivingApi.ArchivingWatchApi.ArchivingWatch; @@ -168,20 +177,46 @@ public class TdbArchivingWatcher extends AbsArchivingWatcher { startLoggingFactory(); - // this.linesComparator = new ControlResultLineComparator (); archiversComparator = new ArchiversComparator(); domainsComparator = new DomainsComparator(); - // this.archivingAttributeSubNamesComparator = new - // ArchivingAttributeSubNamesComparator (); archivingAttributeComparator = new ArchivingAttributeComparator(); watcherThread.start(); - if (!ArchivingWatch.isDoStartOnInitDevice())// this.doStartOnInitDevice - // ) - { + if (!ArchivingWatch.isDoStartOnInitDevice()) { warnOff(); } + + } + + /** + * ask all archivers for their KO attributes + * + * @return + * @throws DevFailed + */ + public String[] getKOAttributesFromArchivers(boolean doRetry) throws DevFailed { + + List<String> archiversStatus = new ArrayList<String>(); + String[] archiverNames = ApiUtil.get_db_obj().get_device_exported_for_class( + TdbArchivingManagerApiRef.classDevice); + Group group = new Group("archivers"); + group.add(archiverNames); + GroupCmdReplyList replies = group.command_inout("GetKOAttributes", true); + for (Object reply : replies) { + GroupCmdReply r = (GroupCmdReply) reply; + try { + DeviceData result = r.get_data(); + String archiverStatus = r.dev_name() + " " + Arrays.toString(result.extractStringArray()); + archiversStatus.add(archiverStatus); + if (doRetry) { + new DeviceProxy(r.dev_name()).command_inout_asynch("RetryForAttribute", result, true); + } + } catch (DevFailed e) { + archiversStatus.add(r.dev_name() + " ERROR"); + } + } + return archiversStatus.toArray(new String[archiversStatus.size()]); } // ========================================================= diff --git a/src/main/java/TdbArchivingWatcher/TdbArchivingWatcherClass.java b/src/main/java/TdbArchivingWatcher/TdbArchivingWatcherClass.java index 4db2386365be324e724f6a64ff0fd07c525459c4..b97c3f1bfa9a28e2e4afa4288a53287531fa5124 100644 --- a/src/main/java/TdbArchivingWatcher/TdbArchivingWatcherClass.java +++ b/src/main/java/TdbArchivingWatcher/TdbArchivingWatcherClass.java @@ -92,6 +92,7 @@ import fr.esrf.TangoDs.DeviceClass; import fr.esrf.TangoDs.DeviceImpl; import fr.esrf.TangoDs.SpectrumAttr; import fr.esrf.TangoDs.TangoConst; +import fr.esrf.TangoDs.TemplCommandInOut; import fr.esrf.TangoDs.UserDefaultAttrProp; import fr.esrf.TangoDs.Util; @@ -263,6 +264,8 @@ public class TdbArchivingWatcherClass extends DeviceClass implements TangoConst command_list.addElement(new GetFeedAliveProgressionClass("GetFeedAliveProgression", Tango_DEV_VOID, Tango_DEV_LONG, "", "Percentage of the feedalive execution ", DispLevel.OPERATOR)); + command_list.addElement(new TemplCommandInOut("GetKOAttributesFromArchivers", "getKOAttributesFromArchivers", + "do a retry", "the list of ko per archiver")); // add polling if any /* diff --git a/src/main/java/TdbExtractor/TdbExtractor.java b/src/main/java/TdbExtractor/TdbExtractor.java index 9086f5effa74b35ef89fa725e29f63aacf87326d..cd02f1ab5cfe07426239b79b5ec4c6447d49b97c 100644 --- a/src/main/java/TdbExtractor/TdbExtractor.java +++ b/src/main/java/TdbExtractor/TdbExtractor.java @@ -2439,13 +2439,19 @@ public class TdbExtractor extends DeviceImpl } // And fill buffer with database's data - - if (_2value) { - final DbData[] dbDatas = dbData.splitDbData(); - tg_1.fill_attr_polling_buffer(this, random_name_1, dbDatas[0].getDataAsTimedAttrData()); - tg_2.fill_attr_polling_buffer(this, random_name_2, dbDatas[1].getDataAsTimedAttrData()); - } else { - tg_1.fill_attr_polling_buffer(this, random_name_1, dbData.getDataAsTimedAttrData()); + try { + if (_2value) { + final DbData[] dbDatas = dbData.splitDbData(); + tg_1.fill_attr_polling_buffer(this, random_name_1, dbDatas[0].getDataAsTimedAttrData()); + tg_2.fill_attr_polling_buffer(this, random_name_2, dbDatas[1].getDataAsTimedAttrData()); + } else { + tg_1.fill_attr_polling_buffer(this, random_name_1, dbData.getDataAsTimedAttrData()); + } + } catch (Exception e) { + // FIXME java.lang.ArrayIndexOutOfBoundsException thrown when some + // data are empty. + e.printStackTrace(); + System.out.println("ERROR when filling data polling buffer, may be empty"); } final DevVarLongStringArray argout = new DevVarLongStringArray(); diff --git a/src/main/java/fr/soleil/archiving/utils/TangoStateUtils.java b/src/main/java/fr/soleil/archiving/utils/TangoStateUtils.java index de9f717ec8ef6a81d9562d2d9b15b57d2e12a3b7..a233af21412fec880305a8918de6310ee43467ed 100644 --- a/src/main/java/fr/soleil/archiving/utils/TangoStateUtils.java +++ b/src/main/java/fr/soleil/archiving/utils/TangoStateUtils.java @@ -1,7 +1,6 @@ package fr.soleil.archiving.utils; -import java.util.Map; -import java.util.Map.Entry; +import java.util.Set; import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevState; @@ -16,37 +15,42 @@ public class TangoStateUtils { device.set_status(msg); } - public static void setDisable(final DeviceImpl device, - final Map<String, Boolean> archivingStatus) { - device.set_state(DevState.DISABLE); - device.set_status(statusToString(archivingStatus)); - } - public static void setRunning(final DeviceImpl device) { device.set_state(DevState.RUNNING); device.set_status("Starting archiving"); } - public static void setOn(final DeviceImpl device, final Map<String, Boolean> archivingStatus) { - device.set_state(DevState.ON); - device.set_status(statusToString(archivingStatus)); + public static void updateState(final DeviceImpl device, Set<String> koAttributes, Set<String> okAttributes) { + + if (koAttributes.isEmpty() && okAttributes.isEmpty()) { + device.set_state(DevState.OFF); + device.set_status("No attributes to archive"); + } else if (!koAttributes.isEmpty()) { + device.set_state(DevState.DISABLE); + device.set_status(statusToString(koAttributes, okAttributes)); + } else { + device.set_state(DevState.ON); + device.set_status(statusToString(koAttributes, okAttributes)); + } } public static void isAllowed(final DeviceImpl device) throws DevFailed { - if (device.get_state().equals(DevState.FAULT) - || device.get_state().equals(DevState.RUNNING)) { - Except.throw_exception("NOT_ALLOWED", "action is not allowed while device is in " + if (device.get_state().equals(DevState.FAULT) || device.get_state().equals(DevState.RUNNING)) { + Except.throw_exception("NOT_ALLOWED", "action is not allowed while device is " + TangoConst.Tango_DevStateName[device.get_state().value()], "isAllowed"); } } - public static String statusToString(final Map<String, Boolean> archivingStatus) { - final StringBuilder b = new StringBuilder(); - for (final Entry<String, Boolean> entry : archivingStatus.entrySet()) { - b.append(entry.getKey()); - b.append(":"); - b.append(entry.getValue() ? "OK\n" : "KO\n"); + public static String statusToString(Set<String> koAttributes, Set<String> okAttributes) { + final StringBuilder sb = new StringBuilder("- KO ["); + for (String koS : koAttributes) { + sb.append("\n").append(koS); + } + sb.append("]\n- OK ["); + for (String okS : okAttributes) { + sb.append("\n").append(okS); } - return b.toString(); + sb.append("]"); + return sb.toString(); } } diff --git a/src/test/resources/log4j.xml b/src/test/resources/log4j.xml deleted file mode 100644 index 89b5ee06f20b4ddccc50bd5fe1182d96a67c88a8..0000000000000000000000000000000000000000 --- a/src/test/resources/log4j.xml +++ /dev/null @@ -1,105 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> - -<!-- An example log4j configuration xml file for log4jdbc --> -<!-- Logging levels are: --> -<!-- DEBUG < INFO < WARN < ERROR < FATAL --> - -<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> - - <appender name="stdout-appender" class="org.apache.log4j.ConsoleAppender"> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %5p %c{1}: %m%n"/> - </layout> - </appender> - - <appender name="sql-appender" class="org.apache.log4j.FileAppender"> - <param name="File" value="./logs/sql.log"/> - <param name="Append" value="false"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="-----> %d{yyyy-MM-dd HH:mm:ss.SSS} <%t> %m%n%n"/> - </layout> - </appender> - - <appender name="sql-timing-appender" class="org.apache.log4j.FileAppender"> - <param name="File" value="./logs/sqltiming.log"/> - <param name="Append" value="false"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n"/> - </layout> - </appender> - - <appender name="jdbc-appender" class="org.apache.log4j.FileAppender"> - <param name="File" value="./logs/jdbc.log"/> - <param name="Append" value="false"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n"/> - </layout> - </appender> - - <appender name="jdbc-connection" class="org.apache.log4j.FileAppender"> - <param name="File" value="./logs/connection.log"/> - <param name="Append" value="false"/> - <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n"/> - </layout> - </appender> - - <!-- - The Following 5 logs can be turned on and off while the server is running - LIVE in order to trace the SQL and/or all JDBC coming out of the application. - - To turn a log on, set the level value to INFO or DEBUG (to see class name and - line number information in the log) The DEBUG setting is much more inefficient - but the output is much more useful. - - To turn off JDBC logging completely, you must set all 5 logs to a level higher - than ERROR (FATAL is suggested.) - --> - - <!-- log SQL (pre-execution) plus exceptions caused by SQL --> - <logger name="jdbc.sqlonly" additivity="false"> - <level value="debug"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- log SQL with timing information, post execution --> - <logger name="jdbc.sqltiming" additivity="false"> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- only use the two logs below to trace ALL JDBC information, - NOTE: This can be very voluminous! --> - - <!-- log all jdbc calls except ResultSet calls --> - <logger name="jdbc.audit" additivity="false"> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- log the jdbc ResultSet calls --> - <logger name="jdbc.resultset" additivity="false"> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- log connection open/close events and dump of all open connection numbers --> - <logger name="jdbc.connection" additivity="false"> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- this log is for internal debugging of log4jdbc, itself --> - <!-- debug logging for log4jdbc itself --> - <logger name="log4jdbc.debug" additivity="false"> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </logger> - - <!-- by default, log everything to the console with a level of WARN or higher --> - <root> - <level value="error"/> - <appender-ref ref="stdout-appender"/> - </root> -</log4j:configuration> \ No newline at end of file