Class Correlator<S,R,A extends SourceAgent<R>>

java.lang.Object
xal.tools.correlator.Correlator<S,R,A>
Direct Known Subclasses:
ChannelCorrelator

public abstract class Correlator<S,R,A extends SourceAgent<R>> extends Object
The Correlator is the class that is used to setup monitoring of correlated events. It is the sole entry point to the outside world. When correlations are found, the Correlator broadcasts the correlation. Note that all time is in seconds unless otherwise stated.
Author:
tap
  • Field Details

    • localCenter

      protected MessageCenter localCenter
    • binTimespan

      protected double binTimespan
    • correlationTester

      protected CorrelationTester<R> correlationTester
  • Constructor Details

    • Correlator

      protected Correlator(double aBinTimespan)
      Creates new Correlator
    • Correlator

      protected Correlator(double aBinTimespan, CorrelationFilter<R> aFilter)
      Correlator constructor
  • Method Details

    • registerEvents

      protected void registerEvents()
      Register for notices.
    • addListener

      public void addListener(CorrelationNotice<R> listener)
      Register the listener as a receiver of Correlation notices from this correlator.
      Parameters:
      listener - to register for receiving events
    • removeListener

      public void removeListener(CorrelationNotice<R> listener)
      Unregister the listener as a receiver of Correlation notices from this correlator.
      Parameters:
      listener - to remove from receiving events
    • binTimespan

      public double binTimespan()
      Maximum time span allowed for events to be considered correlated
      Returns:
      the bin timespan
    • setBinTimespan

      public void setBinTimespan(double timespan)
      Set the maximum time span allowed for events to be considered correlated
      Parameters:
      timespan - of the bins
    • setCorrelationFilter

      public void setCorrelationFilter(CorrelationFilter<R> newFilter)
      Set the correlation filter to the one specified.
      Parameters:
      newFilter - The correlation filter to use.
    • getSourceAgents

      protected Collection<A> getSourceAgents()
      Get all of the channel agents managed by this correlator
      Returns:
      collection of source agents
    • getNamesOfSources

      public Collection<String> getNamesOfSources()
      Get all the names of all the sources managed by this correlator
      Returns:
      names of the sources
    • numSources

      public int numSources()
      Number of channels being managed
      Returns:
      number of sources
    • hasSource

      public boolean hasSource(String sourceName)
      See if we already manage this channel
      Parameters:
      sourceName - name of source to test
      Returns:
      true if the named source is in this correlator and false if not
    • addSource

      protected void addSource(S source, String sourceName)
      Add a source to monitor. The name provided with each source must be unique to that source. Subclasses need to wrap this method to enforce the source type.
      Parameters:
      source - to add
      sourceName - name of source to add
    • addSource

      protected void addSource(S source, String sourceName, RecordFilter<R> recordFilter)
      Add a source to monitor. If we already monitor a source as determined by the source name, then do nothing. The record filter is used to determine whether or not to accept a reading of the specified source when the event is handled. You can create your own custom filter or use a pre-built one. Subclasses need to wrap this method to enforce the source type.
      Parameters:
      source - to add
      sourceName - name of source to add
      recordFilter - filter for the source
    • newSourceAgent

      protected abstract A newSourceAgent(S source, String sourceName, RecordFilter<R> recordFilter)
    • removeSource

      public void removeSource(String sourceName)
      Stop managing the specified source.
      Parameters:
      sourceName - name of source to remove
    • removeAllSources

      public void removeAllSources()
      Stop managing all registered sources
    • pulseMonitorWithTimeout

      public void pulseMonitorWithTimeout(double timeout)
      Monitor until the timeout or until a complete correlation is found
      Parameters:
      timeout - time to wait in seconds
    • monitorWithTimeout

      public void monitorWithTimeout(double timeout)
      Monitor and post the best partial correlation if the timeout is exceeded. The timeout is rescheduled after every post.
      Parameters:
      timeout - time to wait in seconds
    • startMonitoring

      public void startMonitoring()
      Start monitoring the managed sources.
    • stopMonitoring

      public void stopMonitoring()
      Stop monitoring the managed sources.
    • isRunning

      public boolean isRunning()
      Determine if the correlator is running
      Returns:
      true if the correlator is running and false otherwise.
    • dispose

      public void dispose()
      Dispose of the correlator and its overhead
    • fetchCorrelationWithTimeout

      public Correlation<R> fetchCorrelationWithTimeout(double aTimeout)
      fetchCorrelationWithTimeout() is a convenience method that allows the user a simple way to fetch a correlation without handling events and implementing a listener. The method spawns a fetch and blocks until a correlation is retrieved or the timeout has expired. The resulting correlation is returned. If no correlation was found within the timeout, null is returned.
      Parameters:
      aTimeout - timeout for fetching a correlation
      Returns:
      fetched correlation or null if none within the timeout