Revision: 17424
http://sourceforge.net/p/gate/code/17424
Author: valyt
Date: 2014-02-26 11:01:11 +0000 (Wed, 26 Feb 2014)
Log Message:
-----------
Bugfix: make sure the state is checked at regular intervals, even when no more
input is available.
Modified Paths:
--------------
mimir/branches/5.0/mimir-client/src/gate/mimir/index/MimirConnector.java
Modified:
mimir/branches/5.0/mimir-client/src/gate/mimir/index/MimirConnector.java
===================================================================
--- mimir/branches/5.0/mimir-client/src/gate/mimir/index/MimirConnector.java
2014-02-26 10:36:54 UTC (rev 17423)
+++ mimir/branches/5.0/mimir-client/src/gate/mimir/index/MimirConnector.java
2014-02-26 11:01:11 UTC (rev 17424)
@@ -24,6 +24,7 @@
import java.net.URL;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
/**
* Utility class that implements the client side of the Mimir RPC indexing
@@ -56,15 +57,25 @@
@Override
public void run() {
try {
- byte[] data = inputBuffer.take();
+ // The logic is: if there is a connectionInterval (positive value),
then
+ // check the state with the same interval, to make sure we flush the
+ // data to the server, even if no more documents are submitted.
+ // If the connection interval is negative, then every time there is
+ // a document in the queue, it will immediately be sent to the server
+ // so we don't need to time-out the poll.
+ byte[] data = inputBuffer.poll(
+ (connectionInterval > 0 ? connectionInterval : Integer.MAX_VALUE),
+ TimeUnit.MILLISECONDS);
while(data != END_OF_LIST) {
try{
- // if too much data, write the buffer
- if(data.length + byteBuffer.size() > BYTE_BUFFER_SIZE){
- writeBuffer(); // this will also empty (reset) the buffer
+ if(data != null) {
+ // if too much data, write the buffer
+ if(data.length + byteBuffer.size() > BYTE_BUFFER_SIZE){
+ writeBuffer(); // this will also empty (reset) the buffer
+ }
+ // add the current document to the buffer
+ byteBuffer.write(data);
}
- // add the current document to the buffer
- byteBuffer.write(data);
// if too long since last write, write the buffer
if(System.currentTimeMillis() - lastWrite > connectionInterval) {
writeBuffer();
@@ -73,7 +84,9 @@
// error communicating with the remote end point
exception = e;
}
- data = inputBuffer.take();
+ data = inputBuffer.poll(
+ (connectionInterval > 0 ? connectionInterval :
Integer.MAX_VALUE),
+ TimeUnit.MILLISECONDS);
}
// we're closing
if(byteBuffer.size() > 0) {
@@ -98,25 +111,27 @@
* @throws IOException
*/
protected void writeBuffer() throws IOException {
- // first phase - call the indexUrl action to find out where to post the
- // data
- StringBuilder indexURLString = new
StringBuilder(indexURL.toExternalForm());
- if(indexURLString.length() == 0) {
- throw new IllegalArgumentException("No index URL specified");
+ if(byteBuffer.size() > 0) {
+ // first phase - call the indexUrl action to find out where to post the
+ // data
+ StringBuilder indexURLString = new
StringBuilder(indexURL.toExternalForm());
+ if(indexURLString.length() == 0) {
+ throw new IllegalArgumentException("No index URL specified");
+ }
+ if(indexURLString.charAt(indexURLString.length() - 1) != '/') {
+ // add a slash if necessary
+ indexURLString.append('/');
+ }
+ indexURLString.append("manage/indexUrl");
+ StringBuilder postUrlBuilder = new StringBuilder();
+
+ webUtils.getText(postUrlBuilder, indexURLString.toString());
+
+ // second phase - post to the URL we were given
+ webUtils.postData(postUrlBuilder.toString(), byteBuffer);
+ byteBuffer.reset();
}
- if(indexURLString.charAt(indexURLString.length() - 1) != '/') {
- // add a slash if necessary
- indexURLString.append('/');
- }
- indexURLString.append("manage/indexUrl");
- StringBuilder postUrlBuilder = new StringBuilder();
- webUtils.getText(postUrlBuilder, indexURLString.toString());
-
- // second phase - post to the URL we were given
- webUtils.postData(postUrlBuilder.toString(), byteBuffer);
- byteBuffer.reset();
-
lastWrite = System.currentTimeMillis();
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs