Class ArchiveChannel

  • Direct Known Subclasses:
    DeltaArchiveChannel, MonitoredArchiveChannel, ScannedArchiveChannel

    public abstract class ArchiveChannel
    extends Object
    Base for archived channels. An ArchiveChannel has
    1. A main PV; in the typical case, this would be the PV for the .VAL. The record processing timestamp from this PV constitutes identity.
    2. A optional collection of metadata/field PVs. Data from these PV's is stored as part of the mainPV.
    3. A SampleBuffer where the data from the main PV is stored.
    4. A Writer, typically the STS, where the data in the SampleBuffer is periodically flushed.
    Version:
    Initial version:CSS, 4-Jun-2012, Luofeng Li:added codes to support for the new archiver
    Author:
    Kay Kasemir
    • Field Detail

      • latestDBRTimeEvent

        protected DBRTimeEvent latestDBRTimeEvent
        The latest DBRTimeEvent received from the control system
      • lastDBRTimeEvent

        protected DBRTimeEvent lastDBRTimeEvent
        The last DBRTimeEvent written to the archive.
      • pvMetrics

        protected final PVMetrics pvMetrics
        pvMetrics for this channel. Ideally, we should move all metrics to this class.
    • Constructor Detail

      • ArchiveChannel

        public ArchiveChannel​(String name,
                              Writer writer,
                              Enablement enablement,
                              int buffer_capacity,
                              Timestamp last_archived_timestamp,
                              ConfigService configservice,
                              ArchDBRTypes archdbrtype,
                              String controlPVname,
                              int commandThreadID,
                              boolean usePVAccess)
                       throws Exception
        create archive channel
        Parameters:
        name - pv's name
        writer - the writer for this pv
        enablement - start or stop archiving this pv when channel is created
        buffer_capacity - the sample buffer's capacity for this pv
        last_archived_timestamp - the last time stamp when this pv was archived
        configservice - the configservice of new archiver
        archdbrtype - the archiving dbr type
        controlPVname - the pv's name who control this pv to start archiving or stop archiving
        commandThreadID - - this is the index into the array of JCA command threads that processes this context.
        usePVAccess - - Should we use PVAccess to connect to this PV.
        Throws:
        Exception - error when creating archive channel for this pv
    • Method Detail

      • getControlPVname

        public String getControlPVname()
        if this channel is started or stopped archiving by a another pv, return the pv's name
        Returns:
        the pv's name who control this channel archiving
      • setlastRotateLogsEpochSeconds

        public void setlastRotateLogsEpochSeconds​(long lastRotateLogsEpochSecond)
        set the time stamp of the last value is stored in short term storage
        Parameters:
        lastRotateLogsEpochSecond - the time stamp of last value and it is the number of milliseconds since 1970/01/01
      • getWriter

        public Writer getWriter()
        get the writer for this channel
        Returns:
        the writer for this channel
      • getPVMetrics

        public PVMetrics getPVMetrics()
        get pv metrics for this channel
        Returns:
        PVMetrics
      • getPVData

        public ArrayListEventStream getPVData()
        get the combined ArrayListEventStream of prevouse and current
        Returns:
        ArrayListEventStream
      • getName

        public final String getName()
        Returns:
        Name of channel
      • getEnablement

        public final Enablement getEnablement()
        Returns:
        How channel affects its groups
      • isEnabled

        public final boolean isEnabled()
        Returns:
        true if channel is currently enabled
      • getMechanism

        public abstract String getMechanism()
        Returns:
        Short description of sample mechanism
      • isConnected

        public final boolean isConnected()
        Returns:
        true if connected
      • start

        public final void start()
                         throws Exception
        Start archiving this channel.
        Throws:
        Exception -  
      • stop

        public final void stop()
                        throws Exception
        Stop archiving this channel
        Throws:
        Exception -  
      • getCurrentArchivedValue

        public final DBRTimeEvent getCurrentArchivedValue()
        Returns:
        Most recent value of the channel's PV
      • getReceivedValues

        public long getReceivedValues()
        Returns:
        Count of received values
      • getLastArchivedValue

        public final DBRTimeEvent getLastArchivedValue()
        Returns:
        Last value written to archive
      • getSampleBuffer

        public final SampleBuffer getSampleBuffer()
        Returns:
        Sample buffer
      • reset

        public void reset()
        Reset counters
      • handleNewValue

        protected boolean handleNewValue​(DBRTimeEvent timeevent)
                                  throws Exception
        Called for each value received from PV.

        Base class remembers the most_recent_value, and asserts that one 'first' sample is archived. Derived class must call super().

        Parameters:
        timeevent - DBRTimeEvent
        Returns:
        true if the value was already written because it's the first value after startup or error, so there's no need to write that sample again.
        Throws:
        Exception -  
      • startUpMetaChannels

        public void startUpMetaChannels()
                                 throws Exception
        Start the metachannels

        Throws:
        Exception -  
      • shutdownMetaChannels

        public void shutdownMetaChannels()
                                  throws Exception
        Throws:
        Exception
      • handleDisconnected

        protected void handleDisconnected()
                                   throws Exception
        Handle a disconnect event.

        Base class clears the most_recent_value and adds a 'disconnected' info sample. Subclasses may override, but must call super().

        Throws:
        Exception -  
      • addValueToBuffer

        protected final boolean addValueToBuffer​(DBRTimeEvent timeevent)
                                          throws Exception
        Add given sample to buffer, performing a back-in-time check, updating the sample buffer error state.
        Parameters:
        timeevent - DBRTimeEvent
        Returns:
        false if value failed back-in-time or future check, true if value was added.
        Throws:
        Exception -  
      • getCurrentCopyOfMetaFields

        public HashMap<String,​String> getCurrentCopyOfMetaFields()
        Get the current value of all the meta fields.
        Returns:
        - Can return null if this PV has no meta fields.
      • getHostName

        public String getHostName()
      • getLowLevelChannelStateInfo

        public void getLowLevelChannelStateInfo​(List<Map<String,​String>> statuses)
      • isMetaPVConnected

        public boolean isMetaPVConnected​(String metaFieldName)
        Get the archive channel for a particular metachannel.
        Parameters:
        metaFieldName -  
        Returns:
        boolean True or False
      • getMetaPVNames

        public Set<String> getMetaPVNames()
        Get the field names for which we have established channels.
        Returns:
        String the Meta PV names
      • getMetaChannelCount

        public int getMetaChannelCount()
        Number of field names for which we have established channels.
        Returns:
        int  
      • getConnectedMetaChannelCount

        public int getConnectedMetaChannelCount()
        Get the number of connected field channels
        Returns:
        int  
      • metaChannelsNeedStartingUp

        public boolean metaChannelsNeedStartingUp()
        Do any of the meta channels in this PV need starting up?
        Returns:
        boolean True or False
      • getSecondsElapsedSinceSearchRequest

        public long getSecondsElapsedSinceSearchRequest()
        Return the amount of time (in seconds) since we asked CAJ/JCA to connect to this channel.
        Returns:
        long  
      • getJCACommandThreadID

        public int getJCACommandThreadID()
        Returns:
        int the jCACommandThreadID
      • setJCACommandThreadID

        public void setJCACommandThreadID​(int jCACommandThreadID)
        Parameters:
        jCACommandThreadID - the jCACommandThreadID to set
      • updateMetadataOnceADay

        public void updateMetadataOnceADay​(EngineContext context)
        Use this method to do a caget on the metadata..
        Parameters:
        context - EngineContext
      • getLatestMetadata

        public HashMap<String,​String> getLatestMetadata()
        Combine the metadata from various sources and return the latest copy.
        Returns:
        HashMap