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..2ba156e78a00d8e388d08957cdedd79cf4f8a71b 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.17</version> <scm> <connection>${scm.connection.svn.tango-cs}:archiving/server/hdbtdbArchivingServers</connection> 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/HdbCollector.java b/src/main/java/HdbArchiver/Collector/HdbCollector.java index 2cb43def930bc7738c3da6e10cf31ad256bec55c..816dd7591ec12c17d598205d7bab37d5b61034f8 100644 --- a/src/main/java/HdbArchiver/Collector/HdbCollector.java +++ b/src/main/java/HdbArchiver/Collector/HdbCollector.java @@ -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..02b49626e2ccdc1d436294313cd3748aede4a8e9 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,6 +143,7 @@ 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); @@ -154,9 +155,6 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal 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(); } } @@ -364,11 +363,11 @@ public abstract class BooleanScalar extends HdbCollector implements IBooleanScal if (isFirstValue) { doArchive = true; isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + 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..d7fedf368ff3d93df2f65bceac05304b9a3a763e 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,17 @@ 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..."); + 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 +208,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 +219,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 +228,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 +242,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(); } } @@ -422,11 +417,11 @@ public abstract class NumberScalar extends HdbCollector implements INumberScalar if (isFirstValue) { doArchive = true; isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + 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 +436,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 +468,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 +476,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..050e397b0a8a2665627957110b1e669b1bb19be5 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StateScalar.java @@ -80,6 +80,7 @@ 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); @@ -90,9 +91,6 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala // 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 +99,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 +114,7 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala // == // null ) // { + stopCollecting(); IDevStateScalar attribute = null; attribute = (IDevStateScalar) attributeList.add(attName); @@ -123,11 +124,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 +140,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(); } } @@ -303,12 +302,12 @@ public abstract class StateScalar extends HdbCollector implements IDevStateScala if (isFirstValue) { doArchive = true; isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + 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 +321,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 +357,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..1dd6910dfd38ef2602b7945fd60a324d4d3db071 100644 --- a/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java +++ b/src/main/java/HdbArchiver/Collector/scalar/StringScalar.java @@ -82,6 +82,7 @@ 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); @@ -92,9 +93,6 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar // 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 +101,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 +113,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 +123,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 +138,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(); } } @@ -307,12 +306,12 @@ public abstract class StringScalar extends HdbCollector implements IStringScalar if (isFirstValue) { doArchive = true; isFirstValue = false; - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + 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 +325,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 +356,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..e7d72187a7f8e85303d5a217fd8efec0a654df46 100644 --- a/src/main/java/HdbArchiver/HdbArchiver.java +++ b/src/main/java/HdbArchiver/HdbArchiver.java @@ -365,6 +365,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Vector; +import java.util.concurrent.Executors; import org.omg.CORBA.SystemException; import org.omg.CORBA.UserException; @@ -640,26 +641,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 +666,29 @@ public class HdbArchiver extends DeviceImpl implements TangoConst { } } + private class InitDeviceTask implements Runnable { + @Override + public void run() { + 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); + } + triggerArchiving(archivingMessConfig.toArray(), false); + } else { + TangoStateUtils.setOn(HdbArchiver.this, archivingStatus); + } + } catch (final DevFailed devFailed) { + // triggerArchiving has thrown + TangoStateUtils.setDisable(HdbArchiver.this, archivingStatus); + } catch (ArchivingException e) { + TangoStateUtils.setFault(HdbArchiver.this, e.getMessage()); + } + } + } + private class StartArchivingRunnable implements Runnable { private final ArchivingMessConfig archivingMessConfig; @@ -1003,7 +1009,6 @@ 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); } diff --git a/src/main/java/TdbArchiver/Collector/DbProxy.java b/src/main/java/TdbArchiver/Collector/DbProxy.java index 6a48b6b67b0920aa4f1b818cfec85df34606cb8b..9af4c7a217ec5ef7cb317f918df79c14b982fca6 100644 --- a/src/main/java/TdbArchiver/Collector/DbProxy.java +++ b/src/main/java/TdbArchiver/Collector/DbProxy.java @@ -69,6 +69,7 @@ package TdbArchiver.Collector; import java.util.Vector; +import fr.esrf.Tango.DevFailed; import fr.esrf.TangoApi.Database; import fr.esrf.TangoDs.Util; import fr.soleil.commonarchivingapi.ArchivingTools.Diary.ILogger; @@ -166,44 +167,21 @@ public class DbProxy { tableName, writable); } - public Vector<AttributeLightMode> getArchiverCurrentTasks(final String archiverName) // throws - // ArchivingException - // , DevFailed - { + public Vector<AttributeLightMode> getArchiverCurrentTasks(final String archiverName) throws DevFailed, + ArchivingException { // System.out.println("DbProxy.getArchiverCurrentTasks"); Vector<AttributeLightMode> archiverCurrentTasks; final boolean facility = manager.getFacility(); - try { - archiverCurrentTasks = manager - .getDataBase() - .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 ( 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; + archiverCurrentTasks = manager.getDataBase().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; + } 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..35433b0937d683dfeeee9d7b5f52689ccd3e4ae0 100644 --- a/src/main/java/TdbArchiver/Collector/TdbCollector.java +++ b/src/main/java/TdbArchiver/Collector/TdbCollector.java @@ -194,10 +194,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; @@ -261,6 +259,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); @@ -274,20 +273,14 @@ public abstract class TdbCollector extends ArchiverCollector { if (filesNames.get(attName) == 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); } isFirstValue = true; - startCollecting(); - - if (attributeList.get(attName) == null) { - super.m_logger.trace(ILogger.LEVEL_WARNING, "addSource/The first add test failed for attribute|" - + attName); - } } 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 +288,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,6 +313,7 @@ public abstract class TdbCollector extends ArchiverCollector { * while ( ( IBooleanScalar ) attributeList.get(attributeName) != * null ) { */ + stopCollecting(); final IEntity attribute = attributeList.get(attributeName); if (attribute != null) { removeListeners(attribute); @@ -333,10 +329,6 @@ public abstract class TdbCollector extends ArchiverCollector { filesNames.get(attributeName).closeFile(); filesNames.remove(attributeName); } - if (attributeList.isEmpty()) { - stopCollecting(); - } - } } catch (final Exception e) { final String message = GlobalConst.ARCHIVING_ERROR_PREFIX + " : " + "Failed removing '" + attributeName @@ -344,15 +336,17 @@ 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); + 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, "Export forced done for " + attributeName + " - " + result); return result; } @@ -379,21 +373,18 @@ public abstract class TdbCollector extends ArchiverCollector { /** * 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 +393,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,66 +434,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) { @@ -538,7 +464,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 +475,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..2619406abfe84794a9cf0d769c46a6047b24f62d 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); } } @@ -178,13 +178,13 @@ public class BooleanScalar extends TdbCollector implements IBooleanScalarListene try { boolean doArchive = false; if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); doArchive = true; isFirstValue = false; } 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..ab35957c17f39c778b3094a9d63fda94747337b5 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/NumberScalar.java @@ -207,13 +207,13 @@ public class NumberScalar extends TdbCollector implements INumberScalarListener boolean doArchive = false; if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); doArchive = true; isFirstValue = false; } 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..57832a3d0ce45fbf64579cff199ca51fecf550fb 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/StateScalar.java @@ -56,13 +56,13 @@ public class StateScalar extends TdbCollector implements IDevStateScalarListener try { boolean doArchive = false; if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + "first value, forcing archiving"); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + "first value, forcing archiving"); doArchive = true; isFirstValue = false; } 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..59ab3c08d8129180c131866f59a9c67ff10cfcc6 100644 --- a/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java +++ b/src/main/java/TdbArchiver/Collector/scalar/StringScalar.java @@ -74,14 +74,14 @@ public class StringScalar extends TdbCollector implements IStringScalarListener try { boolean doArchive = false; if (isFirstValue) { - m_logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); + logger.trace(ILogger.LEVEL_DEBUG, attributeName + " first value, forcing archiving"); doArchive = true; isFirstValue = false; } 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..83788a076598b1a1025a2e393f068258477ec99f 100644 --- a/src/main/java/TdbArchiver/TdbArchiver.java +++ b/src/main/java/TdbArchiver/TdbArchiver.java @@ -392,6 +392,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Map; import java.util.Vector; +import java.util.concurrent.Executors; import org.omg.CORBA.SystemException; import org.omg.CORBA.UserException; @@ -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,29 @@ public class TdbArchiver extends DeviceImpl implements TangoConst { } } + private class InitDeviceTask implements Runnable { + @Override + public void run() { + 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); + } + triggerArchiving(archivingMessConfig.toArray(), false); + } else { + TangoStateUtils.setOn(TdbArchiver.this, archivingStatus); + } + } catch (final DevFailed devFailed) { + // triggerArchiving has thrown + TangoStateUtils.setDisable(TdbArchiver.this, archivingStatus); + } catch (ArchivingException e) { + TangoStateUtils.setFault(TdbArchiver.this, e.getMessage()); + } + } + } + private class StartArchivingRunnable implements Runnable { private final ArchivingMessConfig archivingMessConfig; private final boolean updateAMTTable; 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