Package de.desy.tine.server.alarms

Examples of de.desy.tine.server.alarms.TAlarm


      return (TAlarm[])devAlarmList.toArray(new TAlarm[0]);
    }
  }
  private TAlarm getAlarmFromList(int code,byte[] data,short flags,TAlarmWatchEntry awe)
  { // called only by setAlarm() ...
    TAlarm alm = null;
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    boolean keepTimestamp = false;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      if (code == 0) DbgLog.log("getAlarmFromList","searching for alarm code == 0?");
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // this shouldn't happen !
          // (if a caller uses a 'set' method on the alarm, it's almost gotta be right after this gets called)
          nerr++;
          MsgLog.log("getAlarmFromList", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return null;
          continue;
        }
        keepTimestamp = false;
        TAlarmDefinition ads = alm.getAlmDef();
        if (alm.isTerminated())
        { // is marked for termination
          boolean oscPinned = TAlarm.getAlmOscillationWindowPinned();
          int oscw = TAlarm.getAlmOscillationWindow();
          if (ads != null)
          {
            if (!oscPinned) oscPinned = ads.isOscillationWindowPinned();
            oscw = ads.getAlarmOscillationWindow();
          }
          if (!alm.isTransient() && !oscPinned)
          { // oscillation window too small ?
            int dt = (alm.getTimeStamp()+TAlarm.getTerminationWindow()) - (int)(System.currentTimeMillis()/1000);
            if (dt > 0 && dt < TAlarm.ALM_OSCILLATION_MAXIMUM-oscw)
            { // adjust the oscillation window
              oscw += dt;
              if (ads != null) ads.setAlarmOscillationWindow(oscw);
              else TAlarm.setAlmOscillationWindow(oscw,false);
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList","increase alarm oscillation windows to "+oscw+" clear counts");
            }
          }
          continue;
        }
        else
        { // not marked for termination
          if (alm.getCode() == code && alm.getWatchEntry() == awe)
          { // it's already in the list so remove NEW bit !
            byte dsc = alm.getDescriptor();
            byte[] adata = alm.getData();
            int dlen = ads == null ? 0 : ads.getAlarmDataArraySize();
            if (dlen > 0 && data != null && adata != null)
            { // check for alarm data changed
              for (int n=0; n<dlen && n<adata.length && n<data.length; n++)
              {
                if (data[n] != adata[n])
                { // remove NEW and add DATACHANGE
                  dsc &= ~(byte)(TAlarmDescriptor.NEW);
                  if (alm.isDataChange())
                  { // already marked as data change (when was the last time ?)
                    if (thisTimeStamp - alm.getTimeStamp() < TAlarm.getAlmDataChangeWindow())
                    {
                      keepTimestamp = true;
                    }
                  }
                  if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
                  dsc |= (byte)TAlarmDescriptor.DATACHANGE;
                  if (TEquipmentModuleFactory.getDebugLevel() > 0)
                    DbgLog.log("getAlarmFromList",alm.getTag() + " : alarm data changed");
                  break;
                }
              }
            }
            if (alm.getClearCount() > 1)
            { // check for oscillating alarm ...
              dsc &= ~(byte)(TAlarmDescriptor.NEW);
              if (alm.isOscillating()) keepTimestamp = true;
              if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
              dsc |= (byte)TAlarmDescriptor.OSCILLATION;
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList",alm.getTag() + " : mark alarm as oscillating");
            }
            alm.resetClearCount();
            alm.setDescriptor(dsc);
            return alm;
          }
        }
      }
      // not found, so this is a new one ...
      // TODO: worry about 'max_alarms_exceeded', i.e. alarm storms and the length of this list!
      if (devAlarmList.size() > maximumAllowedNumberOfAlarms)
      {
        devAlarmList.removeFirst();
        MsgLog.log("TDevice.getAlarmFromList", "alarm buffer full",TErrorList.max_alarms_exceeded,null,1);
      }
      flags |= TAlarmDescriptor.NEW;
      if ((flags & TAlarmDescriptor.TRANSIENT) != 0) flags |= TAlarmDescriptor.TERMINATE;
      alm = new TAlarm(code,(byte)flags,data,this);
      alm.setWatchEntry(awe);
      if (eqm.casReadRequired) alm.blockRemoval();
      devAlarmList.add(alm);
    }
    if (TEquipmentModuleFactory.getDebugLevel() > 0)
      DbgLog.log("getAlarmFromList",devName + " : " + alm.getTag() + "(" + code + ") : add alarm to list");
    return alm;
  }
View Full Code Here


  }
  public void processAlarms()
  {
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      nDevAlarmsAtHsv = 0; devAlarmHsv = 0;
      nDevAlarmsAtMrt = 0; devAlarmMrt = 0;
      nDevAlarmsAtMrct = 0;
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // someone could be using e.g. the setData() method on the alarm itself
          // (not a good way to do it, but it's supported)
          nerr++;
          MsgLog.log("processAlarms", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return;
          continue;
        }
        if (alm.isTerminated() && 
            thisTimeStamp > alm.getTimeStamp() + TAlarm.getTerminationWindow())
        {
          if (alm.getSeverity() > 0 && alm.isRemovalBlocked())
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 2) DbgLog.log("processAlarms",alm.getTag() + " : missing CAS read -> removal blocked");
          }
          else
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 1) DbgLog.log("processAlarms",alm.getTag() + " : remove alarm");
            li.remove();
            continue;
          }
        }
        // apply termination flag if necessary ...
        if (!alm.isTerminated() && thisTimeStamp > alm.getTimeStamp())
        {
          int oscw = TAlarm.getAlmOscillationWindow();
          TAlarmDefinition ads = alm.getAlmDef();
          if (ads != null) oscw = ads.getAlarmOscillationWindow();
          if (alm.getClearCount() > (oscw-TAlarm.ALM_OSCILLATION_CUSHION))
          {
            byte dsc = alm.getDescriptor();
            dsc &= ~(byte)TAlarmDescriptor.NEW;
            dsc |= (byte)TAlarmDescriptor.TERMINATE;
            alm.setDescriptor(dsc);
            alm.setTimeStamp(thisTimeStamp);
            //refreshMrt(thisTimeStamp);
            alm.setTerminated(true);
            DbgLog.log("processAlarms",alm.getTag() + " : mark alarm as terminated");
          }
        }
        // apply heartbeat if necessary
        if (thisTimeStamp > alm.getTimeStamp() + TAlarm.getAlmHeartbeatWindow())
        {
          byte dsc = alm.getDescriptor();
          dsc &= ~(byte)TAlarmDescriptor.NEW;
          dsc |= (byte)TAlarmDescriptor.HEARTBEAT;
          alm.setDescriptor(dsc);
          alm.setTimeStamp(thisTimeStamp);
          //refreshMrt(thisTimeStamp);
        }
        refreshMrt(alm.getTimeStamp());
        refreshHsv((short)alm.getSeverity());
      }
      // adjust most recent completed timestamp (if necessary)
      int mrct = 0;
      if (thisTimeStamp > devAlarmMrt && devAlarmMrt > mrct)
      {
View Full Code Here

  {
    return setAlarm(code,data,TAlarmDescriptor.NEW);
  }
  public TAlarm setAlarm(int code,byte[] data,TAlarmWatchEntry awe)
  {
    TAlarm alm = getAlarmFromList(code,data,TAlarmDescriptor.NEW,awe);
    if (alm.isTerminated()) DbgLog.log("setAlarm",alm.getTag() + " : set alarm as terminated");
    return alm;
  }
View Full Code Here

    if (offline)
    {
      if (TLinkFactory.debugLevel > 0) DbgLog.log("setAlarm","alarm not set: "+devName+" is off line");
      return null;
    }
    TAlarm alm = getAlarmFromList(code,data,flags,null);
    if (alm.isTerminated()) DbgLog.log("setAlarm",alm.getTag() + " : set alarm as terminated");
    return alm;
  }
View Full Code Here

   *
   * @param code Is the alarm code specifying which alarm to clear
   */
  public void clearAlarm(int code)
  {
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      int lstalm = 0;
      Iterator<TAlarm> li = devAlarmList.iterator();
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        lstalm = alm.getCode();
        if (code == TErrorList.warn_disk_space || code == TErrorList.low_disk_space)
        { // mask off the high bits
          lstalm &= 0xff;
        }
        if (lstalm != code) continue;
        alm.clear();
      }
    }
  }
View Full Code Here

      }
    }
  }
  public void clearAlarm(int code,TAlarmWatchEntry awe)
  {
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        if (alm.getCode() != code && alm.getWatchEntry() != awe) continue;
        alm.clear();
      }
    }
  }
View Full Code Here

  {
    synchronized (devAlarmList)
    {
      boolean found = false;
      Iterator<TAlarm> li = devAlarmList.iterator();
      TAlarm alm = null;
      while (li.hasNext())
      {
        alm = (TAlarm)li.next();
        if ((alm.getDescriptor() & TAlarmDescriptor.TERMINATE) != 0) continue;
        if (alm.getCode() != code) continue;
        alm.setDescriptor((byte)TAlarmDescriptor.TERMINATE);
        alm.clear();
        found = true;
      }
      if (!found)
      {
        if (TEquipmentModuleFactory.getDebugLevel() > 2)
View Full Code Here

      return (TAlarm[])devAlarmList.toArray(new TAlarm[0]);
    }
  }
  private TAlarm getAlarmFromList(int code,byte[] data,short flags,TAlarmWatchEntry awe)
  { // called only by setAlarm() ...
    TAlarm alm = null;
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    boolean keepTimestamp = false;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      if (code == 0) DbgLog.log("getAlarmFromList","searching for alarm code == 0?");
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // this shouldn't happen !
          // (if a caller uses a 'set' method on the alarm, it's almost gotta be right after this gets called)
          nerr++;
          MsgLog.log("getAlarmFromList", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return null;
          continue;
        }
        keepTimestamp = false;
        TAlarmDefinition ads = alm.getAlmDef();
        if (alm.isTerminated())
        { // is marked for termination
          boolean oscPinned = TAlarm.getAlmOscillationWindowPinned();
          int oscw = TAlarm.getAlmOscillationWindow();
          if (ads != null)
          {
            if (!oscPinned) oscPinned = ads.isOscillationWindowPinned();
            oscw = ads.getAlarmOscillationWindow();
          }
          if (!alm.isTransient() && !oscPinned)
          { // oscillation window too small ?
            int dt = (alm.getTimeStamp()+TAlarm.getTerminationWindow()) - (int)(System.currentTimeMillis()/1000);
            if (dt > 0 && dt < TAlarm.ALM_OSCILLATION_MAXIMUM-oscw)
            { // adjust the oscillation window
              oscw += dt;
              if (ads != null) ads.setAlarmOscillationWindow(oscw);
              else TAlarm.setAlmOscillationWindow(oscw,false);
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList","increase alarm oscillation windows to "+oscw+" clear counts");
            }
          }
          continue;
        }
        else
        { // not marked for termination
          if (alm.getCode() == code && alm.getWatchEntry() == awe)
          { // it's already in the list so remove NEW bit !
            byte dsc = alm.getDescriptor();
            byte[] adata = alm.getData();
            int dlen = ads == null ? 0 : ads.getAlarmDataArraySize();
            if (dlen > 0 && data != null && adata != null)
            { // check for alarm data changed
              for (int n=0; n<dlen && n<adata.length && n<data.length; n++)
              {
                if (data[n] != adata[n])
                { // remove NEW and add DATACHANGE
                  dsc &= ~(byte)(TAlarmDescriptor.NEW);
                  if (alm.isDataChange())
                  { // already marked as data change (when was the last time ?)
                    if (thisTimeStamp - alm.getTimeStamp() < TAlarm.getAlmDataChangeWindow())
                    {
                      keepTimestamp = true;
                    }
                  }
                  if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
                  dsc |= (byte)TAlarmDescriptor.DATACHANGE;
                  if (TEquipmentModuleFactory.getDebugLevel() > 0)
                    DbgLog.log("getAlarmFromList",alm.getTag() + " : alarm data changed");
                  break;
                }
              }
            }
            if (alm.getClearCount() > 1)
            { // check for oscillating alarm ...
              dsc &= ~(byte)(TAlarmDescriptor.NEW);
              if (alm.isOscillating()) keepTimestamp = true;
              if (!keepTimestamp) alm.setTimeStamp(thisTimeStamp);
              dsc |= (byte)TAlarmDescriptor.OSCILLATION;
              if (TEquipmentModuleFactory.getDebugLevel() > 0)
                DbgLog.log("getAlarmFromList",alm.getTag() + " : mark alarm as oscillating");
            }
            alm.resetClearCount();
            alm.setDescriptor(dsc);
            return alm;
          }
        }
      }
      // not found, so this is a new one ...
      // TODO: worry about 'max_alarms_exceeded', i.e. alarm storms and the length of this list!
      if (devAlarmList.size() > maximumAllowedNumberOfAlarms)
      {
        devAlarmList.removeFirst();
        MsgLog.log("TDevice.getAlarmFromList", "alarm buffer full",TErrorList.max_alarms_exceeded,null,1);
      }
      flags |= TAlarmDescriptor.NEW;
      if ((flags & TAlarmDescriptor.TRANSIENT) != 0) flags |= TAlarmDescriptor.TERMINATE;
      alm = new TAlarm(code,(byte)flags,data,this);
      alm.setWatchEntry(awe);
      if (eqm.casReadRequired) alm.blockRemoval();
      devAlarmList.add(alm);
    }
    if (TEquipmentModuleFactory.getDebugLevel() > 0)
      DbgLog.log("getAlarmFromList",devName + " : " + alm.getTag() + "(" + code + ") : add alarm to list");
    return alm;
  }
View Full Code Here

  }
  public void processAlarms()
  {
    int nerr = 0;
    int thisTimeStamp = (int)(System.currentTimeMillis()/1000);
    TAlarm alm = null;
    synchronized (devAlarmList)
    {
      Iterator<TAlarm> li = devAlarmList.iterator();
      nDevAlarmsAtHsv = 0; devAlarmHsv = 0;
      nDevAlarmsAtMrt = 0; devAlarmMrt = 0;
      nDevAlarmsAtMrct = 0;
      while (li.hasNext())
      {
        try
        {
          alm = (TAlarm)li.next();
        }
        catch (ConcurrentModificationException e)
        { // someone could be using e.g. the setData() method on the alarm itself
          // (not a good way to do it, but it's supported)
          nerr++;
          MsgLog.log("processAlarms", "concurrent modification error "+nerr,TErrorList.semaphore_error,e,0);
          if (nerr > 3) return;
          continue;
        }
        if (alm.isTerminated() && 
            thisTimeStamp > alm.getTimeStamp() + TAlarm.getTerminationWindow())
        {
          if (alm.getSeverity() > 0 && alm.isRemovalBlocked())
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 2) DbgLog.log("processAlarms",alm.getTag() + " : missing CAS read -> removal blocked");
          }
          else
          {
            if (TEquipmentModuleFactory.getDebugLevel() > 1) DbgLog.log("processAlarms",alm.getTag() + " : remove alarm");
            li.remove();
            continue;
          }
        }
        // apply termination flag if necessary ...
        if (!alm.isTerminated() && thisTimeStamp > alm.getTimeStamp())
        {
          int oscw = TAlarm.getAlmOscillationWindow();
          TAlarmDefinition ads = alm.getAlmDef();
          if (ads != null) oscw = ads.getAlarmOscillationWindow();
          if (alm.getClearCount() > (oscw-TAlarm.ALM_OSCILLATION_CUSHION))
          {
            byte dsc = alm.getDescriptor();
            dsc &= ~(byte)TAlarmDescriptor.NEW;
            dsc |= (byte)TAlarmDescriptor.TERMINATE;
            alm.setDescriptor(dsc);
            alm.setTimeStamp(thisTimeStamp);
            //refreshMrt(thisTimeStamp);
            alm.setTerminated(true);
            DbgLog.log("processAlarms",alm.getTag() + " : mark alarm as terminated");
          }
        }
        // apply heartbeat if necessary
        if (thisTimeStamp > alm.getTimeStamp() + TAlarm.getAlmHeartbeatWindow())
        {
          byte dsc = alm.getDescriptor();
          dsc &= ~(byte)TAlarmDescriptor.NEW;
          dsc |= (byte)TAlarmDescriptor.HEARTBEAT;
          alm.setDescriptor(dsc);
          alm.setTimeStamp(thisTimeStamp);
          //refreshMrt(thisTimeStamp);
        }
        refreshMrt(alm.getTimeStamp());
        refreshHsv((short)alm.getSeverity());
      }
      // adjust most recent completed timestamp (if necessary)
      int mrct = 0;
      if (thisTimeStamp > devAlarmMrt && devAlarmMrt > mrct)
      {
View Full Code Here

  {
    return setAlarm(code,data,TAlarmDescriptor.NEW);
  }
  public TAlarm setAlarm(int code,byte[] data,TAlarmWatchEntry awe)
  {
    TAlarm alm = getAlarmFromList(code,data,TAlarmDescriptor.NEW,awe);
    if (alm.isTerminated()) DbgLog.log("setAlarm",alm.getTag() + " : set alarm as terminated");
    return alm;
  }
View Full Code Here

TOP

Related Classes of de.desy.tine.server.alarms.TAlarm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.