Class QueryMonitorTimeout

  • All Implemented Interfaces:
    QueryMonitor
    Direct Known Subclasses:
    PageTableQueryMonitor, QueryCountQueryMonitor

    public class QueryMonitorTimeout
    extends java.lang.Object
    implements QueryMonitor
    QueryMonitor that cancels a query after a given timeout period. An instance of this method should be created, passed to SessionMethods.runQuery and then services repeatedly by calling the tickle method periodically. The timeout period should be significantly longer than the tickle period (so a little variance in the time between tickle calls won't cause an unwanted timeout). Note that the constructor calls tickle to initialise the timing so you should create this object when you need it (and will immediately tickle it) and not before.

    The shouldCancelQuery method will return true if the tickle method has not been called in the past n milliseconds where n is set during construction.

    Author:
    Thomas Riley
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected long lastTickle
      Time of last call to tickle.
      protected int n
      Number of milliseconds before timeout.
      protected int tickleCount
      number of tickles.
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryMonitorTimeout​(int n)
      Construct a new instance of QueryMonitorTimeout.
    • Field Detail

      • n

        protected int n
        Number of milliseconds before timeout.
      • lastTickle

        protected long lastTickle
        Time of last call to tickle.
      • tickleCount

        protected int tickleCount
        number of tickles. used to determine how.
    • Constructor Detail

      • QueryMonitorTimeout

        public QueryMonitorTimeout​(int n)
        Construct a new instance of QueryMonitorTimeout.
        Parameters:
        n - the number of milliseconds to timeout after
    • Method Detail

      • shouldCancelQuery

        public boolean shouldCancelQuery()
        Return true if tickle has not been called in a period of time greater than the timeout value. Called intermittently while a query is run providing an opportunity to cancel the query. param results the Results object associated with the running query param request the http servlet request
        Specified by:
        shouldCancelQuery in interface QueryMonitor
        Returns:
        false if the query should be cancelled, otherwise true
      • tickle

        public void tickle()
        Tell this object to continue returning false from shouldCancelQuery. If this method is not called for a period of time greater than the timeout period, shouldCancelQuery will return true.
      • getTickleCount

        public int getTickleCount()
        Find out how many times tickle has been called.
        Returns:
        number of times tickle has been called
      • queryCompleted

        public void queryCompleted()
        Called when the query has completed.
        Specified by:
        queryCompleted in interface QueryMonitor
      • isCompleted

        public boolean isCompleted()
        Find out whether the query has completed.
        Returns:
        true when the query has completed
      • queryCancelledWithError

        public void queryCancelledWithError()
        Called when the query stopped with an error. The error message should be in the session.
        Specified by:
        queryCancelledWithError in interface QueryMonitor
      • isCancelledWithError

        public boolean isCancelledWithError()
        Find out whether an error occured while trying to run the query.
        Returns:
        true if an error occured, false if not
      • isCancelled

        public boolean isCancelled()
        Find out whether the query was cancelled.
        Returns:
        true if query was cancelled, false if not
      • queryCancelled

        public void queryCancelled()
        Called when the query is cancelled. Usually as a result of shouldCancelQuery returning true.
        Specified by:
        queryCancelled in interface QueryMonitor
      • setPathQuery

        public void setPathQuery​(PathQuery query)
        Parameters:
        query - the path query to set
      • getPathQuery

        public PathQuery getPathQuery()
        Returns:
        the path query