Revision: 14741
http://gate.svn.sourceforge.net/gate/?rev=14741&view=rev
Author: valyt
Date: 2011-12-12 14:31:03 +0000 (Mon, 12 Dec 2011)
Log Message:
-----------
New MimirSearchException type (internal server error). This occrs e.g. when the
remote query has expired for a RemoteQueryRunner.
GWT code now traps remote 'internal server errors' and re-posts the query.
Two consecutive remote connection errors in the GWT UI lead to giving up.
Modified Paths:
--------------
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
mimir/trunk/mimir-web/src/groovy/gate/mimir/util/WebUtilsManager.groovy
mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/MimirSearchException.java
Modified:
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
===================================================================
---
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
2011-12-12 14:28:30 UTC (rev 14740)
+++
mimir/trunk/mimir-web/grails-app/services/gate/mimir/web/server/GwtRpcService.groovy
2011-12-12 14:31:03 UTC (rev 14741)
@@ -120,57 +120,65 @@
int firstDocumentRank, int documentsCount) throws MimirSearchException {
QueryRunner qRunner = searchService.getQueryRunner(queryId);
if(qRunner) {
- ResultsData rData = new ResultsData(
+ try {
+ ResultsData rData = new ResultsData(
resultsTotal:qRunner.getDocumentsCount(),
- resultsPartial: qRunner.getCurrentDocumentsCount())
- if(firstDocumentRank >= 0) {
- // also obtain some documents data
- List<DocumentData> documents = []
- int maxRank = Math.min(firstDocumentRank + documentsCount,
- qRunner.getDocumentsCount());
- for(int docRank = firstDocumentRank; docRank < maxRank; docRank++) {
- DocumentData docData = new DocumentData(
- documentRank:docRank,
- documentTitle:qRunner.getDocumentTitle(docRank),
- documentUri:qRunner.getDocumentURI(docRank))
- // create the snippets
- List<String[]> snippets = new ArrayList<String[]>();
- List<Binding> hits = qRunner.getDocumentHits(docRank).collect{it};
- 3.times {
- if(hits) {
- String[] snippet = new String[3];
- Binding aHit = hits.remove(0)
- int termPos = Math.max(0, aHit.termPosition - 3)
- if(termPos < aHit.termPosition) {
- snippet[0] = qRunner.getDocumentText(docRank, termPos,
- aHit.termPosition - termPos).toList().transpose().inject('')
{
+ resultsPartial: qRunner.getDocumentsCurrentCount())
+ if(firstDocumentRank >= 0) {
+ // also obtain some documents data
+ List<DocumentData> documents = []
+ int maxRank = Math.min(firstDocumentRank + documentsCount,
+ qRunner.getDocumentsCount());
+ for(int docRank = firstDocumentRank; docRank < maxRank; docRank++) {
+ DocumentData docData = new DocumentData(
+ documentRank:docRank,
+ documentTitle:qRunner.getDocumentTitle(docRank),
+ documentUri:qRunner.getDocumentURI(docRank))
+ // create the snippets
+ List<String[]> snippets = new ArrayList<String[]>();
+ List<Binding> hits = qRunner.getDocumentHits(docRank).collect{it};
+ 3.times {
+ if(hits) {
+ String[] snippet = new String[3];
+ Binding aHit = hits.remove(0)
+ int termPos = Math.max(0, aHit.termPosition - 3)
+ if(termPos < aHit.termPosition) {
+ snippet[0] = qRunner.getDocumentText(docRank, termPos,
+ aHit.termPosition -
termPos).toList().transpose().inject('') {
+ acc, val -> acc + val[0] + (val[1] ? ' ' : '')
+ }
+ } else {
+ snippet[0] = '';
+ }
+ snippet[1] = qRunner.getDocumentText(docRank,
aHit.termPosition,
+ aHit.length).toList().transpose().inject('') {
acc, val -> acc + val[0] + (val[1] ? ' ' : '')
- }
- } else {
- snippet[0] = '';
+ }
+ snippet[2] = qRunner.getDocumentText(docRank,
+ aHit.termPosition + aHit.length, 3).toList().
+ transpose().inject('') {
+ acc, val -> acc + val[0] + (val[1] ? ' ' : '')
+ }
+ snippets << snippet
}
- snippet[1] = qRunner.getDocumentText(docRank, aHit.termPosition,
- aHit.length).toList().transpose().inject('') {
- acc, val -> acc + val[0] + (val[1] ? ' ' : '')
- }
- snippet[2] = qRunner.getDocumentText(docRank,
- aHit.termPosition + aHit.length, 3).toList().
- transpose().inject('') {
- acc, val -> acc + val[0] + (val[1] ? ' ' : '')
- }
- snippets << snippet
}
+ if(hits) {
+ // more than 3 hits: show ellipsis
+ snippets.add([" ", "...", " "]as String[])
+ }
+ docData.snippets = snippets
+ documents.add(docData)
}
- if(hits) {
- // more than 3 hits: show ellipsis
- snippets.add([" ", "...", " "]as String[])
- }
- docData.snippets = snippets
- documents.add(docData)
+ if(documents) rData.setDocuments(documents)
}
- if(documents) rData.setDocuments(documents)
+ return rData
+ } catch (Exception e) {
+ // we had a problem accessing the data inside the query runner. We'll
+ // just assume the runner is not valid any more
+ throw new
MimirSearchException(MimirSearchException.INTERNAL_SERVER_ERROR,
+ "Error extracting data from the query runner - " +
+ "your session may have expired.");
}
- return rData
} else {
throw new MimirSearchException(MimirSearchException.QUERY_ID_NOT_KNOWN,
"Could not find your query. " +
Modified:
mimir/trunk/mimir-web/src/groovy/gate/mimir/util/WebUtilsManager.groovy
===================================================================
--- mimir/trunk/mimir-web/src/groovy/gate/mimir/util/WebUtilsManager.groovy
2011-12-12 14:28:30 UTC (rev 14740)
+++ mimir/trunk/mimir-web/src/groovy/gate/mimir/util/WebUtilsManager.groovy
2011-12-12 14:31:03 UTC (rev 14741)
@@ -18,6 +18,9 @@
import gate.mimir.web.RemoteIndex;
class WebUtilsManager {
+
+ static WebUtils staticWebUtils = new WebUtils();
+
public WebUtils currentWebUtils(RemoteIndex remoteIndex) {
if(RCH.requestAttributes) {
WebUtils utils = RCH.requestAttributes.session.webUtilsInstance
@@ -34,7 +37,7 @@
return new WebUtils(remoteIndex.remoteUsername,
remoteIndex.remotePassword)
} else {
- return WebUtils.staticWebUtils()
+ return staticWebUtils
}
}
}
Modified: mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java
===================================================================
--- mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-12
14:28:30 UTC (rev 14740)
+++ mimir/trunk/mimir-web/src/gwt/gate/mimir/web/client/UI.java 2011-12-12
14:31:03 UTC (rev 14741)
@@ -70,6 +70,13 @@
private int newFirstDocument;
/**
+ * Flag used to indicate if we previously encountered an error
+ * communicating with the remote endpoint. This flag gets cleared on every
+ * successful access.
+ */
+ boolean remoteError = false;
+
+ /**
* Creates a new results updater.
* @param newFirstDocument the first document to be displayed on the page.
* This can be used for navigating between pages.
@@ -79,6 +86,10 @@
this.newFirstDocument = newFirstDocument;
}
+ public void setFirstDocument(int newFirstDocument) {
+ this.newFirstDocument = newFirstDocument;
+ }
+
@Override
public void run() {
if(newFirstDocument != firstDocumentOnPage) {
@@ -91,26 +102,54 @@
new AsyncCallback<ResultsData>() {
@Override
public void onSuccess(ResultsData result) {
+ remoteError = false;
updatePage(result);
if(result.getResultsTotal() < 0) schedule(500);
}
@Override
public void onFailure(Throwable caught) {
- if(caught instanceof MimirSearchException &&
- ((MimirSearchException)caught).getErrorCode() ==
- MimirSearchException.QUERY_ID_NOT_KNOWN) {
- // query ID not known -> re-post the query
- if(queryString != null && queryString.length() > 0){
- queryId = null;
- postQuery(queryString);
- }
+ if(remoteError) {
+ // this is the second failure: bail out
+ // re-throw the exception so it's seen (useful when debugging)
+ throw new RuntimeException(caught);
} else {
- // ignore and try again later
- schedule(500);
- // re-throw the exception so it's seen (useful when debugging)
- throw new RuntimeException(caught);
+ // update the flag so we get out next time
+ remoteError = true;
}
+ if(caught instanceof MimirSearchException) {
+ if(((MimirSearchException)caught).getErrorCode() ==
+ MimirSearchException.QUERY_ID_NOT_KNOWN) {
+ // query ID not known -> re-post the query
+ if(queryString != null && queryString.length() > 0){
+ queryId = null;
+ postQuery(queryString);
+ return;
+ }
+ } else if(((MimirSearchException)caught).getErrorCode() ==
+ MimirSearchException.INTERNAL_SERVER_ERROR) {
+ // server side error: try reposting the query once
+ // clean up old state
+ if(queryId != null) {
+ // release old query
+ gwtRpcService.releaseQuery(queryId, new AsyncCallback<Void>() {
+ @Override
+ public void onSuccess(Void result) {}
+ @Override
+ public void onFailure(Throwable caught) {}
+ });
+ }
+ if(queryString != null && queryString.length() > 0){
+ queryId = null;
+ postQuery(queryString);
+ return;
+ }
+ }
+ }
+ // ignore and try again later
+ schedule(500);
+ // re-throw the exception so it's seen (useful when debugging)
+ throw new RuntimeException(caught);
}
});
}
@@ -391,6 +430,8 @@
*/
protected HTMLPanel pageLinksPanel;
+ protected ResultsUpdater resultsUpdater;
+
/**
* The rank of the first document on page.
*/
@@ -426,6 +467,7 @@
indexId = getIndexId();
uriIsLink = Boolean.parseBoolean(getUriIsLink());
+ resultsUpdater = new ResultsUpdater(0);
initLocalData();
initGui();
initListeners();
@@ -439,7 +481,6 @@
protected void initGui() {
HTMLPanel searchDiv =
HTMLPanel.wrap(Document.get().getElementById("searchBox"));
-
TextArea searchTextArea = new TextArea();
searchTextArea.setCharacterWidth(60);
searchTextArea.setVisibleLines(10);
@@ -568,7 +609,8 @@
newQueryString.trim())){
searchBox.setText(newQueryString);
}
- new ResultsUpdater(newFirstDoc).schedule(10);
+ resultsUpdater.setFirstDocument(newFirstDoc);
+ resultsUpdater.schedule(10);
}
}
}
Modified:
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/MimirSearchException.java
===================================================================
---
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/MimirSearchException.java
2011-12-12 14:28:30 UTC (rev 14740)
+++
mimir/trunk/mimir-web/src/java/gate/mimir/web/client/MimirSearchException.java
2011-12-12 14:31:03 UTC (rev 14741)
@@ -25,6 +25,8 @@
public static final int QUERY_ID_NOT_KNOWN = 1;
+ public static final int INTERNAL_SERVER_ERROR = 1;
+
public static final int OTHER = 0;
private int errorCode;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs