Package org.intermine.web.logic.query
Class QueryMonitorTimeout
- java.lang.Object
-
- org.intermine.web.logic.query.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PathQuery
getPathQuery()
int
getTickleCount()
Find out how many times tickle has been called.boolean
isCancelled()
Find out whether the query was cancelled.boolean
isCancelledWithError()
Find out whether an error occured while trying to run the query.boolean
isCompleted()
Find out whether the query has completed.void
queryCancelled()
Called when the query is cancelled.void
queryCancelledWithError()
Called when the query stopped with an error.void
queryCompleted()
Called when the query has completed.void
setPathQuery(PathQuery query)
boolean
shouldCancelQuery()
Return true if tickle has not been called in a period of time greater than the timeout value.void
tickle()
Tell this object to continue returning false from shouldCancelQuery.
-
-
-
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 interfaceQueryMonitor
- 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 interfaceQueryMonitor
-
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 interfaceQueryMonitor
-
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 interfaceQueryMonitor
-
setPathQuery
public void setPathQuery(PathQuery query)
- Parameters:
query
- the path query to set
-
getPathQuery
public PathQuery getPathQuery()
- Returns:
- the path query
-
-